Search in sources :

Example 1 with PasswordHistory

use of com.emc.storageos.db.client.model.PasswordHistory in project coprhd-controller by CoprHD.

the class SchemaUtil method insertPasswordHistory.

/**
 * initialize PasswordHistory CF
 *
 * @param dbClient
 */
private void insertPasswordHistory(DbClient dbClient) {
    String[] localUsers = { "root", "sysmonitor", "svcuser", "proxyuser" };
    for (String user : localUsers) {
        PasswordHistory passwordHistory = _passwordUtils.getPasswordHistory(user);
        if (passwordHistory == null) {
            passwordHistory = new PasswordHistory();
            passwordHistory.setId(PasswordUtils.getLocalPasswordHistoryURI(user));
            LongMap passwordHash = new LongMap();
            String encpassword = null;
            if (user.equals("proxyuser")) {
                encpassword = _passwordUtils.getEncryptedString("ChangeMe");
            } else {
                encpassword = _passwordUtils.getUserPassword(user);
            }
            // set the first password history entry's time to 0, to remove the impact of ChangeInterval
            // rule, if local users want to change their own password just after the installation.
            passwordHash.put(encpassword, 0L);
            passwordHistory.setUserPasswordHash(passwordHash);
            dbClient.createObject(passwordHistory);
        }
    }
}
Also used : LongMap(com.emc.storageos.db.client.model.LongMap) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory)

Example 2 with PasswordHistory

use of com.emc.storageos.db.client.model.PasswordHistory in project coprhd-controller by CoprHD.

the class PasswordService method setUserPasswordExpireTime.

/**
 * update user's expire time, format for expire_time "yyyy-MM-dd HH:mm:ss"
 *
 * for internal use
 */
@PUT
@Path("/expire")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
public Response setUserPasswordExpireTime(@QueryParam("username") String username, @QueryParam("expire_time") String expireTime) {
    if (username == null || !_localUsers.containsKey(username)) {
        throw APIException.badRequests.invalidParameter("username", username);
    }
    if (expireTime == null) {
        throw APIException.badRequests.invalidParameter("expire_time", expireTime);
    }
    Date date = null;
    try {
        date = _format.parse(expireTime);
    } catch (ParseException e) {
        throw APIException.badRequests.invalidParameterWithCause("expire_time", expireTime, e);
    }
    PasswordHistory ph = _passwordHandler.getPasswordUtils().getPasswordHistory(username);
    Calendar newExpireTime = Calendar.getInstance();
    newExpireTime.setTime(date);
    ph.setExpireDate(newExpireTime);
    _dbClient.updateAndReindexObject(ph);
    // update system_root_expiry_date / system_svc_expiry_date, if needed
    int daysAfterEpoch = PasswordUtils.getDaysAfterEpoch(newExpireTime);
    if (username.equals("root")) {
        _passwordHandler.updateProperty(Constants.ROOT_EXPIRY_DAYS, String.valueOf(daysAfterEpoch));
    } else if (username.equals("svcuser")) {
        _passwordHandler.updateProperty(Constants.SVCUSER_EXPIRY_DAYS, String.valueOf(daysAfterEpoch));
    }
    return Response.ok("set " + username + "'s password expire time to " + newExpireTime.getTime()).build();
}
Also used : Calendar(java.util.Calendar) ParseException(java.text.ParseException) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory) Date(java.util.Date) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with PasswordHistory

use of com.emc.storageos.db.client.model.PasswordHistory in project coprhd-controller by CoprHD.

the class PasswordService method getUserPasswordExpireTime.

/**
 * get user's expire time,
 *
 * for internal use
 */
@GET
@Path("/expire")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
public Response getUserPasswordExpireTime(@QueryParam("username") String username) {
    if (username == null || !_localUsers.containsKey(username)) {
        throw APIException.badRequests.parameterIsNotValid("username");
    }
    PasswordHistory ph = _passwordHandler.getPasswordUtils().getPasswordHistory(username);
    Calendar expireTime = ph.getExpireDate();
    if (expireTime != null) {
        return Response.ok(_format.format(expireTime.getTime())).build();
    } else {
        return Response.ok("no expire time set for the user").build();
    }
}
Also used : Calendar(java.util.Calendar) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with PasswordHistory

use of com.emc.storageos.db.client.model.PasswordHistory in project coprhd-controller by CoprHD.

the class PasswordUtils method updatePasswordHistory.

/**
 * update user's password expire date.
 *
 * if it is not reset by securityAdmin, also add the password in user's password history
 *
 * @param username
 * @param hashedPassword
 */
public void updatePasswordHistory(String username, String hashedPassword, Calendar expireTime, boolean bReset) {
    PasswordHistory lph = getPasswordHistory(username);
    boolean isNew = false;
    if (lph == null) {
        isNew = true;
        lph = new PasswordHistory();
        lph.setId(getLocalPasswordHistoryURI(username));
    }
    Calendar now = Calendar.getInstance();
    if (!bReset) {
        lph.getUserPasswordHash().put(hashedPassword, now.getTimeInMillis());
    }
    lph.setExpireDate(expireTime);
    if (isNew) {
        dbClient.createObject(lph);
    } else {
        dbClient.updateAndReindexObject(lph);
    }
}
Also used : PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory)

Example 5 with PasswordHistory

use of com.emc.storageos.db.client.model.PasswordHistory in project coprhd-controller by CoprHD.

the class PasswordUtils method setExpireTimeOfUser.

/**
 * update user's expireTime in Cassandra
 *
 * @param user
 * @param expireTime
 */
private void setExpireTimeOfUser(String user, Calendar expireTime) {
    Password password = constructUserPassword(user);
    PasswordHistory ph = password.getPasswordHistory();
    ph.setExpireDate(expireTime);
    dbClient.updateAndReindexObject(ph);
    _log.info("set new expire time for user " + user + ": " + (expireTime == null ? "null" : expireTime.getTime()));
}
Also used : PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory)

Aggregations

PasswordHistory (com.emc.storageos.db.client.model.PasswordHistory)10 LongMap (com.emc.storageos.db.client.model.LongMap)3 Calendar (java.util.Calendar)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 Password (com.emc.storageos.security.password.Password)2 Test (org.junit.Test)2 ExpireRule (com.emc.storageos.security.password.rules.ExpireRule)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1