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());
}
use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.
the class AuthenticatorOATH method process.
/**
* Processes the OTP input by the user. Checks the OTP for validity, and
* resynchronizes the server as needed.
*
* @param callbacks Incoming from the UI.
* @param state State of the module to process this access.
* @return -1 for success; 0 for failure, any other int to move to that state.
* @throws AuthLoginException upon any errors.
*/
@Override
public int process(Callback[] callbacks, int state) throws AuthLoginException {
try {
checkForSessionAndGetUsernameAndUUID();
final OathDeviceSettings settings = getOathDeviceSettings(id.getName(), id.getRealm());
try {
//figures out whether we're optional or not, based on server + user setting
detectNecessity(id);
} catch (Exception e) {
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
int selectedIndex;
switch(state) {
case LOGIN_OPTIONAL:
case LOGIN_NO_DEVICE:
case LOGIN_OPT_DEVICE:
case LOGIN_SAVED_DEVICE:
if (null == callbacks) {
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
}
//fall-throughs are INTENTIONAL
switch(state) {
case LOGIN_START:
return beginLogin(settings);
case LOGIN_OPTIONAL:
selectedIndex = ((ConfirmationCallback) callbacks[0]).getSelectedIndex();
if (selectedIndex == SKIP_OATH_INDEX) {
realmOathService.setUserSkipOath(id, AuthenticatorOathService.SKIPPABLE);
return ISAuthConstants.LOGIN_SUCCEED;
}
case LOGIN_NO_DEVICE:
selectedIndex = ((ConfirmationCallback) callbacks[0]).getSelectedIndex();
if (selectedIndex == REGISTER_DEVICE_OPTION_VALUE_INDEX) {
newDevice = createBasicDevice();
paintRegisterDeviceCallback(id, newDevice);
return REGISTER_DEVICE;
}
case LOGIN_OPT_DEVICE:
selectedIndex = ((ConfirmationCallback) callbacks[1]).getSelectedIndex();
if (selectedIndex == OPT_DEVICE_SKIP_INDEX) {
realmOathService.setUserSkipOath(id, AuthenticatorOathService.SKIPPABLE);
//user backed out of saving device
realmOathService.removeAllUserDevices(id);
return ISAuthConstants.LOGIN_SUCCEED;
}
case LOGIN_SAVED_DEVICE:
return doLoginSavedDevice(callbacks, state, settings);
case REGISTER_DEVICE:
if (isOptional) {
replaceHeader(LOGIN_OPT_DEVICE, MODULE_NAME);
return LOGIN_OPT_DEVICE;
} else {
replaceHeader(LOGIN_SAVED_DEVICE, MODULE_NAME);
return LOGIN_SAVED_DEVICE;
}
case RECOVERY_USED:
if (isOptional) {
//if it's optional and you log in, config not skippable
realmOathService.setUserSkipOath(id, AuthenticatorOathService.NOT_SKIPPABLE);
}
return ISAuthConstants.LOGIN_SUCCEED;
default:
throw new AuthLoginException("amAuth", "invalidLoginState", new Object[] { state });
}
} catch (SSOException | IdRepoException | IOException e) {
debug.error("OATH.process() : SSOException", e);
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
}
use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.
the class OathMakerTest method shouldDefaultCounterToZero.
@Test
public void shouldDefaultCounterToZero() throws Exception {
// Given
// When
OathDeviceSettings deviceSettings = testFactory.createDeviceProfile(SECRET_HEX_LENGTH);
// Then
assertThat(deviceSettings.getCounter()).isEqualTo(0);
}
use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.
the class OathMakerTest method shouldDefaultLastLoginTimeToZero.
@Test
public void shouldDefaultLastLoginTimeToZero() throws Exception {
// Given
// When
OathDeviceSettings deviceSettings = testFactory.createDeviceProfile(SECRET_HEX_LENGTH);
// Then
assertThat(deviceSettings.getLastLogin()).isEqualTo(0);
}
use of org.forgerock.openam.core.rest.devices.OathDeviceSettings in project OpenAM by OpenRock.
the class OathMakerTest method shouldNotGenerateLessThan8BytesOfSecret.
@Test
public void shouldNotGenerateLessThan8BytesOfSecret() throws Exception {
// Given
// When
OathDeviceSettings deviceSettings = testFactory.createDeviceProfile(0);
// Then
assertThat(deviceSettings.getSharedSecret()).hasSize(16);
}
Aggregations