Search in sources :

Example 1 with LongMap

use of com.emc.storageos.db.client.model.LongMap 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 LongMap

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

the class PasswordValidationUnitTest method testExpireRule.

@Test
public void testExpireRule() {
    ExpireRule expireRule = new ExpireRule(1);
    long current = System.currentTimeMillis();
    long twoDaysAgo = current - 2 * 24 * 60 * 60 * 1000;
    Password password = new Password("svcuser", "oldpassword", "password");
    PasswordHistory passwordHistory = new PasswordHistory();
    LongMap map = new LongMap();
    map.put("hashedPassword", twoDaysAgo);
    passwordHistory.setUserPasswordHash(map);
    password.setPasswordHistory(passwordHistory);
    logger.info("current=" + current + ", 2daysAgo = " + twoDaysAgo);
    try {
        expireRule.validate(password);
        Assert.fail("password already expired, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
    }
}
Also used : LongMap(com.emc.storageos.db.client.model.LongMap) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) ExpireRule(com.emc.storageos.security.password.rules.ExpireRule) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory) Password(com.emc.storageos.security.password.Password) Test(org.junit.Test)

Example 3 with LongMap

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

the class PasswordValidationUnitTest method testPasswordHistorySort.

@Test
public void testPasswordHistorySort() {
    long current = System.currentTimeMillis();
    long oneDayAgo = current - 1 * 24 * 60 * 60 * 1000;
    long twoDaysAgo = current - 2 * 24 * 60 * 60 * 1000;
    long threeDaysAgo = current - 3 * 24 * 60 * 60 * 1000;
    logger.info("oneDayAgo = " + oneDayAgo);
    logger.info("twoDaysAgo = " + twoDaysAgo);
    logger.info("threeDaysAgo = " + threeDaysAgo);
    Password password = new Password("svcuser", "oldpassword", "password");
    PasswordHistory passwordHistory = new PasswordHistory();
    LongMap map = new LongMap();
    map.put("hashedPassword1", oneDayAgo);
    map.put("hashedPassword3", threeDaysAgo);
    map.put("hashedPassword2", twoDaysAgo);
    passwordHistory.setUserPasswordHash(map);
    password.setPasswordHistory(passwordHistory);
    long latestChangedTime = password.getLatestChangedTime();
    logger.info("latestChangedTime = " + latestChangedTime);
    Assert.assertEquals(latestChangedTime, oneDayAgo);
    List<String> passwords = password.getPreviousPasswords(3);
    logger.info("password sorted:");
    for (String p : passwords) {
        logger.info(p);
    }
    Assert.assertTrue(passwords.get(0).equals("hashedPassword1"));
    Assert.assertTrue(passwords.get(1).equals("hashedPassword2"));
    Assert.assertTrue(passwords.get(2).equals("hashedPassword3"));
}
Also used : LongMap(com.emc.storageos.db.client.model.LongMap) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory) Password(com.emc.storageos.security.password.Password) Test(org.junit.Test)

Aggregations

LongMap (com.emc.storageos.db.client.model.LongMap)3 PasswordHistory (com.emc.storageos.db.client.model.PasswordHistory)3 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