Search in sources :

Example 1 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException 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;
}
Also used : UserRealm(org.wso2.carbon.user.api.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityException(org.wso2.carbon.identity.base.IdentityException) Claim(org.wso2.carbon.user.core.claim.Claim)

Example 2 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method updateUserIdentityClaims.

/**
 * Updates users recovery data such as the phone number, email etc
 *
 * @param userStoreManager
 * @param userIdentityRecoveryData
 * @throws IdentityException
 */
public static void updateUserIdentityClaims(String userName, UserStoreManager userStoreManager, UserIdentityClaimDTO[] userIdentityRecoveryData) throws IdentityException {
    UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
    UserIdentityClaimsDO userIdentityDO = store.load(userName, userStoreManager);
    if (userIdentityDO != null) {
        userIdentityDO.updateUserIdentityRecoveryData(userIdentityRecoveryData);
        store.store(userIdentityDO, userStoreManager);
    } else {
        throw IdentityException.error("No user account found for user " + userName);
    }
}
Also used : UserIdentityDataStore(org.wso2.carbon.identity.mgt.store.UserIdentityDataStore) UserIdentityClaimsDO(org.wso2.carbon.identity.mgt.dto.UserIdentityClaimsDO)

Example 3 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method invalidateUserIdentityMetadata.

/**
 * Invalidates the identity metadata
 *
 * @param userName
 * @param tenantId
 * @param metadataType
 * @param metadata
 * @throws IdentityException
 */
public static void invalidateUserIdentityMetadata(String userName, int tenantId, String metadataType, String metadata) throws IdentityException {
    JDBCUserRecoveryDataStore store = new JDBCUserRecoveryDataStore();
    UserRecoveryDataDO metadataDO = new UserRecoveryDataDO(userName, tenantId, metadataType, metadata);
    store.invalidate(metadataDO);
}
Also used : UserRecoveryDataDO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO) JDBCUserRecoveryDataStore(org.wso2.carbon.identity.mgt.store.JDBCUserRecoveryDataStore)

Example 4 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method getPrimaryQuestions.

/**
 * Returns an array of primary security questions
 *
 * @param tenantId
 * @return
 * @throws IdentityException
 */
public static String[] getPrimaryQuestions(int tenantId) throws IdentityException {
    JDBCUserRecoveryDataStore store = new JDBCUserRecoveryDataStore();
    UserRecoveryDataDO[] metadata = store.load("TENANT", tenantId);
    if (metadata.length < 1) {
        return new String[0];
    }
    List<String> validSecurityQuestions = new ArrayList<String>();
    String[] questionsList = new String[validSecurityQuestions.size()];
    return validSecurityQuestions.toArray(questionsList);
}
Also used : UserRecoveryDataDO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO) JDBCUserRecoveryDataStore(org.wso2.carbon.identity.mgt.store.JDBCUserRecoveryDataStore) ArrayList(java.util.ArrayList)

Example 5 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method removePrimaryQuestions.

/**
 * Remove primary security questions
 *
 * @param tenantId
 * @throws IdentityException
 */
public static void removePrimaryQuestions(String[] primarySecurityQuestion, int tenantId) throws IdentityException {
    UserRecoveryDataDO[] metadata = new UserRecoveryDataDO[primarySecurityQuestion.length];
    int i = 0;
    for (String secQuestion : primarySecurityQuestion) {
        if (!secQuestion.contains(UserCoreConstants.ClaimTypeURIs.CHALLENGE_QUESTION_URI)) {
            throw IdentityException.error("One or more security questions does not contain the namespace " + UserCoreConstants.ClaimTypeURIs.CHALLENGE_QUESTION_URI);
        }
        metadata[i++] = new UserRecoveryDataDO("TENANT", tenantId, UserRecoveryDataDO.METADATA_PRIMARAY_SECURITY_QUESTION, secQuestion);
    }
}
Also used : UserRecoveryDataDO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO)

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