use of org.wso2.carbon.user.api.Claim in project carbon-apimgt by wso2.
the class APIUtil method getClaims.
/**
* Returns the user claims for the given user.
*
* @param endUserName name of the user whose claims needs to be returned
* @param tenantId tenant id of the user
* @param dialectURI claim dialect URI
* @return claims map
* @throws APIManagementException
*/
public static SortedMap<String, String> getClaims(String endUserName, int tenantId, String dialectURI) throws APIManagementException {
SortedMap<String, String> claimValues;
try {
ClaimManager claimManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
String[] claimURIs = claimMappingtoClaimURIString(claims);
UserStoreManager userStoreManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(endUserName);
claimValues = new TreeMap(userStoreManager.getUserClaimValues(tenantAwareUserName, claimURIs, null));
return claimValues;
} catch (UserStoreException e) {
throw new APIManagementException("Error while retrieving user claim values from user store", e);
}
}
use of org.wso2.carbon.user.api.Claim in project carbon-apimgt by wso2.
the class APIUtil method getClaimDisplayName.
/**
* Returns the display name of the given claim URI.
*
* @param claimURI
* @param subscriber
* @return display name of the claim
* @throws APIManagementException
*/
public static String getClaimDisplayName(String claimURI, String subscriber) throws APIManagementException {
String tenantDomain = MultitenantUtils.getTenantDomain(subscriber);
int tenantId;
String displayName;
try {
tenantId = getTenantId(tenantDomain);
ClaimManager claimManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
displayName = claimManager.getClaim(claimURI).getDisplayTag();
} catch (UserStoreException e) {
throw new APIManagementException("Error while retrieving claim values from user store", e);
}
return displayName;
}
use of org.wso2.carbon.user.api.Claim in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method checkWithBackUpCodes.
/**
* If user forgets the mobile, then user can use the back up codes to authenticate the user.
*
* @param context the AuthenticationContext
* @param userToken the userToken
* @param authenticatedUser the name of authenticatedUser
* @throws AuthenticationFailedException
*/
private void checkWithBackUpCodes(AuthenticationContext context, String userToken, AuthenticatedUser authenticatedUser) throws AuthenticationFailedException {
String savedOTPString = null;
String username = context.getProperty(SMSOTPConstants.USER_NAME).toString();
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
UserRealm userRealm = getUserRealm(username);
try {
if (userRealm != null) {
savedOTPString = userRealm.getUserStoreManager().getUserClaimValue(tenantAwareUsername, SMSOTPConstants.SAVED_OTP_LIST, null);
}
if (StringUtils.isEmpty(savedOTPString)) {
if (log.isDebugEnabled()) {
log.debug("The claim " + SMSOTPConstants.SAVED_OTP_LIST + " does not contain any values");
}
throw new AuthenticationFailedException("The claim " + SMSOTPConstants.SAVED_OTP_LIST + " does not contain any values");
} else if (savedOTPString.contains(userToken)) {
if (log.isDebugEnabled()) {
log.debug("Found saved backup SMS OTP for user :" + authenticatedUser);
}
context.setSubject(authenticatedUser);
savedOTPString = savedOTPString.replaceAll(userToken, "").replaceAll(",,", ",");
userRealm.getUserStoreManager().setUserClaimValue(tenantAwareUsername, SMSOTPConstants.SAVED_OTP_LIST, savedOTPString, null);
} else {
if (log.isDebugEnabled()) {
log.debug("User entered OTP :" + userToken + " does not match with any of the saved backup codes");
}
throw new AuthenticationFailedException("Verification Error due to Code " + userToken + " mismatch.");
}
} catch (UserStoreException e) {
throw new AuthenticationFailedException("Cannot find the user claim for OTP list for user : " + authenticatedUser, e);
}
}
Aggregations