use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class UserIdentityManagementUtil method storeUserIdentityMetadata.
/**
* Stores new metadata
*
* @param metadata
* @throws IdentityException
*/
public static void storeUserIdentityMetadata(UserRecoveryDataDO metadata) throws IdentityException {
JDBCUserRecoveryDataStore store = new JDBCUserRecoveryDataStore();
metadata.setValid(true);
store.store(metadata);
}
use of org.wso2.carbon.identity.base.IdentityException 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);
}
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class Utils method getVerifiedChallenges.
/**
* gets no of verified user challenges
*
* @param userDTO bean class that contains user and tenant Information
* @return no of verified challenges
* @throws IdentityException if fails
*/
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {
int noOfChallenges = 0;
try {
UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();
Resource resource;
if (registry.resourceExists(identityKeyMgtPath)) {
resource = registry.get(identityKeyMgtPath);
String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
if (property != null) {
return Integer.parseInt(property);
}
}
} catch (RegistryException e) {
log.error("Error while processing userKey", e);
}
return noOfChallenges;
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class Utils method getTenantId.
/**
* gets the tenant id from the tenant domain
*
* @param domain - tenant domain name
* @return tenantId
* @throws IdentityException if fails or tenant doesn't exist
*/
public static int getTenantId(String domain) throws IdentityException {
int tenantId;
TenantManager tenantManager = IdentityMgtServiceComponent.getRealmService().getTenantManager();
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
if (log.isDebugEnabled()) {
String msg = "Domain is not defined implicitly. So it is Super Tenant domain.";
log.debug(msg);
}
} else {
try {
tenantId = tenantManager.getTenantId(domain);
if (tenantId < 1 && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
String msg = "This action can not be performed by the users in non-existing domains.";
log.error(msg);
throw IdentityException.error(msg);
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error in retrieving tenant id of tenant domain: " + domain + ".";
log.error(msg, e);
throw IdentityException.error(msg, e);
}
}
return tenantId;
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class Utils method getClaimsFromUserStoreManager.
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;
}
Aggregations