use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class IdentityClaimManager method getAllSupportedClaims.
/**
* Returns all supported claims.
*
* @param realm user realm
* @return array of all supported claims
* @throws IdentityException if error occurs while building supported claims
*/
public Claim[] getAllSupportedClaims(UserRealm realm) throws IdentityException {
try {
ClaimManager claimAdmin = realm.getClaimManager();
ClaimMapping[] mappings = claimAdmin.getAllSupportClaimMappingsByDefault();
Claim[] claims = new Claim[0];
if (mappings != null) {
claims = new Claim[mappings.length];
for (int i = 0; i < mappings.length; i++) {
claims[i] = (Claim) mappings[i].getClaim();
}
}
return claims;
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error occurred while loading supported claims", e);
getException("Error occurred while loading supported claima", e);
}
return new Claim[0];
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method proceedOTPWithFederatedMobileNumber.
private void proceedOTPWithFederatedMobileNumber(AuthenticationContext context, HttpServletResponse response, String username, String queryParams, boolean sendOtpToFederatedMobile) throws AuthenticationFailedException {
try {
String federatedMobileAttributeKey;
String mobile = null;
StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep() - 1);
String previousStepAuthenticator = stepConfig.getAuthenticatedAutenticator().getName();
StepConfig currentStep = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
String currentStepAuthenticator = currentStep.getAuthenticatorList().iterator().next().getName();
if (sendOtpToFederatedMobile) {
federatedMobileAttributeKey = getFederatedMobileAttributeKey(context, previousStepAuthenticator);
if (StringUtils.isEmpty(federatedMobileAttributeKey)) {
federatedMobileAttributeKey = getFederatedMobileAttributeKey(context, currentStepAuthenticator);
}
Map<ClaimMapping, String> userAttributes = context.getCurrentAuthenticatedIdPs().values().iterator().next().getUser().getUserAttributes();
for (Map.Entry<ClaimMapping, String> entry : userAttributes.entrySet()) {
String key = String.valueOf(entry.getKey().getLocalClaim().getClaimUri());
String value = entry.getValue();
if (key.equals(federatedMobileAttributeKey)) {
mobile = String.valueOf(value);
proceedWithOTP(response, context, getErrorPage(context), mobile, queryParams, username);
break;
}
}
if (StringUtils.isEmpty(mobile)) {
if (log.isDebugEnabled()) {
log.debug("There is no mobile claim to send otp ");
}
throw new AuthenticationFailedException("There is no mobile claim to send otp");
}
} else {
redirectToErrorPage(response, context, queryParams, SMSOTPConstants.SEND_OTP_DIRECTLY_DISABLE);
}
} catch (AuthenticationFailedException e) {
throw new AuthenticationFailedException(" Failed to process SMSOTP flow ", e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.
the class UserInfoUserStoreClaimRetrieverTest method getUserAttributes.
@DataProvider
public Object[][] getUserAttributes() {
ClaimMapping map1 = ClaimMapping.build("localClaimUri1", "remoteClaimUri1", "defaultValue1", true);
ClaimMapping map2 = ClaimMapping.build("localClaimUri2", "remoteClaimUri2", "defaultValue1", true);
Map<ClaimMapping, Object> claims1 = new HashMap<ClaimMapping, Object>();
Map<ClaimMapping, Object> claims2 = new HashMap<ClaimMapping, Object>();
claims1.put(map1, "User1");
claims2.put(map2, "User1, User2");
return new Object[][] { { claims1 }, { claims2 } };
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultClaimsRetriever method getDefaultClaims.
@Override
public String[] getDefaultClaims(String endUserName) throws IdentityOAuth2Exception {
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
try {
tenantId = OAuth2Util.getTenantIdFromUserName(endUserName);
// if no claims were requested, return all
if (log.isDebugEnabled()) {
log.debug("No claims set requested. Returning all claims in the dialect");
}
ClaimManager claimManager = OAuthComponentServiceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
return claimToString(claims);
} catch (UserStoreException e) {
throw new IdentityOAuth2Exception("Error while reading default claims for user : " + endUserName, e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.
the class ClaimUtil method getUserClaimsUsingTokenResponse.
public static Map<String, Object> getUserClaimsUsingTokenResponse(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException {
Map<ClaimMapping, String> userAttributes = getUserAttributesFromCache(tokenResponse);
Map<String, Object> userClaimsInOIDCDialect;
if (isEmpty(userAttributes)) {
if (log.isDebugEnabled()) {
log.debug("User attributes not found in cache against the token. Retrieved claims from user store.");
}
userClaimsInOIDCDialect = getClaimsFromUserStore(tokenResponse);
} else {
UserInfoClaimRetriever retriever = UserInfoEndpointConfig.getInstance().getUserInfoClaimRetriever();
userClaimsInOIDCDialect = retriever.getClaimsMap(userAttributes);
}
if (isEmpty(userClaimsInOIDCDialect)) {
userClaimsInOIDCDialect = new HashMap<>();
}
return userClaimsInOIDCDialect;
}
Aggregations