Author: dimuthul
Date: Thu Feb 28 00:48:05 2008
New Revision: 14297
Log:
Changing the class name to DataSupplier.
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultDataSupplier.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/util/DefaultDataSupplierImpl.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthenticator.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthorizer.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultRealm.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreAdmin.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreReader.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
Thu Feb 28 00:48:05 2008
@@ -42,12 +42,12 @@
}
public DefaultAccessControlAdmin(DataSource dataSource, String algo,
- DefaultStrategy store) {
+ DefaultDataSupplier store) {
super(dataSource, algo, store);
}
public DefaultAccessControlAdmin(DataSource dataSource,
- DefaultStrategy store) {
+ DefaultDataSupplier store) {
super(dataSource, DefaultRealmConfig.PERMISSION_BLOCK_FIRST, store);
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthenticator.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthenticator.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthenticator.java
Thu Feb 28 00:48:05 2008
@@ -30,7 +30,7 @@
import org.wso2.authenticator.Authenticator;
import org.wso2.authenticator.AuthenticatorException;
-import org.wso2.registry.users.def.util.DefaultStrategyImpl;
+import org.wso2.registry.users.def.util.DefaultDataSupplierImpl;
/**
@@ -44,19 +44,19 @@
protected DefaultRealm realm = null;
- protected DefaultStrategy data = null;
+ protected DefaultDataSupplier data = null;
public DefaultAuthenticator(DataSource dataSource) {
this.dataSource = dataSource;
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
}
- public DefaultAuthenticator(DataSource dataSource, DefaultStrategy store) {
+ public DefaultAuthenticator(DataSource dataSource, DefaultDataSupplier
store) {
this.dataSource = dataSource;
if (store != null) {
this.data = store;
} else {
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
}
}
@@ -106,11 +106,11 @@
return isAuth;
}
- public DefaultStrategy getData() {
+ public DefaultDataSupplier getData() {
return data;
}
- public void setData(DefaultStrategy data) {
+ public void setData(DefaultDataSupplier data) {
this.data = data;
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthorizer.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthorizer.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAuthorizer.java
Thu Feb 28 00:48:05 2008
@@ -28,7 +28,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.users.Authorizer;
import org.wso2.registry.users.UserStoreException;
-import org.wso2.registry.users.def.util.DefaultStrategyImpl;
+import org.wso2.registry.users.def.util.DefaultDataSupplierImpl;
/**
@@ -40,7 +40,7 @@
protected DataSource dataSource = null;
/** The object that pumps sqls */
- protected DefaultStrategy data = null;
+ protected DefaultDataSupplier data = null;
/** logger */
private static Log log = LogFactory.getLog(DefaultAuthorizer.class);
@@ -50,17 +50,17 @@
public DefaultAuthorizer(DataSource dataSource, String algo) {
this.dataSource = dataSource;
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
this.algorithm = algo;
}
public DefaultAuthorizer(DataSource dataSource, String algo,
- DefaultStrategy strategy) {
+ DefaultDataSupplier strategy) {
this.dataSource = dataSource;
if (strategy != null) {
this.data = strategy;
} else {
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
}
this.algorithm = algo;
}
@@ -368,11 +368,11 @@
return result;
}
- public DefaultStrategy getData() {
+ public DefaultDataSupplier getData() {
return data;
}
- public void setData(DefaultStrategy data) {
+ public void setData(DefaultDataSupplier data) {
this.data = data;
}
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultDataSupplier.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultDataSupplier.java
Thu Feb 28 00:48:05 2008
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.registry.users.def;
+
+import org.wso2.registry.users.UserStoreException;
+
+/**
+ * Method in this class dominate how the DefaultRealm behaves. This enables
+ * different types of Realms to be written. For example users can be pulled out
+ * from tables with different names. Sample implementation is WSASRealm.
+ *
+ * Thrives to achieve loose coupling.
+ */
+public interface DefaultDataSupplier {
+
+ /**
+ * Retrives the column name given the column Id
+ */
+ public String getColumnName(int columnID);
+
+ /**
+ * Retrieves the authentication SQL
+ */
+ public String getAuthenticatorSQL(int sqlID);
+
+ /**
+ * Retrieves the SQL to perform User Store administration.
+ */
+ public String getUserStoreAdminSQL(int sqlID);
+
+ /**
+ * Retrieves the Access Control Admin SQL
+ */
+ public String getAccessControlAdminSQL(int sqlID);
+
+ /**
+ * Retrieves the Authorizer SQL
+ */
+ public String getAuthorizerSQL(int sqlID);
+
+ /**
+ * Retrieves the User Store Reader SQL
+ */
+ public String getUserStoreReaderSQL(int sqlID);
+
+ /**
+ * Retrieves the User ID
+ */
+ public String getUserId(String userName) throws UserStoreException;
+
+ /**
+ * Retrieves the Role ID
+ */
+ public String getRoleId(String roleName) throws UserStoreException;
+
+ /**
+ * Retrieves the User Roles
+ */
+ public String[] getUserRoles(String userName) throws UserStoreException;
+
+
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultRealm.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultRealm.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultRealm.java
Thu Feb 28 00:48:05 2008
@@ -30,7 +30,7 @@
import org.wso2.registry.users.UserStoreAdmin;
import org.wso2.registry.users.UserStoreException;
import org.wso2.registry.users.UserStoreReader;
-import org.wso2.registry.users.def.util.DefaultStrategyImpl;
+import org.wso2.registry.users.def.util.DefaultDataSupplierImpl;
/**
@@ -57,7 +57,7 @@
protected DataSource dataSource = null;
- protected DefaultStrategyImpl strategyObject = null;
+ protected DefaultDataSupplierImpl strategyObject = null;
private static Log log = LogFactory.getLog(DefaultRealm.class);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreAdmin.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreAdmin.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreAdmin.java
Thu Feb 28 00:48:05 2008
@@ -49,7 +49,7 @@
super(dataSource);
}
- public DefaultUserStoreAdmin(DataSource dataSource, DefaultStrategy store)
{
+ public DefaultUserStoreAdmin(DataSource dataSource, DefaultDataSupplier
store) {
super(dataSource, store);
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreReader.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreReader.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultUserStoreReader.java
Thu Feb 28 00:48:05 2008
@@ -31,7 +31,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.users.UserStoreException;
import org.wso2.registry.users.UserStoreReader;
-import org.wso2.registry.users.def.util.DefaultStrategyImpl;
+import org.wso2.registry.users.def.util.DefaultDataSupplierImpl;
@@ -45,19 +45,19 @@
private static Log log = LogFactory.getLog(DefaultUserStoreReader.class);
protected DataSource dataSource = null;
- protected DefaultStrategy data = null;
+ protected DefaultDataSupplier data = null;
public DefaultUserStoreReader(DataSource dataSource) {
this.dataSource = dataSource;
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
}
- public DefaultUserStoreReader(DataSource dataSource, DefaultStrategy
store) {
+ public DefaultUserStoreReader(DataSource dataSource, DefaultDataSupplier
store) {
this.dataSource = dataSource;
if (store != null) {
this.data = store;
} else {
- this.data = new DefaultStrategyImpl(dataSource);
+ this.data = new DefaultDataSupplierImpl(dataSource);
}
}
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/util/DefaultDataSupplierImpl.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/util/DefaultDataSupplierImpl.java
Thu Feb 28 00:48:05 2008
@@ -0,0 +1,353 @@
+/*
+ * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.registry.users.def.util;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.wso2.registry.users.UserStoreException;
+import org.wso2.registry.users.def.DefaultRealmConstants;
+import org.wso2.registry.users.def.DefaultDataSupplier;
+
+
+/**
+ * Represents the user store. If you change this object it will change the way
+ * the DefaultRealmBehaves.
+ */
+public class DefaultDataSupplierImpl implements DefaultDataSupplier {
+
+ protected DataSource dataSource = null;
+
+ public DefaultDataSupplierImpl(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public DefaultDataSupplierImpl() {
+
+ }
+
+ public String getColumnName(int columnID) {
+ String sqlString = null;
+ switch (columnID) {
+ case DefaultRealmConstants.COLUMN_ID_ATTR_NAME:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ATTR_NAME;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_ATTR_VALUE:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ATTR_VALUE;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_ID:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ID;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_USER_NAME:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_USER_NAME;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_ROLE_NAME:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ROLE_NAME;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_ROLE_ID:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ROLE_ID;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_USER_ID:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_USER_ID;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_IS_ALLOWED:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_IS_ALLOWED;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_CREDENTIAL:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_CREDENTIAL;
+ break;
+ case DefaultRealmConstants.COLUMN_ID_ACTION:
+ sqlString = DefaultRealmConstants.COLUMN_NAME_ACTION;
+ break;
+ default:
+ System.out.println("Null");
+ break;
+ }
+ return sqlString;
+
+ }
+
+ public String getAuthenticatorSQL(int sqlID) {
+ String sqlString = null;
+ switch (sqlID) {
+ case DefaultRealmConstants.GET_USER:
+ sqlString = DefaultRealmConstants.GET_USER_SQL;
+ break;
+ default:
+ System.out.println("Null");
+ break;
+ }
+ return sqlString;
+ }
+
+ public String getUserStoreAdminSQL(int sqlID) {
+ String sqlString = null;
+ switch (sqlID) {
+ case DefaultRealmConstants.ADD_USER:
+ sqlString = DefaultRealmConstants.ADD_USER_SQL;
+ break;
+ case DefaultRealmConstants.ADD_ROLE:
+ sqlString = DefaultRealmConstants.ADD_ROLE_SQL;
+ break;
+ case DefaultRealmConstants.ADD_USER_ROLE:
+ sqlString = DefaultRealmConstants.ADD_USER_ROLE_SQL;
+ break;
+ case DefaultRealmConstants.ADD_USER_ATTRIBUTE:
+ sqlString = DefaultRealmConstants.ADD_USER_ATTRIBUTE_SQL;
+ break;
+ case DefaultRealmConstants.ADD_ROLE_ATTRIBUTE:
+ sqlString = DefaultRealmConstants.ADD_ROLE_ATTRIBUTE_SQL;
+ break;
+ case DefaultRealmConstants.UPDATE_USER:
+ sqlString = DefaultRealmConstants.UPDATE_USER_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_USER:
+ sqlString = DefaultRealmConstants.DELETE_USER_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_ROLE:
+ sqlString = DefaultRealmConstants.DELETE_ROLE_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_USER_ROLE:
+ sqlString = DefaultRealmConstants.DELETE_USER_ROLE_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_ROLE_ATTRIBUTE:
+ sqlString = DefaultRealmConstants.DELETE_ROLE_ATTRIBUTE_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_USER_ATTRIBUTE:
+ sqlString = DefaultRealmConstants.DELETE_USER_ATTRIBUTE_SQL;
+ break;
+ case DefaultRealmConstants.GET_ROLE:
+ sqlString = DefaultRealmConstants.GET_ROLE_SQL;
+ break;
+ default:
+ System.out.println("Null");
+ break;
+ }
+ return sqlString;
+ }
+
+ public String getAccessControlAdminSQL(int sqlID) {
+ String sqlString = null;
+ switch (sqlID) {
+ case DefaultRealmConstants.ADD_PERMISSION:
+ sqlString = DefaultRealmConstants.ADD_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.ADD_ROLE_PERMISSION:
+ sqlString = DefaultRealmConstants.ADD_ROLE_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.ADD_USER_PERMISSION:
+ sqlString = DefaultRealmConstants.ADD_USER_PERMISSION_SQL;
+ break;
+
+ case DefaultRealmConstants.DELETE_PERMISSION_ON_RESOURCE:
+ sqlString =
DefaultRealmConstants.DELETE_PERMISSION_ON_RESOURCE_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_USER_PERMISSION:
+ sqlString = DefaultRealmConstants.DELETE_USER_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.DELETE_ROLE_PERMISSION:
+ sqlString = DefaultRealmConstants.DELETE_ROLE_PERMISSION_SQL;
+ break;
+
+ default:
+ break;
+ }
+ return sqlString;
+ }
+
+ public String getAuthorizerSQL(int sqlID) {
+ String sqlString = null;
+ switch (sqlID) {
+
+ case DefaultRealmConstants.GET_PERMISSION:
+ sqlString = DefaultRealmConstants.GET_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.GET_ROLE_AUTHORIZED:
+ sqlString = DefaultRealmConstants.GET_ROLE_AUTHORIZED_SQL;
+ break;
+ case DefaultRealmConstants.GET_USER_AUTHORIZED:
+ sqlString = DefaultRealmConstants.GET_USER_AUTHORIZED_SQL;
+ break;
+ case DefaultRealmConstants.GET_ALLOWED_ROLES_FOR_RESOURCE:
+ sqlString =
DefaultRealmConstants.GET_ALLOWED_ROLES_FOR_RESOURCE_SQL;
+ break;
+ case DefaultRealmConstants.GET_DENIED_ROLES_FOR_RESOURCE:
+ sqlString =
DefaultRealmConstants.GET_DENIED_ROLES_FOR_RESOURCE_SQL;
+ break;
+ case DefaultRealmConstants.GET_ALLOWED_USERS_ON_RESOURCE:
+ sqlString =
DefaultRealmConstants.GET_ALLOWED_USERS_ON_RESOURCE_SQL;
+ break;
+ case DefaultRealmConstants.GET_DENIED_USERS_ON_RESOURCE:
+ sqlString = DefaultRealmConstants.GET_DENIED_USERS_ON_RESOURCE_SQL;
+ break;
+ case DefaultRealmConstants.GET_ROLE_PERMISSION:
+ sqlString = DefaultRealmConstants.GET_ROLE_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.GET_USER_PERMISSION:
+ sqlString = DefaultRealmConstants.GET_USER_PERMISSION_SQL;
+ break;
+ case DefaultRealmConstants.GET_RESOURCE_PERMISSION:
+ sqlString = DefaultRealmConstants.GET_RESOURCE_PERMISSION_SQL;
+ break;
+ default:
+ break;
+ }
+ return sqlString;
+ }
+
+ public String getUserStoreReaderSQL(int sqlID) {
+ String sqlString = null;
+ switch (sqlID) {
+ case DefaultRealmConstants.GET_USER_ROLES:
+ sqlString = DefaultRealmConstants.GET_USER_ROLES_SQL;
+ break;
+ case DefaultRealmConstants.GET_ROLE_ATTRIBUTES:
+ sqlString = DefaultRealmConstants.GET_ROLE_ATTRIBUTES_SQL;
+ break;
+ case DefaultRealmConstants.GET_USER_ATTRIBUTES:
+ sqlString = DefaultRealmConstants.GET_USER_ATTRIBUTES_SQL;
+ break;
+ case DefaultRealmConstants.GET_ATTRIBUTE_NAMES:
+ sqlString = DefaultRealmConstants.GET_ATTRIBUTE_NAMES_SQL;
+ break;
+ case DefaultRealmConstants.GET_USERS_IN_ROLE:
+ sqlString = DefaultRealmConstants.GET_USERS_IN_ROLE_SQL;
+ break;
+ case DefaultRealmConstants.GET_USERS_WITH_PROPERTY:
+ sqlString = DefaultRealmConstants.GET_USERS_WITH_PROPERTY_SQL;
+ break;
+ case DefaultRealmConstants.GET_USERS_WITH_PROPERTY_VALUE:
+ sqlString =
DefaultRealmConstants.GET_USERS_WITH_PROPERTY_VALUE_SQL;
+ break;
+ case DefaultRealmConstants.GET_USERS_ALL:
+ sqlString = DefaultRealmConstants.GET_USERS_ALL_SQL;
+ break;
+ case DefaultRealmConstants.GET_ROLES_ALL:
+ sqlString = DefaultRealmConstants.GET_ROLES_ALL_SQL;
+ break;
+ default:
+ break;
+ }
+ return sqlString;
+ }
+
+ public String getUserId(String userName) throws UserStoreException {
+ String id = null;
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getUserIdStmt = dbConnection
+ .prepareStatement(DefaultRealmConstants.GET_USER_ID_SQL);
+ getUserIdStmt.setString(1, userName);
+ ResultSet rs = getUserIdStmt.executeQuery();
+ if (rs.next()) {
+ id = rs.getString(this
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ID));
+ }
+ getUserIdStmt.close();
+ } catch (SQLException e) {
+ throw new UserStoreException("errorReadingFromUserStore", e);
+ } finally {
+ try {
+ if (dbConnection != null) {
+ dbConnection.close();
+ }
+ } catch (SQLException e) {
+ throw new UserStoreException("errorClosingConnection", e);
+ }
+ }
+ return id;
+ }
+
+ public String getRoleId(String roleName) throws UserStoreException {
+ String id = null;
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getRolIdStmt =
dbConnection.prepareStatement(DefaultRealmConstants.GET_ROLE_ID_SQL);
+ getRolIdStmt.setString(1, roleName);
+ ResultSet rs = getRolIdStmt.executeQuery();
+ if (rs.next()) {
+ id = rs.getString(this
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ID));
+ }
+
+ getRolIdStmt.close();
+ } catch (SQLException e) {
+ throw new UserStoreException("errorReadingFromUserStore", e);
+ } finally {
+ try {
+ if (dbConnection != null) {
+ dbConnection.close();
+ }
+ } catch (SQLException e) {
+ throw new UserStoreException("errorClosingConnection", e);
+ }
+ }
+ return id;
+ }
+
+ public String[] getUserRoles(String userName) throws UserStoreException {
+ String[] names = new String[0];
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getUserRolesStmt = dbConnection
+
.prepareStatement(DefaultRealmConstants.GET_USER_ROLES_SQL);
+ getUserRolesStmt.setString(1, userName);
+ ResultSet rs = getUserRolesStmt.executeQuery();
+ List lst = new LinkedList();
+ String colName = this
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ROLE_NAME);
+ while (rs.next()) {
+ lst.add(rs.getString(colName));
+ }
+ if (lst.size() > 0) {
+ names = (String[]) lst.toArray(new String[lst.size()]);
+ }
+ getUserRolesStmt.close();
+ } catch (SQLException e) {
+ throw new UserStoreException("errorReadingFromUserStore", e);
+ } finally {
+ try {
+ if (dbConnection != null) {
+ dbConnection.close();
+ }
+ } catch (SQLException e) {
+ throw new UserStoreException("errorClosingConnection", e);
+ }
+ }
+ return names;
+ }
+}
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev