Java源码示例:com.okta.sdk.resource.user.factor.FactorType

示例1
public static String relativeLink(Factor factor) {
    FactorType type = factor.getType();
    String templateName;
    switch (type) {
        case U2F:
            templateName = "u2f";
            break;
        case TOKEN_SOFTWARE_TOTP:
            templateName = "totp";
            break;
        case SMS:
            templateName = "sms";
            break;
        default:
            templateName = "unknown";
    }

    return templateName;
}
 
示例2
public static FactorType fromRelativeLink(String type) {
    FactorType oktaType;
    switch (type) {
        case "u2f":
            oktaType = FactorType.U2F;
            break;
        case "totp":
            oktaType = FactorType.TOKEN_SOFTWARE_TOTP;
            break;
        case "sms":
            oktaType = FactorType.SMS;
            break;
        default:
            oktaType = null;
    }
    return oktaType;
}
 
示例3
@GET
@Path("/mfa/verify/{type}")
public MfaVerifyView getVerifyMfaView(@PathParam("type") String type) throws AuthenticationException {

    AuthenticationResponse authenticationResponse = getPreviousAuthResult();
    com.okta.authn.sdk.resource.Factor factor = getFactor(type, authenticationResponse);

    if (factor.getType().equals(FactorType.TOKEN_SOFTWARE_TOTP)) {
        return new MfaVerifyView(factor);
    } else {
        return new MfaVerifyView(challengeFactor(factor, authenticationResponse));
    }
}
 
示例4
@POST
@Path("/recover")
public RecoveryChallengeView recoverPassword(@FormParam("username") String username,
                                             @FormParam("factor") String factorType) throws AuthenticationException {
    authenticationClient.recoverPassword(username, FactorType.valueOf(factorType), null, new ExampleAuthenticationStateHandler());
    return new RecoveryChallengeView();
}
 
示例5
private com.okta.authn.sdk.resource.Factor getFactor(String type, AuthenticationResponse authenticationResponse) {

        FactorType oktaType = MfaVerifyView.fromRelativeLink(type);
        return authenticationResponse.getFactors().stream()
                .filter(it -> it.getType().equals(oktaType))
                .findFirst().get();
    }
 
示例6
@Override
public AuthenticationResponse recoverPassword(String username, FactorType factorType, String relayState, AuthenticationStateHandler stateHandler) throws AuthenticationException {
    return recoverPassword(instantiate(RecoverPasswordRequest.class)
                                .setUsername(username)
                                .setFactorType(factorType)
                                .setRelayState(relayState),
                            stateHandler);
}
 
示例7
@Override
public AuthenticationResponse unlockAccount(String username, FactorType factorType, String relayState, AuthenticationStateHandler stateHandler) throws AuthenticationException {
    return unlockAccount(instantiate(UnlockAccountRequest.class)
                    .setUsername(username)
                    .setFactorType(factorType)
                    .setRelayState(relayState),
                stateHandler);
}
 
示例8
@Override
public AuthenticationResponse enrollFactor(FactorType type, FactorProvider provider, FactorProfile profile, String stateToken, AuthenticationStateHandler stateHandler) throws AuthenticationException {
    return enrollFactor(instantiate(FactorEnrollRequest.class)
                                .setFactorType(type)
                                .setProvider(provider)
                                .setFactorProfile(profile)
                                .setStateToken(stateToken),
                            stateHandler);
}
 
示例9
private void sendEmail() {
    String username = usernameEditText.getText().toString();
    if (TextUtils.isEmpty(username)) {
        usernameEditText.setError(getString(R.string.empty_field_error));
        return;
    }

    UnlockAccountRequest unlockAccountRequest = authenticationClient.instantiate(UnlockAccountRequest.class)
            .setUsername(username)
            .setFactorType(FactorType.EMAIL);

    unlockAccount(unlockAccountRequest);
}
 
示例10
/**
 * Determines if a MFA factor is currently supported by Cerberus or not
 *
 * @param factor Okta MFA factor
 * @return boolean
 */
public boolean isSupportedFactor(Factor factor) {

  final FactorType type = factor.getType();
  final FactorProvider provider = factor.getProvider();

  return !(provider.equals(FactorProvider.OKTA) && UNSUPPORTED_OKTA_MFA_TYPES.contains(type));
}
 
示例11
@Test
public void handleMfaRequired() throws Exception {

  String email = "email";
  String id = "id";
  AuthStatus expectedStatus = AuthStatus.MFA_REQUIRED;

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.TOKEN_SOFTWARE_TOTP;
  String deviceId = "device id";
  String status = "status";

  AuthenticationResponse expectedResponse = mock(AuthenticationResponse.class);

  User user = mock(User.class);
  when(user.getId()).thenReturn(id);
  when(user.getLogin()).thenReturn(email);
  when(expectedResponse.getUser()).thenReturn(user);

  DefaultFactor factor = mock(DefaultFactor.class);

  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);
  when(factor.getStatus()).thenReturn(status);
  when(factor.getId()).thenReturn(deviceId);
  when(expectedResponse.getFactors()).thenReturn(Lists.newArrayList(factor));

  // do the call
  initialLoginStateHandler.handleMfaRequired(expectedResponse);

  AuthResponse actualResponse = authenticationResponseFuture.get(1, TimeUnit.SECONDS);

  //  verify results
  assertEquals(id, actualResponse.getData().getUserId());
  assertEquals(email, actualResponse.getData().getUsername());
  assertEquals(expectedStatus, actualResponse.getStatus());
}
 
示例12
@Test(expected = ApiException.class)
public void handleMfaRequiredFailNoSupportedDevicesEnrolled() throws Exception {

  String email = "email";
  String id = "id";
  AuthStatus expectedStatus = AuthStatus.MFA_REQUIRED;

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.PUSH;
  String deviceId = "device id";
  String status = "status";

  AuthenticationResponse expectedResponse = mock(AuthenticationResponse.class);

  User user = mock(User.class);
  when(user.getId()).thenReturn(id);
  when(user.getLogin()).thenReturn(email);
  when(expectedResponse.getUser()).thenReturn(user);

  DefaultFactor factor = mock(DefaultFactor.class);

  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);
  when(factor.getStatus()).thenReturn(status);
  when(factor.getId()).thenReturn(deviceId);
  when(expectedResponse.getFactors()).thenReturn(Lists.newArrayList(factor));

  // do the call
  initialLoginStateHandler.handleMfaRequired(expectedResponse);

  AuthResponse actualResponse = authenticationResponseFuture.get(1, TimeUnit.SECONDS);

  //  verify results
  assertEquals(id, actualResponse.getData().getUserId());
  assertEquals(email, actualResponse.getData().getUsername());
  assertEquals(expectedStatus, actualResponse.getStatus());
}
 
示例13
@Test
public void handleMfaEnroll() throws Exception {

  String email = "email";
  String id = "id";
  AuthStatus expectedStatus = AuthStatus.MFA_REQUIRED;

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.TOKEN_SOFTWARE_TOTP;
  String deviceId = "device id";
  String status = "status";

  AuthenticationResponse expectedResponse = mock(AuthenticationResponse.class);

  User user = mock(User.class);
  when(user.getId()).thenReturn(id);
  when(user.getLogin()).thenReturn(email);
  when(expectedResponse.getUser()).thenReturn(user);

  DefaultFactor factor = mock(DefaultFactor.class);

  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);
  when(factor.getStatus()).thenReturn(status);
  when(factor.getId()).thenReturn(deviceId);
  when(expectedResponse.getFactors()).thenReturn(Lists.newArrayList(factor));

  // do the call
  initialLoginStateHandler.handleMfaEnroll(expectedResponse);

  AuthResponse actualResponse = authenticationResponseFuture.get(1, TimeUnit.SECONDS);

  //  verify results
  assertEquals(id, actualResponse.getData().getUserId());
  assertEquals(email, actualResponse.getData().getUsername());
  assertEquals(expectedStatus, actualResponse.getStatus());
}
 
示例14
@Test
public void getFactorKey() {

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(FactorType.PUSH);
  when(factor.getProvider()).thenReturn(FactorProvider.OKTA);

  String expected = "okta-push";
  String actual = abstractOktaStateHandler.getFactorKey(factor);

  assertEquals(expected, actual);
}
 
示例15
@Test
public void getDeviceNameGoogleTotp() {

  FactorProvider provider = FactorProvider.GOOGLE;
  FactorType type = FactorType.TOKEN_SOFTWARE_TOTP;

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);

  String result = this.abstractOktaStateHandler.getDeviceName(factor);

  assertEquals("Google Authenticator", result);
}
 
示例16
@Test
public void getDeviceNameOktaTotp() {

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.TOKEN_SOFTWARE_TOTP;

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);

  String result = this.abstractOktaStateHandler.getDeviceName(factor);

  assertEquals("Okta Verify TOTP", result);
}
 
示例17
@Test
public void getDeviceNameOktaPush() {

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.PUSH;

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);

  String result = this.abstractOktaStateHandler.getDeviceName(factor);

  assertEquals("Okta Verify Push", result);
}
 
示例18
@Test
public void getDeviceNameOktaCall() {

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.CALL;

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);

  String result = this.abstractOktaStateHandler.getDeviceName(factor);

  assertEquals("Okta Voice Call", result);
}
 
示例19
@Test
public void getDeviceNameOktaSms() {

  FactorProvider provider = FactorProvider.OKTA;
  FactorType type = FactorType.SMS;

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(type);
  when(factor.getProvider()).thenReturn(provider);

  String result = this.abstractOktaStateHandler.getDeviceName(factor);

  assertEquals("Okta Text Message Code", result);
}
 
示例20
@Test
public void isSupportedFactorFalse() {

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(FactorType.PUSH);
  when(factor.getProvider()).thenReturn(FactorProvider.OKTA);

  boolean expected = false;
  boolean actual = abstractOktaStateHandler.isSupportedFactor(factor);

  TestCase.assertEquals(expected, actual);
}
 
示例21
@Test
public void isSupportedFactorTrue() {

  DefaultFactor factor = mock(DefaultFactor.class);
  when(factor.getType()).thenReturn(FactorType.TOKEN_SOFTWARE_TOTP);
  when(factor.getProvider()).thenReturn(FactorProvider.OKTA);

  boolean expected = true;
  boolean actual = abstractOktaStateHandler.isSupportedFactor(factor);

  TestCase.assertEquals(expected, actual);
}
 
示例22
@POST
@Path("/unlock")
public void unlockAccount(@FormParam("username") String username,
                          @FormParam("factor") String factorType) throws AuthenticationException {
    authenticationClient.unlockAccount(username, FactorType.valueOf(factorType), null, new ExampleAuthenticationStateHandler());
}
 
示例23
@Override
public FactorType getType() {
    return getEnumProperty(TYPE_PROPERTY);
}
 
示例24
@Override
public FactorType getFactorType() {
    return getEnumProperty(FACTOR_TYPE_PROPERTY);
}
 
示例25
@Override
public RecoverPasswordRequest setFactorType(FactorType factorType) {
    setProperty(FACTOR_TYPE_PROPERTY, factorType);
    return this;
}
 
示例26
@Override
public FactorType getFactorType() {
    return getEnumProperty(FACTOR_TYPE_PROPERTY);
}
 
示例27
@Override
public FactorEnrollRequest setFactorType(FactorType factorType) {
    setProperty(FACTOR_TYPE_PROPERTY, factorType);
    return this;
}
 
示例28
@Override
public FactorType getFactorType() {
    return getEnumProperty(FACTOR_TYPE_PROPERTY);
}
 
示例29
@Override
public UnlockAccountRequest setFactorType(FactorType factorType) {
    setProperty(FACTOR_TYPE_PROPERTY, factorType);
    return this;
}
 
示例30
@Override
public FactorType getFactorType() {
    return getEnumProperty(FACTOR_TYPE_PROPERTY);
}