/** * @param userName Current username * @param userStoreManager User store * @return State whether current user is a privileged user * @throws AccountLockException */ protected boolean isAccountLock(String userName, UserStoreManager userStoreManager) throws AccountLockException { String accountLockedClaim; try { Map<String, String> values = userStoreManager.getUserClaimValues(userName, new String[]{ AccountConstants.ACCOUNT_LOCKED_CLAIM}, UserCoreConstants.DEFAULT_PROFILE); accountLockedClaim = values.get(AccountConstants.ACCOUNT_LOCKED_CLAIM); } catch (UserStoreException e) { throw new AccountLockException("Error occurred while retrieving " + AccountConstants .ACCOUNT_LOCKED_CLAIM + " claim value", e); } return Boolean.parseBoolean(accountLockedClaim); }
/** * This method retrieves requested claim value from the user store * * @param username * @param userStoreManager * @param claimURI * @return claim value as a String * @throws FrameworkException */ private String getClaimValue(String username, UserStoreManager userStoreManager, String claimURI) throws FrameworkException { try { Map<String, String> values = userStoreManager.getUserClaimValues(username, new String[]{claimURI}, UserCoreConstants.DEFAULT_PROFILE); if (log.isDebugEnabled()) { log.debug(String.format("%s claim value of user %s is set to: " + values.get(claimURI), claimURI, username)); } return values.get(claimURI); } catch (UserStoreException e) { throw new FrameworkException("Error occurred while retrieving claim: " + claimURI, e); } } }
protected long getUnlockTime(String userName, UserStoreManager userStoreManager) throws AccountLockException { long unlockTime = 0; try { Map<String, String> values = userStoreManager.getUserClaimValues(userName, new String[]{ AccountConstants.ACCOUNT_UNLOCK_TIME_CLAIM}, UserCoreConstants.DEFAULT_PROFILE); String userClaimValue = values.get(AccountConstants.ACCOUNT_UNLOCK_TIME_CLAIM); if (NumberUtils.isNumber(userClaimValue)) { unlockTime = Long.parseLong(userClaimValue); } } catch (UserStoreException e) { throw new AccountLockException("Error occurred while retrieving " + AccountConstants .ACCOUNT_UNLOCK_TIME_CLAIM + " claim value", e); } return unlockTime; }
/** * This method retrieves requested claim value from the user store * * @param username * @param userStoreManager * @param claimURI * @return claim value as a String * @throws FrameworkException */ private String getClaimValue(String username, UserStoreManager userStoreManager, String claimURI) throws FrameworkException { try { Map<String, String> values = userStoreManager.getUserClaimValues(username, new String[]{claimURI}, UserCoreConstants.DEFAULT_PROFILE); if (log.isDebugEnabled()) { log.debug(String.format("%s claim value of user %s is set to: " + values.get(claimURI), claimURI, username)); } return values.get(claimURI); } catch (UserStoreException e) { throw new FrameworkException("Error occurred while retrieving claim: " + claimURI, e); } } }
public ClaimValue[] getUserClaimValuesForClaims(String userName, String[] claims, String profileName) throws UserStoreException { return convertMapToClaimValue(getUserStoreManager().getUserClaimValues(userName, claims, profileName)); }
public ClaimDTO[] getUserClaimValues(String userName, String profileName) throws UserStoreException { return convertClaimToClaimDTO(getUserStoreManager().getUserClaimValues(userName, profileName)); }
localClaimURIs.add(claimURI); allLocalClaims = userStore.getUserClaimValues(tenantAwareUserName, localClaimURIs.toArray(new String[localClaimURIs.size()]), null);
localClaimURIs.add(claimURI); allLocalClaims = userStore.getUserClaimValues(tenantAwareUserName, localClaimURIs.toArray(new String[localClaimURIs.size()]), null);
Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) {
Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) {
Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) {
if (userStoreManager != null) { Map<String, String> claimsMap = userStoreManager .getUserClaimValues(userName, new String[]{claim}, UserCoreConstants.DEFAULT_PROFILE); if (claimsMap != null && !claimsMap.isEmpty()) { claimValue = claimsMap.get(claim);
public static Map<String, String> getUserClaimValues(String username, String[] requestedClaims, String profile) throws IdentityException { try { UserRealm userRealm = AnonymousSessionUtil.getRealmByUserName(SAMLSSOUtil.getRegistryService(), SAMLSSOUtil.getRealmService(), username); if(userRealm == null){ throw IdentityException.error("User realm is not present for this user name:" + username); } username = MultitenantUtils.getTenantAwareUsername(username); UserStoreManager userStoreManager = userRealm.getUserStoreManager(); return userStoreManager.getUserClaimValues(username, requestedClaims, profile); } catch (UserStoreException e) { log.error("Error while retrieving claims values", e); throw IdentityException.error( "Error while retrieving claims values", e); } catch (CarbonException e) { log.error("Error while retrieving claims values", e); throw IdentityException.error( "Error while retrieving claim values", e); } }
public static Map<String,String> getClaimsFromUserStoreManager(String userName, int tenantId, String[] claims) throws IdentityException { Map<String, String> claimValues = new HashMap<>(); org.wso2.carbon.user.core.UserStoreManager userStoreManager = null; RealmService realmService = IdentityMgtServiceComponent.getRealmService(); try { if (realmService.getTenantUserRealm(tenantId) != null) { userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId). getUserStoreManager(); } } catch (UserStoreException e) { throw IdentityException.error("Error retrieving the user store manager for tenant id : " + tenantId, e); } try { if (userStoreManager != null) { claimValues = userStoreManager.getUserClaimValues(userName, claims, UserCoreConstants.DEFAULT_PROFILE); } } catch (Exception e) { throw IdentityException.error("Unable to retrieve the claim for user : " + userName, e); } return claimValues; }
public static Map<String, String> getUserClaimValues(String username, String[] requestedClaims, String profile) throws IdentityException { try { UserRealm userRealm = AnonymousSessionUtil.getRealmByUserName(SAMLSSOUtil.getRegistryService(), SAMLSSOUtil.getRealmService(), username); if(userRealm == null){ throw IdentityException.error("User realm is not present for this user name:" + username); } username = MultitenantUtils.getTenantAwareUsername(username); UserStoreManager userStoreManager = userRealm.getUserStoreManager(); return userStoreManager.getUserClaimValues(username, requestedClaims, profile); } catch (UserStoreException e) { log.error("Error while retrieving claims values", e); throw IdentityException.error( "Error while retrieving claims values", e); } catch (CarbonException e) { log.error("Error while retrieving claims values", e); throw IdentityException.error( "Error while retrieving claim values", e); } }
/** * Set claim to user store manager * * @param user user * @param claim claim uri * @param value claim value * @throws IdentityException if fails */ public static void setClaimInUserStoreManager(User user, String claim, String value) throws UserStoreException { String fullUserName = IdentityUtil.addDomainToName(user.getUserName(), user.getUserStoreDomain()); int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain()); org.wso2.carbon.user.core.UserStoreManager userStoreManager = null; RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService(); if (realmService.getTenantUserRealm(tenantId) != null) { userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId). getUserStoreManager(); } if (userStoreManager != null) { Map<String, String> values = userStoreManager.getUserClaimValues(fullUserName, new String[]{ claim}, UserCoreConstants.DEFAULT_PROFILE); String oldValue = values.get(claim); if (oldValue == null || !oldValue.equals(value)) { Map<String, String> claimMap = new HashMap<String, String>(); claimMap.put(claim, value); userStoreManager.setUserClaimValues(fullUserName, claimMap, UserCoreConstants.DEFAULT_PROFILE); } } }
return; Map<String, String> values = userStoreManager.getUserClaimValues(userName, new String[]{ ACCOUNT_LOCKED_CLAIM}, UserCoreConstants.DEFAULT_PROFILE); isAccountLocked = Boolean.parseBoolean(values.get(ACCOUNT_LOCKED_CLAIM));
public static Map<String, String> getClaimValues(User user, int tenantId, String[] claimUris) throws CaptchaServerException { String username = user.getUserName(); if (!StringUtils.isBlank(user.getUserStoreDomain()) && !"PRIMARY".equals(user.getUserStoreDomain())) { username = IdentityUtil.addDomainToName(user.getUserName(), user.getUserStoreDomain()); } RealmService realmService = CaptchaDataHolder.getInstance().getRealmService(); UserRealm userRealm; try { userRealm = (UserRealm) realmService.getTenantUserRealm(tenantId); } catch (UserStoreException e) { throw new CaptchaServerException("Failed to retrieve user realm from tenant id : " + tenantId, e); } UserStoreManager userStoreManager; try { userStoreManager = userRealm.getUserStoreManager(); } catch (UserStoreException e) { throw new CaptchaServerException("Failed to retrieve user store manager.", e); } Map<String, String> claimValues = null; try { claimValues = userStoreManager.getUserClaimValues(username, claimUris, UserCoreConstants.DEFAULT_PROFILE); } catch (org.wso2.carbon.user.core.UserStoreException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while retrieving user claims.", e); } } return claimValues; }
public static String getClaimFromUserStoreManager(User user, String claim) throws UserStoreException { String userStoreQualifiedUsername = IdentityUtil.addDomainToName(user.getUserName(), user.getUserStoreDomain()); org.wso2.carbon.user.core.UserStoreManager userStoreManager = null; RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService(); String claimValue = ""; int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain()); if (realmService.getTenantUserRealm(tenantId) != null) { userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId). getUserStoreManager(); } if (userStoreManager != null) { Map<String, String> claimsMap = userStoreManager .getUserClaimValues(userStoreQualifiedUsername, new String[]{claim}, UserCoreConstants.DEFAULT_PROFILE); if (claimsMap != null && !claimsMap.isEmpty()) { claimValue = claimsMap.get(claim); } } return claimValue; }
public static boolean isAccountDisabled(User user) throws IdentityRecoveryException { int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain()); RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService(); UserRealm userRealm; try { userRealm = (UserRealm) realmService.getTenantUserRealm(tenantId); } catch (UserStoreException e) { throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages .ERROR_CODE_FAILED_TO_LOAD_REALM_SERVICE, user.getTenantDomain(), e); } org.wso2.carbon.user.core.UserStoreManager userStoreManager; try { userStoreManager = userRealm.getUserStoreManager(); } catch (UserStoreException e) { throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages .ERROR_CODE_FAILED_TO_LOAD_USER_STORE_MANAGER, null, e); } try { Map<String, String> values = userStoreManager.getUserClaimValues(IdentityUtil.addDomainToName(user .getUserName(), user.getUserStoreDomain()), new String[]{ IdentityRecoveryConstants.ACCOUNT_DISABLED_CLAIM}, UserCoreConstants.DEFAULT_PROFILE); boolean accountDisable = Boolean.parseBoolean(values.get(IdentityRecoveryConstants.ACCOUNT_DISABLED_CLAIM)); return accountDisable; } catch (org.wso2.carbon.user.core.UserStoreException e) { throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages .ERROR_CODE_FAILED_TO_LOAD_USER_CLAIMS, null, e); } }