[jboss-cvs] JBossAS SVN: r102964 - projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/attrib.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 25 11:37:49 EDT 2010
Author: anil.saldhana at jboss.com
Date: 2010-03-25 11:37:49 -0400 (Thu, 25 Mar 2010)
New Revision: 102964
Modified:
projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/attrib/DatabaseAttributeLocator.java
Log:
SECURITY-454: extract the getcolumnvalue method out for overriding by non-sql dbs
Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/attrib/DatabaseAttributeLocator.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/attrib/DatabaseAttributeLocator.java 2010-03-25 15:36:33 UTC (rev 102963)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/attrib/DatabaseAttributeLocator.java 2010-03-25 15:37:49 UTC (rev 102964)
@@ -47,6 +47,10 @@
/**
* An attribute locator that gets the attributes from the DB
+ * <p>
+ * <b>NOTE:</b> Subclasses should try to override the {@link #getColumnValue(URI, EvaluationCtx)}
+ * method if the DB is not a true RDBMS
+ * </p>
* @author Anil.Saldhana at redhat.com
* @since Mar 1, 2010
*/
@@ -101,70 +105,8 @@
return new EvaluationResult(BagAttribute.createEmptyBag(attributeId));
}
- Object columnValue = null;
- //Do DB stuff here
- Connection connection = getConnection();
+ Object columnValue = getColumnValue(attributeType, context);
- PreparedStatement statement = null;
- ResultSet resultSet = null;
-
- try
- {
- statement = connection.prepareStatement(sqlStatement);
-
- Object pluginValue = null;
- try
- {
- pluginValue = getPreparedStatementPluginValue(context, attributeType);
- }
- catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
- statement.setObject(1, pluginValue);
-
- statement.addBatch();
- connection.setAutoCommit(false);
- resultSet = statement.executeQuery();
- connection.setAutoCommit(true);
-
- while (resultSet.next())
- {
- columnValue = resultSet.getObject(columnName);
- break;
- }
- }
- catch (SQLException e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- try
- {
- if(resultSet != null)
- resultSet.close();
- }
- catch (SQLException e)
- {}
-
- try
- {
- if(statement != null)
- statement.close();
- }
- catch (SQLException e)
- {}
-
- try
- {
- if(connection != null)
- connection.close();
- }
- catch (SQLException e)
- {
- }
- }
Set bagSet = new HashSet();
bagSet.add(JBossXACMLUtil.getAttributeValue(columnValue));
@@ -254,6 +196,83 @@
}
/**
+ * Get the value of the attribute we are interested in
+ * @param attributeType
+ * @param context
+ * @return
+ */
+ protected Object getColumnValue(URI attributeType, EvaluationCtx context)
+ {
+ Object columnValue = null;
+
+ //Do DB stuff here
+ Connection connection = getConnection();
+
+ PreparedStatement statement = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ statement = connection.prepareStatement(sqlStatement);
+
+ Object pluginValue = null;
+ try
+ {
+ pluginValue = getPreparedStatementPluginValue(context, attributeType);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
+ statement.setObject(1, pluginValue);
+
+ statement.addBatch();
+ connection.setAutoCommit(false);
+ resultSet = statement.executeQuery();
+ connection.setAutoCommit(true);
+
+ while (resultSet.next())
+ {
+ columnValue = resultSet.getObject(columnName);
+ break;
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ try
+ {
+ if(resultSet != null)
+ resultSet.close();
+ }
+ catch (SQLException e)
+ {}
+
+ try
+ {
+ if(statement != null)
+ statement.close();
+ }
+ catch (SQLException e)
+ {}
+
+ try
+ {
+ if(connection != null)
+ connection.close();
+ }
+ catch (SQLException e)
+ {
+ }
+ }
+
+ return columnValue;
+ }
+
+ /**
* <p>
* Get the value to be plugged into the PreparedStatement using the <code>EvaluationCtx</code>
* </p>
More information about the jboss-cvs-commits
mailing list