Search in sources :

Example 1 with OathDeviceSettings

use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.

the class AuthenticatorOATH method doLoginSavedDevice.

private int doLoginSavedDevice(final Callback[] callbacks, final int state, final OathDeviceSettings settings) throws AuthLoginException, IOException, IdRepoException, SSOException {
    OathDeviceSettings deviceToAuthAgainst = settings;
    if (null == deviceToAuthAgainst && null != newDevice) {
        deviceToAuthAgainst = newDevice;
    }
    //get OTP
    String OTP = ((NameCallback) callbacks[0]).getName();
    if (OTP.length() == 0) {
        debug.error("OATH.process() : invalid OTP code");
        if (++attempt >= TOTAL_ATTEMPTS) {
            setFailureID(userName);
            throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
        }
        replaceHeader(state, MODULE_NAME + "Attempt " + (attempt + 1) + " of " + TOTAL_ATTEMPTS);
        return state;
    }
    //get Arrival time of the OTP
    time = System.currentTimeMillis() / 1000L;
    if (isRecoveryCode(OTP, deviceToAuthAgainst, id)) {
        return RECOVERY_USED;
    } else if (checkOTP(OTP, id, deviceToAuthAgainst)) {
        if (isOptional) {
            //if it's optional and you log in, config not skippable
            realmOathService.setUserSkipOath(id, AuthenticatorOathService.NOT_SKIPPABLE);
        }
        if (null == settings) {
            // this is the first time we have authorised against this device - we can now save it.
            deviceFactory.saveDeviceProfile(id.getName(), id.getRealm(), deviceToAuthAgainst);
        }
        return ISAuthConstants.LOGIN_SUCCEED;
    } else {
        //the OTP is out of the window or incorrect
        if (++attempt >= TOTAL_ATTEMPTS) {
            setFailureID(userName);
            throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
        }
        replaceHeader(state, MODULE_NAME + "Attempt " + (attempt + 1) + " of " + TOTAL_ATTEMPTS);
        return state;
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) InvalidPasswordException(com.sun.identity.authentication.spi.InvalidPasswordException)

Example 2 with OathDeviceSettings

use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.

the class JsonConversionUtilsTest method shouldPerformRoundTripWithOathDeviceSettingsList.

@Test
public void shouldPerformRoundTripWithOathDeviceSettingsList() throws IOException {
    //Given
    OathDeviceSettings object1 = getOathDeviceSettingsObject("secret", "Device Name", 1431999532, 1, true, -1);
    OathDeviceSettings object2 = getOathDeviceSettingsObject("secret2", "Device Name 2", 1431999533, 2, true, -2);
    List<OathDeviceSettings> list = new ArrayList<>();
    list.add(object1);
    list.add(object2);
    //When
    List<JsonValue> jsonValueList = JsonConversionUtils.toJsonValues(list);
    List<OathDeviceSettings> oathDeviceSettingsList = JsonConversionUtils.toOathDeviceSettingValues(jsonValueList);
    //Then
    Assert.assertEquals(list, oathDeviceSettingsList, "Expected OathDeviceSettings objects to have same content");
}
Also used : OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 3 with OathDeviceSettings

use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.

the class OathMakerTest method shouldGenerateCorrectLengthSecret.

@Test
public void shouldGenerateCorrectLengthSecret() throws Exception {
    // Given
    // When
    OathDeviceSettings deviceSettings = testFactory.createDeviceProfile(SECRET_HEX_LENGTH);
    // Then
    assertThat(deviceSettings.getSharedSecret()).hasSize(SECRET_HEX_LENGTH);
}
Also used : OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) Test(org.testng.annotations.Test)

Example 4 with OathDeviceSettings

use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.

the class OathMakerTest method shouldDefaultDeviceName.

@Test
public void shouldDefaultDeviceName() throws Exception {
    // Given
    // When
    OathDeviceSettings deviceSettings = testFactory.createDeviceProfile(SECRET_HEX_LENGTH);
    // Then
    assertThat(deviceSettings.getDeviceName()).isNotEmpty();
}
Also used : OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) Test(org.testng.annotations.Test)

Example 5 with OathDeviceSettings

use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.

the class OathMakerTest method shouldSaveGeneratedDevice.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldSaveGeneratedDevice() throws Exception {
    // Given
    OathDeviceSettings deviceSettings = new OathDeviceSettings();
    deviceSettings.setCounter(42);
    deviceSettings.setSharedSecret("sekret");
    deviceSettings.setChecksumDigit(true);
    deviceSettings.setLastLogin(99, TimeUnit.MILLISECONDS);
    deviceSettings.setDeviceName("test device");
    deviceSettings.setTruncationOffset(32);
    JsonValue expectedJson = JsonConversionUtils.toJsonValue(deviceSettings);
    // When
    testFactory.saveDeviceProfile(USER, REALM, deviceSettings);
    // Then
    ArgumentCaptor<List> savedProfileList = ArgumentCaptor.forClass(List.class);
    verify(mockDao).saveDeviceProfiles(eq(USER), eq(REALM), savedProfileList.capture());
    assertThat(savedProfileList.getValue()).hasSize(1);
    // JsonValue has no sensible .equals() method, so rely on canonical string representation
    assertThat(savedProfileList.getValue().get(0).toString()).isEqualTo(expectedJson.toString());
}
Also used : OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) JsonValue(org.forgerock.json.JsonValue) List(java.util.List) Test(org.testng.annotations.Test)

Aggregations

OathDeviceSettings (org.forgerock.openam.core.rest.devices.OathDeviceSettings)12 Test (org.testng.annotations.Test)8 JsonValue (org.forgerock.json.JsonValue)3 InvalidPasswordException (com.sun.identity.authentication.spi.InvalidPasswordException)2 SSOException (com.iplanet.sso.SSOException)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 SMSException (com.sun.identity.sm.SMSException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NameCallback (javax.security.auth.callback.NameCallback)1 DecoderException (org.apache.commons.codec.DecoderException)1