From 8277a9a8187de07731ba16fe9c667b02331da3b7 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 20 Mar 2015 18:04:04 +0530 Subject: [PATCH] * Added a method to get a single user --- .../device/mgt/user/core/UserManager.java | 1 + .../device/mgt/user/core/UserManagerImpl.java | 20 ++++++++++++++++--- .../core/service/UserManagementService.java | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManager.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManager.java index f73be18c56..8fa3e3b4c3 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManager.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManager.java @@ -28,4 +28,5 @@ public interface UserManager { public List getUsersForTenantAndRole(int tenantId, String roleName) throws UserManagementException; public List getRolesForTenant(int tenantId) throws UserManagementException; public List getUsersForTenant(int tenantId) throws UserManagementException; + public User getUser(String username, int tenantId) throws UserManagementException; } diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java index 14740a1229..e5ec26aeae 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java @@ -20,12 +20,10 @@ package org.wso2.carbon.device.mgt.user.core; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.user.common.Claims; import org.wso2.carbon.device.mgt.user.common.Role; import org.wso2.carbon.device.mgt.user.common.User; import org.wso2.carbon.device.mgt.user.common.UserManagementException; import org.wso2.carbon.device.mgt.user.core.internal.DeviceMgtUserDataHolder; -import org.wso2.carbon.user.api.Claim; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.core.UserCoreConstants; @@ -148,8 +146,24 @@ public class UserManagerImpl implements UserManager { return usersList; } - private void setUserClaims(User newUser, Map claimMap) { + @Override public User getUser(String username, int tenantId) throws UserManagementException { + UserStoreManager userStoreManager; + User user; + try { + userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) + .getUserStoreManager(); + user = new User(username); + setUserClaims(user, userStoreManager + .getUserClaimValues(username, DEFAULT_CLAIM_ARR, UserCoreConstants.DEFAULT_PROFILE)); + } catch (UserStoreException userStoreEx) { + String errorMsg = "User store error in fetching user " + username; + log.error(errorMsg, userStoreEx); + throw new UserManagementException(errorMsg, userStoreEx); + } + return user; + } + private void setUserClaims(User newUser, Map claimMap) { newUser.setRoleName(UserCoreConstants.ClaimTypeURIs.ROLE); newUser.setAccountStatus(claimMap.get(ACCOUNT_STATUS)); newUser.setChallengeQuestion(claimMap.get(CHALLENGE_QUESTION_URI)); diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/service/UserManagementService.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/service/UserManagementService.java index 5e051f2640..6d2740d5db 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/service/UserManagementService.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/service/UserManagementService.java @@ -43,4 +43,9 @@ public class UserManagementService implements UserManager{ public List getUsersForTenant(int tenantId) throws UserManagementException { return DeviceMgtUserDataHolder.getInstance().getUserManager().getUsersForTenant(tenantId); } + + @Override public User getUser(String username, int tenantId) throws UserManagementException { + return DeviceMgtUserDataHolder.getInstance().getUserManager().getUser(username, tenantId); + } + }