me.prettyprint.hector.api.exceptions.HectorException Java Examples

The following examples show how to use me.prettyprint.hector.api.exceptions.HectorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a user by userName.
 */
@Override
public void doDeleteUser(String userName) throws UserStoreException {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    String[] roles = doGetExternalRoleListOfUser(userName, "");
    for (String role : roles) {
        Composite key = new Composite();
        key.addComponent(role, stringSerializer);
        key.addComponent(tenantIdString, stringSerializer);
        ColumnFamilyTemplate<Composite, String> userCFTemplate = new ThriftColumnFamilyTemplate<Composite, String>(
                keyspace, CFConstants.UM_ROLE_USER_INDEX, CompositeSerializer.get(), StringSerializer.get());
        try {
            userCFTemplate.deleteColumn(key, userName);
        } catch (HectorException e) {
            log.error("Error during deletion ", e);
        }
    }

    Composite userKey = new Composite();
    userKey.addComponent(userName, stringSerializer);
    userKey.addComponent(tenantIdString, stringSerializer);
    mutator.addDeletion(userKey, CFConstants.UM_USER_ROLE, null, CompositeSerializer.get());
    mutator.addDeletion(userKey, CFConstants.UM_USER, null, CompositeSerializer.get());
    mutator.execute();

    if (log.isDebugEnabled()) {
        log.debug("Deleted user " + userName + " successfully");
    }
}
 
Example #2
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void doUpdateCredentialByAdmin(String userName, Object newCredential) throws UserStoreException {
    if (!checkUserPasswordValid(newCredential)) {
        throw new UserStoreException(
                "Credential not valid. Credential must be a non null string with following format, "
                        + realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_JAVA_REG_EX));

    }

    String saltValue = null;
    if (TRUE.equalsIgnoreCase(realmConfig.getUserStoreProperties().get(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
        saltValue = Util.getSaltValue();
    }
    String password = Util.preparePassword((String) newCredential, saltValue);
    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    Composite key = new Composite();
    key.addComponent(userName, stringSerializer);
    key.addComponent(tenantIdString, stringSerializer);
    mutator.addInsertion(key, CFConstants.UM_USER,
            HFactory.createColumn(CFConstants.UM_SECRET, password, stringSerializer, stringSerializer));
    mutator.addInsertion(key, CFConstants.UM_USER,
            HFactory.createColumn(CFConstants.UM_SALT_VALUE, saltValue, stringSerializer, stringSerializer));
    try {
        mutator.execute();
        if (log.isDebugEnabled()) {
            log.debug("Changed password for user " + userName + "successfully");
        }
    } catch (HectorException e) {
        throw new UserStoreException("Change Password failed.", e);
    }
}
 
Example #3
Source File: UsergridSystemMonitor.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps "describe_thrift_version API call as this hits a static string in Cassandra. This is the most lightweight
 * way to assure that Hector is alive and talking to the cluster.
 *
 * @return true if we have a lit connection to the cluster.
 */
public boolean getIsCassandraAlive() {
    boolean isAlive = false;
    try {
        isAlive = cluster.describeThriftVersion() != null;
    }
    catch ( HectorException he ) {
        logger.error( "Could not communicate with Cassandra cluster", he );
    }
    return isAlive;
}
 
Example #4
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Adds the user to the user store.
 */
@Override
public void doAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims,
                      String profileName, boolean requirePasswordChange) throws UserStoreException {

    String userId = UUID.randomUUID().toString();
    String saltValue = null;

    if (TRUE.equalsIgnoreCase(realmConfig.getUserStoreProperties().get(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
        saltValue = Util.getSaltValue();
    }

    String password = Util.preparePassword((String) credential, saltValue);

    if (doCheckExistingUser(userName)) {

        String message = "User with credentials " + userName + "exists";

        UserStoreException userStoreException = new UserStoreException(message);
        log.error(message, userStoreException);
        throw userStoreException;
    } else {

        Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());

        Composite key = new Composite();
        key.addComponent(userName, stringSerializer);
        key.addComponent(tenantIdString, stringSerializer);

        // add user ID
        mutator.addInsertion(key, CFConstants.UM_USER,
                HFactory.createColumn(CFConstants.UM_USER_ID, userId, stringSerializer, stringSerializer));
        mutator.addInsertion(key, CFConstants.UM_USER,
                HFactory.createColumn(CFConstants.UM_USER_NAME, userName, stringSerializer, stringSerializer));
        mutator.addInsertion(key, CFConstants.UM_USER,
                HFactory.createColumn(CFConstants.UM_SECRET, password, stringSerializer, stringSerializer));
        mutator.addInsertion(key, CFConstants.UM_USER,
                HFactory.createColumn(CFConstants.UM_SALT_VALUE, saltValue, stringSerializer, stringSerializer));
        mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_REQUIRE_CHANGE_BOOLEAN,
                "false", stringSerializer, stringSerializer));
        mutator.addInsertion(key, CFConstants.UM_USER,
                HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString, stringSerializer, stringSerializer));
        mutator = addUserToRoleList(userName, roleList, mutator);

        if (claims != null) {
            mutator = addClaimsForUser(userId, claims, mutator);
        }

        try {
            mutator.execute();
            if (log.isDebugEnabled()) {
                log.debug("Added user " + userName + " successfully");
            }
        } catch (HectorException e) {
            // TODO- research and check how to identify cassandra failure
            // and handle it efficiently.
            throw new UserStoreException("Adding user failed.", e);
        }
        mutator.execute();

    }
}
 
Example #5
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Update the user list mapped to a role.
 */
@Override
public void doUpdateUserListOfRole(String roleName, String[] deletedUsers, String[] newUsers)
        throws UserStoreException {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    RoleContext ctx = createRoleContext(roleName);
    roleName = ctx.getRoleName();
    boolean isShared = ctx.isShared();
    if (!isShared) {
        //TODO TO BE Implemented
    }
    if (deletedUsers != null && deletedUsers.length > 0) {
        if (isShared) {
            //TODO TO BE Implemented
        } else {
            if (deletedUsers.length > 0) {
                Composite key = new Composite();
                key.addComponent(roleName, stringSerializer);
                key.addComponent(tenantIdString, stringSerializer);

                for (String user : deletedUsers) {

                    Composite userKey = new Composite();
                    userKey.addComponent(user, stringSerializer);
                    userKey.addComponent(tenantIdString, stringSerializer);

                    ColumnFamilyTemplate<Composite, String> userCFTemplate = new ThriftColumnFamilyTemplate<Composite, String>(
                            keyspace, CFConstants.UM_USER_ROLE, CompositeSerializer.get(), StringSerializer.get());
                    ColumnFamilyTemplate<Composite, String> roleCFTemplate = new ThriftColumnFamilyTemplate<Composite, String>(
                            keyspace, CFConstants.UM_ROLE_USER_INDEX, CompositeSerializer.get(),
                            StringSerializer.get());
                    try {
                        roleCFTemplate.deleteColumn(mutator, key, user);
                        userCFTemplate.deleteColumn(mutator, userKey, roleName);
                    } catch (HectorException e) {
                        log.error(e.getMessage(), e);
                        throw new UserStoreException("Error during the updating of a user's role list");
                    }
                }
            }

        }
    }
    // need to clear user roles cache upon roles update
    clearUserRolesCacheByTenant(this.tenantId);

    if (newUsers != null && newUsers.length > 0) {
        if (isShared) {
            //TODO TO BE Implemented
        } else {
            addRoleToUsersList(newUsers, roleName, mutator);
        }
    }
    mutator.execute();

}