Search in sources :

Example 1 with UserRecoveryDataDO

use of org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO 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 2 with UserRecoveryDataDO

use of org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO 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 3 with UserRecoveryDataDO

use of org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO 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)

Example 4 with UserRecoveryDataDO

use of org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO 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 5 with UserRecoveryDataDO

use of org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO in project carbon-identity-framework by wso2.

the class JDBCUserRecoveryDataStore method store.

/**
 * Stores identity data set.
 *
 * @throws IdentityException
 */
@Override
@Deprecated
public void store(UserRecoveryDataDO[] recoveryDataDOs) throws IdentityException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA);
        for (UserRecoveryDataDO dataDO : recoveryDataDOs) {
            prepStmt.setString(1, dataDO.getUserName().toLowerCase());
            prepStmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
            prepStmt.setString(3, dataDO.getCode().toLowerCase());
            prepStmt.setString(4, dataDO.getSecret());
            prepStmt.setString(5, dataDO.getExpireTime());
            prepStmt.addBatch();
        }
        prepStmt.executeBatch();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw IdentityException.error("Error while storing user identity data", e);
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt);
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
Also used : UserRecoveryDataDO(org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

UserRecoveryDataDO (org.wso2.carbon.identity.mgt.dto.UserRecoveryDataDO)16 IdentityException (org.wso2.carbon.identity.base.IdentityException)7 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)4 JDBCUserRecoveryDataStore (org.wso2.carbon.identity.mgt.store.JDBCUserRecoveryDataStore)4 UserStoreException (org.wso2.carbon.user.api.UserStoreException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 Registry (org.wso2.carbon.registry.core.Registry)3 Resource (org.wso2.carbon.registry.core.Resource)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)2 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)1