Search in sources :

Example 6 with IdentityException

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);
}
Also used : JDBCUserRecoveryDataStore(org.wso2.carbon.identity.mgt.store.JDBCUserRecoveryDataStore)

Example 7 with IdentityException

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);
    }
}
Also used : RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 8 with IdentityException

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;
}
Also used : Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 9 with IdentityException

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;
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager)

Example 10 with IdentityException

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;
}
Also used : HashMap(java.util.HashMap) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Aggregations

IdentityException (org.wso2.carbon.identity.base.IdentityException)132 UserStoreException (org.wso2.carbon.user.api.UserStoreException)62 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)38 Test (org.testng.annotations.Test)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 HashMap (java.util.HashMap)30 ArrayList (java.util.ArrayList)29 SQLException (java.sql.SQLException)25 Connection (java.sql.Connection)23 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)22 Resource (org.wso2.carbon.registry.core.Resource)22 PreparedStatement (java.sql.PreparedStatement)21 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)20 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)19 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)18 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)18 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)17 DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)17 Map (java.util.Map)15 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)15