[wsas-java-dev] svn commit r260 - in wsas/java/trunk/modules:
admin/src/org/wso2/wsas/admin/service core/conf/hibernate
www/extensions/core/js
svn at wso2.com
svn at wso2.com
Tue Dec 19 03:44:31 PST 2006
Author: azeez
Date: Tue Dec 19 03:44:30 2006
New Revision: 260
Modified:
wsas/java/trunk/modules/admin/src/org/wso2/wsas/admin/service/UserAdmin.java
wsas/java/trunk/modules/core/conf/hibernate/wso2wsas.hbm.xml
wsas/java/trunk/modules/www/extensions/core/js/users.js
Log:
Fix for WSAS-174 + method name changed
Modified: wsas/java/trunk/modules/admin/src/org/wso2/wsas/admin/service/UserAdmin.java
==============================================================================
--- wsas/java/trunk/modules/admin/src/org/wso2/wsas/admin/service/UserAdmin.java (original)
+++ wsas/java/trunk/modules/admin/src/org/wso2/wsas/admin/service/UserAdmin.java Tue Dec 19 03:44:30 2006
@@ -28,7 +28,6 @@
import org.wso2.wsas.util.HibernateConfigFactory;
import org.wso2.wsf.common.util.ServerConfiguration;
import org.wso2.wsf.common.ServerException;
-import org.wso2.wsf.common.util.ServerConfiguration;
import org.wso2.wsf.common.tools.security.CryptoUtil;
import org.wso2.wsf.common.tools.security.CryptoException;
@@ -39,10 +38,10 @@
* Admin service to manage WSO2 WSAS users
*/
public class UserAdmin extends AbstractAdmin {
- private PersistenceManager persistenceManager;
+ private PersistenceManager pm;
public UserAdmin() {
- persistenceManager = new PersistenceManager(HibernateConfigFactory.getDefaultConfig(
+ pm = new PersistenceManager(HibernateConfigFactory.getDefaultConfig(
ServerConstants.WSO2WSAS_HB_CONFIG_KEY));
}
@@ -71,7 +70,7 @@
ServiceUserRoleDO userRole = new ServiceUserRoleDO();
userRole.setRole(ServerConstants.ADMIN_ROLE);
- persistenceManager.addUser(admin);
+ pm.addUser(admin);
} catch (CryptoException e) {
throw new AxisFault(e);
} catch (ServiceUserAlreadyExistsException e) {
@@ -106,7 +105,7 @@
ServiceUserRoleDO userRole = new ServiceUserRoleDO();
userRole.setRole(ServerConstants.ADMIN_ROLE);
- persistenceManager.updateUser(admin);
+ pm.updateUser(admin);
} catch (Exception e) {
throw new AxisFault(e);
}
@@ -126,7 +125,7 @@
return false;
}
- ServiceUserDO serviceUserDO = persistenceManager.getUser(username);
+ ServiceUserDO serviceUserDO = pm.getUser(username);
if (serviceUserDO == null) {
return false;
@@ -148,7 +147,7 @@
}
serviceUserDO.setPassword(cryptoUtil.encryptAndBase64Encode(password.getBytes()));
- persistenceManager.updateUser(serviceUserDO);
+ pm.updateUser(serviceUserDO);
return true;
}
@@ -159,13 +158,13 @@
return false;
}
- ServiceUserDO serviceUserDO = persistenceManager.getUser(username);
+ ServiceUserDO serviceUserDO = pm.getUser(username);
if (serviceUserDO == null) {
return false;
}
- persistenceManager.updateUser(serviceUserDO);
+ pm.updateUser(serviceUserDO);
return true;
}
@@ -175,7 +174,7 @@
throw new AxisFault("Username cannot be null or empty");
}
- ServiceUserDO serviceUserDO = persistenceManager.getUser(username);
+ ServiceUserDO serviceUserDO = pm.getUser(username);
if (serviceUserDO == null) {
throw new AxisFault("Invalid user , does not exist in the system" +
@@ -183,21 +182,31 @@
}
try {
- persistenceManager.removeUser(username);
+ pm.removeUser(username);
} catch (ServiceUserNotFoundException e) {
throw new AxisFault(e.getMessage());
}
}
- public void addUserWithRole(String username, String role)
- throws AxisFault {
- // added role to a already existing user
+ /**
+ * Assign a role to an existing user
+ *
+ * @param username
+ * @param role
+ * @throws AxisFault
+ */
+ public void assignRoleToUser(String username, String role) throws AxisFault {
try {
- ServiceUserDO serviceUserDO = persistenceManager.getUser(username);
+ ServiceUserDO serviceUserDO = pm.getUser(username);
if (serviceUserDO != null) {
- ServiceUserRoleDO roleDO = persistenceManager.getUserRole(role);
- persistenceManager.addRole(username, roleDO);
+ ServiceUserRoleDO roleDO = pm.getUserRole(role);
+
+ if(serviceUserDO.getRoles().contains(roleDO)){
+ throw new AxisFault("User \'" + username + "\' already has role \'" +
+ role + "\'.");
+ }
+ pm.addRole(username, roleDO);
}
} catch (Exception e) {
throw new AxisFault(e);
@@ -232,10 +241,10 @@
serviceUserDO.setPassword(cryptoUtil.encryptAndBase64Encode(
password.getBytes()));
serviceUserDO.setDescription(description);
- persistenceManager.addUser(serviceUserDO);
+ pm.addUser(serviceUserDO);
- ServiceUserRoleDO roleDO = persistenceManager.getUserRole(role);
- persistenceManager.addRole(username, roleDO);
+ ServiceUserRoleDO roleDO = pm.getUserRole(role);
+ pm.addRole(username, roleDO);
} catch (ServiceUserAlreadyExistsException e) {
return "User with username " + username + " already exists!";
} catch (CryptoException e) {
@@ -246,7 +255,7 @@
}
public UserData[] getUserNames() throws AxisFault {
- ServiceUserDO[] users = persistenceManager.getUsers();
+ ServiceUserDO[] users = pm.getUsers();
if ((users == null) || (users.length == 0)) {
return new UserData[0];
@@ -258,7 +267,7 @@
for (int i = 0; i < users.length; i++) {
serviceUser = users[i];
- ServiceUserRoleDO[] roles = persistenceManager.getUserSpecificRoles(serviceUser.getUsername());
+ ServiceUserRoleDO[] roles = pm.getUserSpecificRoles(serviceUser.getUsername());
RoleData[] roleData = new RoleData[roles.length];
ServiceUserRoleDO serviceRole;
@@ -282,7 +291,7 @@
}
public String[] getUsers() throws AxisFault {
- ServiceUserDO[] users = persistenceManager.getUsers();
+ ServiceUserDO[] users = pm.getUsers();
if ((users == null) || (users.length == 0)) {
return new String[0];
@@ -308,18 +317,15 @@
serviceUserRole.setDescription(description);
try {
- persistenceManager.addUserRole(serviceUserRole);
+ pm.addUserRole(serviceUserRole);
} catch (UserRoleAlreadyExistsException e) {
- // throw new AxisFault("User role " + role + " already exists", e);
- //TODO: we need to handle this properly
return false;
}
-
return true;
}
public String[] getRoleNames() throws AxisFault {
- ServiceUserRoleDO[] userRoles = persistenceManager.getUserRoles();
+ ServiceUserRoleDO[] userRoles = pm.getUserRoles();
if ((userRoles == null) || (userRoles.length == 0)) {
return new String[0];
@@ -335,7 +341,7 @@
}
public RoleData[] getRoleNamesAndDescriptions() throws AxisFault {
- ServiceUserRoleDO[] userRoles = persistenceManager.getUserRoles();
+ ServiceUserRoleDO[] userRoles = pm.getUserRoles();
if ((userRoles == null) || (userRoles.length == 0)) {
return new RoleData[0];
@@ -357,19 +363,19 @@
}
public void deleteUser(String username) throws AxisFault {
- persistenceManager.deleteUser(username);
+ pm.deleteUser(username);
}
public String deleteRoleCompletely(String role) throws AxisFault {
try {
- ServiceUserDO[] userDOs = persistenceManager.getUsers();
+ ServiceUserDO[] userDOs = pm.getUsers();
//Need not to check null because admin is a trivial super user
String usersWithRole = "";
for (int i = 0; i < userDOs.length; i++) {
ServiceUserDO userDO = userDOs[i];
- ServiceUserRoleDO[] roleDOs = persistenceManager.getUserSpecificRoles(userDO.getUsername());
+ ServiceUserRoleDO[] roleDOs = pm.getUserSpecificRoles(userDO.getUsername());
if (roleDOs.length == 1) {
if (roleDOs[0].getRole().equalsIgnoreCase(role.trim())) {
@@ -379,26 +385,25 @@
}
if (usersWithRole.length() != 0) {
- return deleteStatment(false, usersWithRole, role);
+ return getDeleteMsg(false, usersWithRole, role);
}
} catch (Exception e) {
// e.printStackTrace();
throw new AxisFault(e);
}
- persistenceManager.deleteRole(role);
+ pm.deleteRole(role);
- return deleteStatment(true, null, role);
+ return getDeleteMsg(true, null, role);
}
- private String deleteStatment(boolean canDelete, String users, String role) {
+ private String getDeleteMsg(boolean canDelete, String users, String role) {
String cannotDeleteStatement = "Role '" + role +
"' cannot be deleted.\n" + "since it is associated with users; " +
users + " having only this role.\n" +
"Assign these users with a different role before trying to " +
"delete this role.";
- String canDeleteStatement = "Role '" + role +
- "' deleted successfully.";
+ String canDeleteStatement = "Role '" + role + "' deleted successfully.";
if (canDelete) {
return canDeleteStatement;
@@ -417,18 +422,18 @@
throw new ServerException("Role is invalid");
}
- ServiceUserDO serviceUserDO = persistenceManager.getUser(username);
+ ServiceUserDO serviceUserDO = pm.getUser(username);
if (serviceUserDO == null) {
throw new ServerException("ServiceUser is invalid" + username);
}
- ServiceUserRoleDO[] roles = persistenceManager.getUserSpecificRoles(username);
+ ServiceUserRoleDO[] roles = pm.getUserSpecificRoles(username);
if (roles.length == 1) {
return false;
} else {
- persistenceManager.deleteRoleFromUser(username, role);
+ pm.deleteRoleFromUser(username, role);
return true;
}
Modified: wsas/java/trunk/modules/core/conf/hibernate/wso2wsas.hbm.xml
==============================================================================
--- wsas/java/trunk/modules/core/conf/hibernate/wso2wsas.hbm.xml (original)
+++ wsas/java/trunk/modules/core/conf/hibernate/wso2wsas.hbm.xml Tue Dec 19 03:44:30 2006
@@ -297,7 +297,7 @@
<property name="password" column="c_password" not-null="true"/>
<property name="description" column="c_user_description" not-null="false"/>
<set name="roles"
- table="user_role_link_t" inverse="false" sort="unsorted">
+ table="user_role_link_t" inverse="false" sort="unsorted" lazy="false">
<key column="c_user_id"/>
<many-to-many class="org.wso2.wsas.persistence.dataobject.ServiceUserRoleDO"
column="c_user_role_id"/>
Modified: wsas/java/trunk/modules/www/extensions/core/js/users.js
==============================================================================
--- wsas/java/trunk/modules/www/extensions/core/js/users.js (original)
+++ wsas/java/trunk/modules/www/extensions/core/js/users.js Tue Dec 19 03:44:30 2006
@@ -391,13 +391,13 @@
rl = role[role.selectedIndex].value;
- var body_xml = '<req:addUserWithRoleRequest xmlns:req="http://org.apache.axis2/xsd">\n' +
+ var body_xml = '<req:assignRoleToUser xmlns:req="http://org.apache.axis2/xsd">\n' +
'<req:username><![CDATA[' + currentUserName + ']]></req:username>\n'+
'<req:role><![CDATA[' + rl + ']]></req:role>\n'+
- '</req:addUserWithRoleRequest>\n';
+ '</req:assignRoleToUser>\n';
var callURL = serverURL + "/" + "UserAdmin" + "/" ;
- send("addUserWithRole", body_xml, "", callURL, "", false, addUserWtihRoleCallback);
+ send("assignRoleToUser", body_xml, "", callURL, "", false, addUserWtihRoleCallback);
}
More information about the Wsas-java-dev
mailing list