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;
}
}
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");
}
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);
}
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();
}
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());
}
Aggregations