use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project product-microgateway by wso2.
the class JWTGenerationTestCase method start.
@BeforeClass
public void start() throws Exception {
String project = "jwtGeneratorProject";
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Create map with custom claims
Map<String, String> customClaims = new HashMap<>();
customClaims.put("claim1", "testValue1");
customClaims.put("claim2", "testValue2");
jwtTokenProd = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, customClaims);
// Create map with backendJwt claim
Map<String, String> jwtClaim = new HashMap<>();
jwtClaim.put("backendJwt", jwtTokenProd);
jwtWithBackendJwtClaim = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, jwtClaim);
// generate apis with CLI and start the micro gateway server
super.init(project, new String[] { "jwtGeneration/jwt_generation.yaml", "mgw-JwtGenerator.jar" }, null, "confs/jwt-generator-test-config.conf");
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JsClaims method getLocalUserClaim.
/**
* Get the local user claim value specified by the Claim URI.
*
* @param claimUri Local claim URI
* @return Claim value of the given claim URI for the local user if available. Null Otherwise.
*/
private String getLocalUserClaim(String claimUri) {
int usersTenantId = IdentityTenantUtil.getTenantId(authenticatedUser.getTenantDomain());
RealmService realmService = FrameworkServiceDataHolder.getInstance().getRealmService();
try {
UserRealm userRealm = realmService.getTenantUserRealm(usersTenantId);
Map<String, String> claimValues = ((AbstractUserStoreManager) userRealm.getUserStoreManager()).getUserClaimValuesWithID(authenticatedUser.getUserId(), new String[] { claimUri }, null);
return claimValues.get(claimUri);
} catch (UserStoreException e) {
LOG.error(String.format("Error when getting claim : %s of user: %s", claimUri, authenticatedUser), e);
} catch (UserIdNotFoundException e) {
LOG.error("User id is not available for the user: " + authenticatedUser.getLoggableUserId(), e);
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JsClaims method hasLocalClaim.
/**
* Check if there is a local claim by given name.
*
* @param claimUri The local claim URI
* @return Claim value of the user authenticated by the indicated IdP
*/
protected boolean hasLocalClaim(String claimUri) {
int usersTenantId = IdentityTenantUtil.getTenantId(authenticatedUser.getTenantDomain());
RealmService realmService = FrameworkServiceDataHolder.getInstance().getRealmService();
try {
UserRealm userRealm = realmService.getTenantUserRealm(usersTenantId);
Claim[] supportedClaims = IdentityClaimManager.getInstance().getAllSupportedClaims((org.wso2.carbon.user.core.UserRealm) userRealm);
for (Claim claim : supportedClaims) {
if (claim.getClaimUri().equals(claimUri)) {
return true;
}
}
} catch (UserStoreException e) {
LOG.error("Error when retrieving user realm for tenant : " + usersTenantId, e);
} catch (IdentityException e) {
LOG.error("Error when initializing identity claim manager.", e);
}
return false;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class FrameworkUtils method getFederatedSubjectFromClaims.
/*
* Find the Subject identifier among federated claims
*/
public static String getFederatedSubjectFromClaims(AuthenticationContext context, String otherDialect) throws FrameworkException {
String value;
boolean useLocalClaimDialect = context.getExternalIdP().useDefaultLocalIdpDialect();
String userIdClaimURI = context.getExternalIdP().getUserIdClaimUri();
Map<ClaimMapping, String> claimMappings = context.getSubject().getUserAttributes();
if (useLocalClaimDialect) {
Map<String, String> extAttributesValueMap = FrameworkUtils.getClaimMappings(claimMappings, false);
Map<String, String> mappedAttrs = null;
try {
mappedAttrs = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(otherDialect, extAttributesValueMap.keySet(), context.getTenantDomain(), true);
} catch (ClaimMetadataException e) {
throw new FrameworkException("Error while loading claim mappings.", e);
}
String spUserIdClaimURI = mappedAttrs.get(userIdClaimURI);
value = extAttributesValueMap.get(spUserIdClaimURI);
} else {
ClaimMapping claimMapping = new ClaimMapping();
Claim claim = new Claim();
claim.setClaimUri(userIdClaimURI);
claimMapping.setRemoteClaim(claim);
claimMapping.setLocalClaim(claim);
value = claimMappings.get(claimMapping);
}
return value;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class DefaultAttributeFinder method getAttributeValues.
/*
* (non-Javadoc)
*
* @see
* org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder#getAttributeValues(java.lang.
* String, java.lang.String, java.lang.String)
*/
public Set<String> getAttributeValues(String subjectId, String resourceId, String actionId, String environmentId, String attributeId, String issuer) throws Exception {
Set<String> values = new HashSet<String>();
if (log.isDebugEnabled()) {
log.debug("Retrieving attribute values of subjectId \'" + subjectId + "\'with attributeId \'" + attributeId + "\'");
}
if (StringUtils.isEmpty(subjectId)) {
if (log.isDebugEnabled()) {
log.debug("subjectId value is null or empty. Returning empty attribute set");
}
return values;
}
subjectId = MultitenantUtils.getTenantAwareUsername(subjectId);
if (UserCoreConstants.ClaimTypeURIs.ROLE.equals(attributeId)) {
if (log.isDebugEnabled()) {
log.debug("Looking for roles via DefaultAttributeFinder");
}
String[] roles = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager().getRoleListOfUser(subjectId);
if (roles != null && roles.length > 0) {
for (String role : roles) {
if (log.isDebugEnabled()) {
log.debug(String.format("User %1$s belongs to the Role %2$s", subjectId, role));
}
values.add(role);
}
}
} else {
String claimValue = null;
try {
claimValue = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager().getUserClaimValue(subjectId, attributeId, null);
if (log.isDebugEnabled()) {
log.debug("Claim \'" + claimValue + "\' retrieved for attributeId \'" + attributeId + "\' " + "for subjectId \'" + subjectId + "\'");
}
} catch (UserStoreException e) {
if (e.getMessage().startsWith(IdentityCoreConstants.USER_NOT_FOUND)) {
if (log.isDebugEnabled()) {
log.debug("User: " + subjectId + " not found in user store");
}
} else {
throw e;
}
}
if (claimValue == null && log.isDebugEnabled()) {
log.debug(String.format("Request attribute %1$s not found", attributeId));
}
// Fix for multiple claim values
if (claimValue != null) {
String claimSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
if (StringUtils.isBlank(claimSeparator)) {
claimSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT;
}
if (claimValue.contains(claimSeparator)) {
StringTokenizer st = new StringTokenizer(claimValue, claimSeparator);
while (st.hasMoreElements()) {
String attributeValue = st.nextElement().toString();
if (StringUtils.isNotBlank(attributeValue)) {
values.add(attributeValue);
}
}
} else {
values.add(claimValue);
}
}
}
return values;
}
Aggregations