You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2014/10/01 14:34:47 UTC
[2/4] git commit: Code review changes
Code review changes
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e1eb346d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e1eb346d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e1eb346d
Branch: refs/heads/master
Commit: e1eb346dd472bed6df5b05a365d244bc04d916d8
Parents: 4d7491f
Author: lasinducharith <la...@gmail.com>
Authored: Wed Oct 1 17:31:58 2014 +0530
Committer: lasinducharith <la...@gmail.com>
Committed: Wed Oct 1 17:37:10 2014 +0530
----------------------------------------------------------------------
.../manager/listener/TenantUserRoleCreator.java | 17 ++--
.../manager/user/mgt/StratosUserManager.java | 35 ++++----
.../mgt/exception/UserManagementException.java | 19 +----
.../stratos/manager/utils/UserRoleCreator.java | 7 +-
.../rest/endpoint/services/ServiceUtils.java | 84 --------------------
.../rest/endpoint/services/StratosAdmin.java | 81 ++++++++++++++++---
6 files changed, 98 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
index 5bd9ba3..a3b0532 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
@@ -26,21 +26,18 @@ import org.apache.stratos.common.exception.StratosException;
import org.apache.stratos.common.listeners.TenantMgtListener;
import org.apache.stratos.manager.internal.DataHolder;
import org.apache.stratos.manager.user.mgt.exception.UserManagementException;
-import org.apache.stratos.manager.utils.CartridgeConstants;
import org.apache.stratos.manager.utils.UserRoleCreator;
-import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.api.UserRealm;
-import org.wso2.carbon.user.mgt.UserMgtConstants;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
+/**
+ * Listener for Tenant create event to create a new Role
+ */
public class TenantUserRoleCreator implements TenantMgtListener {
- private transient static final Log log = LogFactory.getLog(TenantUserRoleCreator.class);
+ private static final Log log = LogFactory.getLog(TenantUserRoleCreator.class);
/**
* Create an 'user' role at tenant creation time
@@ -63,10 +60,12 @@ public class TenantUserRoleCreator implements TenantMgtListener {
UserRoleCreator.createTenantUserRole(userStoreManager);
} catch (UserStoreException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error while retrieving the user store for tenant : "+ tenantInfo.getTenantDomain();
+ log.error(msg, e);
throw new StratosException(e.getMessage(), e);
} catch (UserManagementException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error while creating the user role in tenant : "+ tenantInfo.getTenantDomain();
+ log.error(msg, e);
throw new StratosException(e.getMessage(), e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/StratosUserManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/StratosUserManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/StratosUserManager.java
index 59c2d8e..ad00e3d 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/StratosUserManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/StratosUserManager.java
@@ -22,15 +22,11 @@ package org.apache.stratos.manager.user.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.manager.internal.DataHolder;
import org.apache.stratos.manager.user.mgt.beans.UserInfoBean;
import org.apache.stratos.manager.user.mgt.exception.UserManagementException;
-import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.UserCoreConstants;
-import org.wso2.carbon.user.core.service.RealmService;
import java.util.ArrayList;
import java.util.HashMap;
@@ -50,8 +46,8 @@ public class StratosUserManager {
/**
* Add a user to the user-store of the particular tenant
*
- * @param userStoreManager
- * @param userInfoBean
+ * @param userStoreManager UserStoreManager
+ * @param userInfoBean UserInfoBean
* @throws UserManagementException
*/
public void addUser(UserStoreManager userStoreManager, UserInfoBean userInfoBean)
@@ -77,7 +73,8 @@ public class StratosUserManager {
}
} catch (UserStoreException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error in adding the user : "+ userInfoBean.getUserName();
+ log.error(msg, e);
throw new UserManagementException(e.getMessage(), e);
}
}
@@ -85,8 +82,8 @@ public class StratosUserManager {
/**
* Delete the user with the given username in the relevant tenant space
*
- * @param userStoreManager
- * @param userName
+ * @param userStoreManager UserStoreManager
+ * @param userName UserName
* @throws UserManagementException
*/
public void deleteUser(UserStoreManager userStoreManager, String userName)
@@ -95,7 +92,8 @@ public class StratosUserManager {
try {
userStoreManager.deleteUser(userName);
} catch (UserStoreException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error in deleting the user : "+ userName;
+ log.error(msg, e);
throw new UserManagementException(e.getMessage(), e);
}
}
@@ -104,8 +102,8 @@ public class StratosUserManager {
/**
* Updates the user info given the new UserInfoBean
*
- * @param userStoreManager
- * @param userInfoBean
+ * @param userStoreManager UserStoreManager
+ * @param userInfoBean UserInfoBean
* @throws UserManagementException
*/
public void updateUser(UserStoreManager userStoreManager, UserInfoBean userInfoBean)
@@ -119,11 +117,6 @@ public class StratosUserManager {
String[] newRoles = new String[1];
newRoles[0] = userInfoBean.getRole();
- Map<String, String> claims = new HashMap<String, String>();
-
- claims.put(UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS, userInfoBean.getEmail());
- claims.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME, userInfoBean.getFirstName());
- claims.put(UserCoreConstants.ClaimTypeURIs.SURNAME, userInfoBean.getLastName());
userStoreManager.updateRoleListOfUser(userInfoBean.getUserName(), getRefinedListOfRolesOfUser(userStoreManager, userInfoBean.getUserName()), newRoles);
userStoreManager.setUserClaimValue(userInfoBean.getUserName(), UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS, userInfoBean.getEmail(), userInfoBean.getProfileName());
@@ -133,7 +126,8 @@ public class StratosUserManager {
}
} catch (UserStoreException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error in updating the user : "+ userInfoBean.getUserName();
+ log.error(msg, e);
throw new UserManagementException(e.getMessage(), e);
}
@@ -149,7 +143,7 @@ public class StratosUserManager {
public List<UserInfoBean> getAllUsers(UserStoreManager userStoreManager)
throws UserManagementException {
- String[] users = null;
+ String[] users;
List<UserInfoBean> userList = new ArrayList<UserInfoBean>();
try {
@@ -164,7 +158,8 @@ public class StratosUserManager {
}
} catch (UserStoreException e) {
- log.error(e.getMessage(), e);
+ String msg = "Error in listing users";
+ log.error(msg, e);
throw new UserManagementException(e.getMessage(), e);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/exception/UserManagementException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/exception/UserManagementException.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/exception/UserManagementException.java
index 1fb8b62..ba75eac 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/exception/UserManagementException.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/user/mgt/exception/UserManagementException.java
@@ -22,20 +22,7 @@ package org.apache.stratos.manager.user.mgt.exception;
public class UserManagementException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public UserManagementException() {
- }
-
- public UserManagementException(String message) {
- super(message);
- }
-
- public UserManagementException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public UserManagementException(Throwable cause) {
- super(cause);
- }
+ public UserManagementException(String message, Throwable cause) {
+ super(message, cause);
}
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/UserRoleCreator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/UserRoleCreator.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/UserRoleCreator.java
index a6021fa..d511b65 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/UserRoleCreator.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/UserRoleCreator.java
@@ -22,25 +22,22 @@ package org.apache.stratos.manager.utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.internal.DataHolder;
import org.apache.stratos.manager.user.mgt.exception.UserManagementException;
import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
-import org.wso2.carbon.user.core.UserRealm;
-import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.mgt.UserMgtConstants;
public class UserRoleCreator {
- private transient static final Log log = LogFactory.getLog(UserRoleCreator.class);
- private static String userRole = "Internal/user";
+ private static final Log log = LogFactory.getLog(UserRoleCreator.class);
/**
* Creating a Internal/user Role at Carbon Server Start-up
*/
public static void createTenantUserRole(UserStoreManager manager) throws UserManagementException{
+ String userRole = "Internal/user";
try {
if (!manager.isExistingRole(userRole)) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index ef1157b..a40286a 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -48,9 +48,6 @@ import org.apache.stratos.manager.subscription.CartridgeSubscription;
import org.apache.stratos.manager.subscription.DataCartridgeSubscription;
import org.apache.stratos.manager.subscription.SubscriptionData;
import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
-import org.apache.stratos.manager.user.mgt.StratosUserManager;
-import org.apache.stratos.manager.user.mgt.beans.UserInfoBean;
-import org.apache.stratos.manager.user.mgt.exception.UserManagementException;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
import org.apache.stratos.messaging.domain.topology.Cluster;
@@ -73,10 +70,6 @@ import org.apache.stratos.rest.endpoint.bean.repositoryNotificationInfoBean.Payl
import org.apache.stratos.rest.endpoint.bean.subscription.domain.SubscriptionDomainBean;
import org.apache.stratos.rest.endpoint.bean.util.converter.PojoConverter;
import org.apache.stratos.rest.endpoint.exception.RestAPIException;
-import org.wso2.carbon.context.CarbonContext;
-import org.wso2.carbon.user.api.UserRealm;
-import org.wso2.carbon.user.api.UserStoreException;
-import org.wso2.carbon.user.api.UserStoreManager;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.rmi.RemoteException;
@@ -92,7 +85,6 @@ public class ServiceUtils {
private static Log log = LogFactory.getLog(ServiceUtils.class);
private static ServiceDeploymentManager serviceDeploymentManager = new ServiceDeploymentManager();
- private static StratosUserManager stratosUserManager = new StratosUserManager();
static void deployCartridge(CartridgeDefinitionBean cartridgeDefinitionBean, ConfigurationContext ctxt,
String userName, String tenantDomain) throws RestAPIException {
@@ -1267,83 +1259,7 @@ public class ServiceUtils {
}
- public static void addUser(UserInfoBean userInfoBean) throws RestAPIException {
- try {
-
- stratosUserManager.addUser(getTenantUserStoreManager(), userInfoBean);
-
- } catch (UserManagementException e) {
- log.error(e.getMessage(), e);
- throw new RestAPIException(e.getMessage(), e);
- }
- log.info("Successfully added an user with Username " + userInfoBean.getUserName());
- }
-
- public static void updateUser(UserInfoBean userInfoBean) throws RestAPIException {
-
- try {
-
- stratosUserManager.updateUser(getTenantUserStoreManager(), userInfoBean);
-
- } catch (UserManagementException e) {
- log.error(e.getMessage(), e);
- throw new RestAPIException(e.getMessage(), e);
- }
- log.info("Successfully updated an user with Username " + userInfoBean.getUserName());
- }
-
- public static void deleteUser(String userName) throws RestAPIException {
-
- try {
-
- stratosUserManager.deleteUser(getTenantUserStoreManager(), userName);
-
- } catch (UserManagementException e) {
- log.error(e.getMessage(), e);
- throw new RestAPIException(e.getMessage(), e);
- }
- log.info("Successfully deleted an user with Username " + userName);
- }
-
- public static List<UserInfoBean> getAllUsers() throws RestAPIException {
-
- List<UserInfoBean> userList = null;
-
- try {
-
- userList = stratosUserManager.getAllUsers(getTenantUserStoreManager());
-
- } catch (UserManagementException e) {
- log.error(e.getMessage(), e);
- throw new RestAPIException(e.getMessage(), e);
- }
- return userList;
- }
-
- /**
- * Get Tenant aware UserStoreManager
- *
- * @return UserStoreManager
- * @throws RestAPIException
- */
- private static UserStoreManager getTenantUserStoreManager() throws RestAPIException {
-
- CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
- UserRealm userRealm = null;
- UserStoreManager userStoreManager = null;
-
- try {
- userRealm = carbonContext.getUserRealm();
- userStoreManager = userRealm.getUserStoreManager();
-
- } catch (UserStoreException e) {
- log.error(e.getMessage(), e);
- throw new RestAPIException(e.getMessage(), e);
- }
-
- return userStoreManager;
- }
public static boolean deployKubernetesGroup(KubernetesGroup kubernetesGroupBean) throws RestAPIException {
http://git-wip-us.apache.org/repos/asf/stratos/blob/e1eb346d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
index c8980b2..2a6bd82 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
@@ -31,7 +31,9 @@ import org.apache.stratos.manager.exception.DomainMappingExistsException;
import org.apache.stratos.manager.exception.ServiceDoesNotExistException;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
import org.apache.stratos.manager.subscription.SubscriptionDomain;
+import org.apache.stratos.manager.user.mgt.StratosUserManager;
import org.apache.stratos.manager.user.mgt.beans.UserInfoBean;
+import org.apache.stratos.manager.user.mgt.exception.UserManagementException;
import org.apache.stratos.rest.endpoint.ServiceHolder;
import org.apache.stratos.rest.endpoint.Utils;
import org.apache.stratos.rest.endpoint.annotation.AuthorizationAction;
@@ -55,6 +57,7 @@ import org.apache.stratos.rest.endpoint.exception.RestAPIException;
import org.apache.stratos.rest.endpoint.exception.TenantNotFoundException;
import org.apache.stratos.tenant.mgt.core.TenantPersistor;
import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
+import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
@@ -1148,14 +1151,23 @@ public class StratosAdmin extends AbstractAdmin {
}
return Response.status(Response.Status.NOT_FOUND).build();
}
-
@POST
@Path("/user")
@Consumes("application/json")
@Produces("application/json")
@AuthorizationAction("/permission/admin/manage/add/users")
public Response addUser(UserInfoBean userInfoBean) throws RestAPIException {
- ServiceUtils.addUser(userInfoBean);
+
+ StratosUserManager stratosUserManager = new StratosUserManager();
+
+ try {
+ stratosUserManager.addUser(getTenantUserStoreManager(), userInfoBean);
+
+ } catch (UserManagementException e) {
+ log.error(e.getMessage(), e);
+ throw new RestAPIException(e.getMessage(), e);
+ }
+ log.info("Successfully added an user with Username " + userInfoBean.getUserName());
URI url = uriInfo.getAbsolutePathBuilder().path(userInfoBean.getUserName()).build();
return Response.created(url).build();
}
@@ -1166,7 +1178,17 @@ public class StratosAdmin extends AbstractAdmin {
@Produces("application/json")
@AuthorizationAction("/permission/admin/manage/add/users")
public Response deleteUser(@PathParam("userName") String userName) throws RestAPIException {
- ServiceUtils.deleteUser(userName);
+
+ StratosUserManager stratosUserManager = new StratosUserManager();
+
+ try {
+ stratosUserManager.deleteUser(getTenantUserStoreManager(), userName);
+
+ } catch (UserManagementException e) {
+ log.error(e.getMessage(), e);
+ throw new RestAPIException(e.getMessage(), e);
+ }
+ log.info("Successfully deleted an user with Username " + userName);
return Response.noContent().build();
}
@@ -1176,7 +1198,17 @@ public class StratosAdmin extends AbstractAdmin {
@Produces("application/json")
@AuthorizationAction("/permission/admin/manage/add/users")
public Response updateUser(UserInfoBean userInfoBean) throws RestAPIException {
- ServiceUtils.updateUser(userInfoBean);
+
+ StratosUserManager stratosUserManager = new StratosUserManager();
+
+ try {
+ stratosUserManager.updateUser(getTenantUserStoreManager(), userInfoBean);
+
+ } catch (UserManagementException e) {
+ log.error(e.getMessage(), e);
+ throw new RestAPIException(e.getMessage(), e);
+ }
+ log.info("Successfully updated an user with Username " + userInfoBean.getUserName());
URI url = uriInfo.getAbsolutePathBuilder().path(userInfoBean.getUserName()).build();
return Response.created(url).build();
}
@@ -1185,18 +1217,45 @@ public class StratosAdmin extends AbstractAdmin {
@Path("/user/list")
@Produces("application/json")
@AuthorizationAction("/permission/admin/manage/add/users")
- public UserInfoBean[] retrieveUsers() throws RestAPIException {
- List<UserInfoBean> userList = null;
+ public UserInfoBean[] listUsers() throws RestAPIException {
+
+ StratosUserManager stratosUserManager = new StratosUserManager();
+ List<UserInfoBean> userList;
+
try {
- userList = ServiceUtils.getAllUsers();
- } catch (Exception e) {
- String msg = "Error in retrieving users";
- log.error(msg, e);
- throw new RestAPIException(msg);
+ userList = stratosUserManager.getAllUsers(getTenantUserStoreManager());
+
+ } catch (UserManagementException e) {
+ log.error(e.getMessage(), e);
+ throw new RestAPIException(e.getMessage(), e);
}
return userList.toArray(new UserInfoBean[userList.size()]);
}
+ /**
+ * Get Tenant UserStoreManager
+ *
+ * @return UserStoreManager
+ * @throws RestAPIException
+ */
+ private static UserStoreManager getTenantUserStoreManager() throws RestAPIException {
+
+ CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
+ UserRealm userRealm = null;
+ UserStoreManager userStoreManager = null;
+
+ try {
+ userRealm = carbonContext.getUserRealm();
+ userStoreManager = userRealm.getUserStoreManager();
+
+ } catch (UserStoreException e) {
+ log.error(e.getMessage(), e);
+ throw new RestAPIException(e.getMessage(), e);
+ }
+
+ return userStoreManager;
+ }
+
@POST
@Path("/kubernetes/deploy/group")
@Produces("application/json")