Author: dimuthul
Date: Fri Mar 7 00:12:15 2008
New Revision: 14572
Log:
Adding some more methods.
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAccessControlAdmin.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAuthorizer.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreAdmin.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreReader.java
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAccessControlAdmin.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAccessControlAdmin.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAccessControlAdmin.java
Fri Mar 7 00:12:15 2008
@@ -21,20 +21,17 @@
import org.wso2.usermanager.readwrite.util.UUIDGenerator;
-public class WSASAccessControlAdmin extends DefaultAuthorizer
- implements AccessControlAdmin{
+public class WSASAccessControlAdmin extends WSASAuthorizer
+ implements AccessControlAdmin{
private static Log log =
LogFactory.getLog(DefaultAccessControlAdmin.class);
+
public WSASAccessControlAdmin(DataSource dataSource, String algo) {
super(dataSource, algo);
}
- public WSASAccessControlAdmin(DataSource dataSource, String algo,
- DefaultDataSupplier store) {
- super(dataSource, algo, store);
- }
-
+
public WSASAccessControlAdmin(DataSource dataSource,
DefaultDataSupplier store) {
super(dataSource, DefaultRealmConfig.PERMISSION_BLOCK_FIRST, store);
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAuthorizer.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAuthorizer.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASAuthorizer.java
Fri Mar 7 00:12:15 2008
@@ -18,7 +18,7 @@
import org.wso2.registry.users.def.DefaultRealmConstants;
import org.wso2.registry.users.def.util.DefaultDataSupplierImpl;
-public class WSASAuthorizer implements Authorizer {
+public class WSASAuthorizer implements Authorizer {
/** DBCP datasource */
protected DataSource dataSource = null;
@@ -351,5 +351,7 @@
}
return result;
}
+
+
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreAdmin.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreAdmin.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreAdmin.java
Fri Mar 7 00:12:15 2008
@@ -117,13 +117,13 @@
}
dbConnection.setAutoCommit(false);
PreparedStatement deleteRolePropsStmt = dbConnection
- .prepareStatement(strategy
+ .prepareStatement(data
.getUserStoreAdminSQL(DefaultRealmConstants.DELETE_ROLE_ATTRIBUTE));
deleteRolePropsStmt.setString(1, roleName);
deleteRolePropsStmt.executeUpdate();
PreparedStatement setRolePropertiesStmt = dbConnection
- .prepareStatement(strategy
+ .prepareStatement(data
.getUserStoreAdminSQL(DefaultRealmConstants.ADD_ROLE_ATTRIBUTE));
Iterator ite = properties.entrySet().iterator();
@@ -172,13 +172,13 @@
}
dbConnection.setAutoCommit(false);
PreparedStatement deleteUserPropsStmt = dbConnection
- .prepareStatement(strategy
+ .prepareStatement(data
.getUserStoreAdminSQL(DefaultRealmConstants.DELETE_USER_ATTRIBUTE));
deleteUserPropsStmt.setString(1, userName);
deleteUserPropsStmt.executeUpdate();
PreparedStatement setUserPropertiesStmt = dbConnection
- .prepareStatement(strategy
+ .prepareStatement(data
.getUserStoreAdminSQL(DefaultRealmConstants.ADD_USER_ATTRIBUTE));
if (properties != null) {
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreReader.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreReader.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/realm/wsas/WSASUserStoreReader.java
Fri Mar 7 00:12:15 2008
@@ -1,6 +1,11 @@
package org.wso2.mashup.realm.wsas;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -13,20 +18,21 @@
import org.wso2.registry.users.def.DefaultDataSupplier;
import org.wso2.registry.users.def.DefaultUserStoreReader;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.readwrite.DefaultRealmConstants;
import org.wso2.wsas.admin.service.UserAdmin;
import org.wso2.wsas.admin.service.util.RoleData;
import org.wso2.wsas.admin.service.util.UserData;
public class WSASUserStoreReader implements UserStoreReader {
- private UserStoreReader defaultReader = null;
protected DataSource dataSource = null;
- protected DefaultDataSupplier strategy = null;
+ protected DefaultDataSupplier data = null;
public WSASUserStoreReader(DataSource dSource, DefaultDataSupplier
strategyObject) throws UserStoreException{
- strategy = strategyObject;
- defaultReader = new DefaultUserStoreReader(dSource, strategy);
+ data = strategyObject;
dataSource = dSource;
+
}
public String[] getAllRoleNames() throws UserStoreException {
@@ -48,20 +54,164 @@
}
public Map getRoleProperties(String roleName) throws UserStoreException {
- return defaultReader.getRoleProperties(roleName);
+ Map props = new HashMap();
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getRolePropertiesStmt = dbConnection
+ .prepareStatement(data
+
.getUserStoreReaderSQL(DefaultRealmConstants.GET_ROLE_ATTRIBUTES));
+ getRolePropertiesStmt.setString(1, roleName);
+ ResultSet rs = getRolePropertiesStmt.executeQuery();
+ String colAttrName = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ATTR_NAME);
+ String colAttrValue = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ATTR_VALUE);
+ while (rs.next()) {
+ String name = rs.getString(colAttrName);
+ String value = rs.getString(colAttrValue);
+ props.put(name, value);
+ }
+ getRolePropertiesStmt.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 props;
+
}
public String[] getUserNamesWithPropertyValue(String propertyName,
String propetyValue) throws UserStoreException {
- return defaultReader.getUserNamesWithPropertyValue(propertyName,
propetyValue);
+ String[] names = new String[0];
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getPropValue = null;
+
+ if (propertyName != null && propertyName.length() != 0) {
+ getPropValue = dbConnection
+ .prepareStatement(data
+
.getUserStoreReaderSQL(DefaultRealmConstants.GET_USERS_WITH_PROPERTY));
+ getPropValue.setString(1, propertyName);
+ getPropValue.setString(2, propetyValue);
+ } else {
+ getPropValue = dbConnection
+ .prepareStatement(data
+
.getUserStoreReaderSQL(DefaultRealmConstants.GET_USERS_WITH_PROPERTY_VALUE));
+ getPropValue.setString(1, propetyValue);
+ }
+
+ ResultSet rs = getPropValue.executeQuery();
+ String colName = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_USER_NAME);
+ List lst = new ArrayList();
+ while (rs.next()) {
+ lst.add(rs.getString(colName));
+ }
+ names = (String[]) lst.toArray(new String[lst.size()]);
+ getPropValue.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;
+
}
public Map getUserProperties(String userName) throws UserStoreException {
- return defaultReader.getUserProperties(userName);
+ Map props = new HashMap();
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getUserPropertiesStmt = dbConnection
+ .prepareStatement(data
+
.getUserStoreReaderSQL(DefaultRealmConstants.GET_USER_ATTRIBUTES));
+ getUserPropertiesStmt.setString(1, userName);
+ ResultSet rs = getUserPropertiesStmt.executeQuery();
+ String colAttrName = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ATTR_NAME);
+ String colAttrValue = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ATTR_VALUE);
+ while (rs.next()) {
+ String name = rs.getString(colAttrName);
+ String value = rs.getString(colAttrValue);
+ props.put(name, value);
+ }
+ getUserPropertiesStmt.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 props;
}
public String[] getUserPropertyNames() throws UserStoreException {
- return defaultReader.getUserPropertyNames();
+ String[] propNames = new String[0];
+ Connection dbConnection = null;
+ try {
+ dbConnection = dataSource.getConnection();
+ if (dbConnection == null) {
+ throw new UserStoreException("null_connection");
+ }
+ dbConnection.setAutoCommit(false);
+ PreparedStatement getUserAttributeNamesStmt = dbConnection
+ .prepareStatement(data
+
.getUserStoreReaderSQL(DefaultRealmConstants.GET_ATTRIBUTE_NAMES));
+ ResultSet rs = getUserAttributeNamesStmt.executeQuery();
+ String colName = data
+ .getColumnName(DefaultRealmConstants.COLUMN_ID_ATTR_NAME);
+ List lst = new ArrayList();
+ while (rs.next()) {
+ lst.add(rs.getString(colName));
+ }
+ propNames = (String[]) lst.toArray(new String[lst.size()]);
+ getUserAttributeNamesStmt.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 propNames;
}
public String[] getUserRoles(String userName) throws UserStoreException {
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev