use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class DefaultAttributeFinder method getSupportedAttributes.
/*
* (non-Javadoc)
*
* @see org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder#getSupportedAttributes()
*/
public Set<String> getSupportedAttributes() {
try {
ClaimManager claimManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager();
ClaimMapping[] claims = claimManager.getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
for (ClaimMapping claim : claims) {
supportedAttrs.add(claim.getClaim().getClaimUri());
}
} catch (Exception e) {
// ignore
}
return supportedAttrs;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method getUserList.
private static String[] getUserList(int tenantId, String claim, String value, String profileName) throws IdentityMgtServiceException {
org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
String[] userList = null;
RealmService realmService = IdentityMgtServiceComponent.getRealmService();
try {
if (realmService.getTenantUserRealm(tenantId) != null) {
userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
}
} catch (Exception e) {
String msg = "Error retrieving the user store manager for the tenant";
throw new IdentityMgtServiceException(msg, e);
}
try {
if (userStoreManager != null) {
userList = userStoreManager.getUserList(claim, value, profileName);
}
return userList;
} catch (Exception e) {
String msg = "Unable to retrieve the claim for the given tenant";
throw new IdentityMgtServiceException(msg, e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method getAllUserIdentityClaims.
/**
* Returns all user claims
*
* @param userName
* @return
* @throws IdentityMgtServiceException
*/
public static UserIdentityClaimDTO[] getAllUserIdentityClaims(String userName) throws IdentityMgtServiceException {
int tenantId = 0;
try {
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
// read all claims and convert them to UserIdentityClaimDTO
Claim[] claims = userStoreManager.getUserClaimValues(userName, null);
List<UserIdentityClaimDTO> allDefaultClaims = new ArrayList<UserIdentityClaimDTO>();
for (Claim claim : claims) {
if (claim.getClaimUri().contains(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
UserIdentityClaimDTO claimDTO = new UserIdentityClaimDTO();
claimDTO.setClaimUri(claim.getClaimUri());
claimDTO.setClaimValue(claim.getValue());
allDefaultClaims.add(claimDTO);
}
}
UserIdentityClaimDTO[] claimDTOs = new UserIdentityClaimDTO[allDefaultClaims.size()];
return allDefaultClaims.toArray(claimDTOs);
} catch (UserStoreException e) {
throw new IdentityMgtServiceException("Error while getting user identity claims", e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method getUsernameByClaims.
/**
* @param claims
* @param tenantId
* @return
* @throws IdentityMgtServiceException - If user cannot be retrieved using the provided claims.
*/
public static String getUsernameByClaims(UserIdentityClaimDTO[] claims, int tenantId) throws IdentityMgtServiceException {
if (claims == null || claims.length < 1) {
throw new IdentityMgtServiceException("No fields found for user search");
}
String userName = null;
String[] tempUserList = null;
// passed array.
for (int i = 0; i < claims.length; i++) {
UserIdentityClaimDTO claim = claims[i];
if (claim.getClaimUri() != null && claim.getClaimValue() != null) {
String[] userList = getUserList(tenantId, claim.getClaimUri(), claim.getClaimValue(), null);
if (userList != null && userList.length > 0) {
if (userList.length == 1) {
return userList[0];
} else {
// If more than one user find the first matching user. Hence need to define unique claims
if (tempUserList != null) {
for (int j = 0; j < tempUserList.length; j++) {
for (int x = 0; x < userList.length; x++) {
if (tempUserList[j].equals(userList[x])) {
return userList[x];
}
}
}
}
tempUserList = userList;
continue;
}
} else {
throw new IdentityMgtServiceException("No associated user is found for given claim values");
}
}
}
return userName;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class Utils method getClaimFromUserStoreManager.
/**
* Get the claims from the user store manager
*
* @param userName user name
* @param tenantId tenantId
* @param claim claim name
* @return claim value
* @throws IdentityException if fails
*/
public static String getClaimFromUserStoreManager(String userName, int tenantId, String claim) throws IdentityException {
org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
RealmService realmService = IdentityMgtServiceComponent.getRealmService();
String claimValue = "";
try {
if (realmService.getTenantUserRealm(tenantId) != null) {
userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
}
} catch (Exception e) {
String msg = "Error retrieving the user store manager for tenant id : " + tenantId;
log.error(msg, e);
throw IdentityException.error(msg, e);
}
try {
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);
}
}
return claimValue;
} catch (Exception e) {
String msg = "Unable to retrieve the claim for user : " + userName;
log.error(msg, e);
throw IdentityException.error(msg, e);
}
}
Aggregations