Search in sources :

Example 6 with AuthResponse

use of com.nike.cerberus.auth.connector.AuthResponse in project cerberus by Nike-Inc.

the class MfaStateHandler method handleMfaChallenge.

/**
 * Handles MFA Challenge, when a MFA challenge has been initiated for call or sms.
 *
 * @param mfaChallengeResponse - Authentication response from the Completable Future
 */
@Override
public void handleMfaChallenge(AuthenticationResponse mfaChallengeResponse) {
    final String userId = mfaChallengeResponse.getUser().getId();
    final String userLogin = mfaChallengeResponse.getUser().getLogin();
    final AuthData authData = AuthData.builder().userId(userId).username(userLogin).build();
    AuthResponse authResponse = AuthResponse.builder().data(authData).status(AuthStatus.MFA_CHALLENGE).build();
    authenticationResponseFuture.complete(authResponse);
}
Also used : AuthData(com.nike.cerberus.auth.connector.AuthData) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse)

Example 7 with AuthResponse

use of com.nike.cerberus.auth.connector.AuthResponse in project cerberus by Nike-Inc.

the class AbstractOktaStateHandlerTest method handleSuccess.

@Test
public void handleSuccess() throws Exception {
    String email = "email";
    String id = "id";
    AuthStatus status = AuthStatus.SUCCESS;
    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);
    // do the call
    abstractOktaStateHandler.handleSuccess(expectedResponse);
    AuthResponse actualResponse = authenticationResponseFuture.get(1, TimeUnit.SECONDS);
    // verify results
    Assert.assertEquals(id, actualResponse.getData().getUserId());
    Assert.assertEquals(email, actualResponse.getData().getUsername());
    Assert.assertEquals(status, actualResponse.getStatus());
}
Also used : User(com.okta.authn.sdk.resource.User) AuthStatus(com.nike.cerberus.auth.connector.AuthStatus) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Example 8 with AuthResponse

use of com.nike.cerberus.auth.connector.AuthResponse in project cerberus by Nike-Inc.

the class InitialLoginStateHandlerTest method handleMfaEnroll.

@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());
}
Also used : User(com.okta.authn.sdk.resource.User) AuthStatus(com.nike.cerberus.auth.connector.AuthStatus) DefaultFactor(com.okta.authn.sdk.impl.resource.DefaultFactor) FactorType(com.okta.authn.sdk.resource.FactorType) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) FactorProvider(com.okta.authn.sdk.resource.FactorProvider) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Example 9 with AuthResponse

use of com.nike.cerberus.auth.connector.AuthResponse in project cerberus by Nike-Inc.

the class InitialLoginStateHandlerTest method handleMfaEnrollFails.

@Test(expected = ApiException.class)
public void handleMfaEnrollFails() throws Exception {
    String email = "email";
    String id = "id";
    AuthStatus expectedStatus = AuthStatus.MFA_REQUIRED;
    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);
    // 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());
}
Also used : User(com.okta.authn.sdk.resource.User) AuthStatus(com.nike.cerberus.auth.connector.AuthStatus) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Example 10 with AuthResponse

use of com.nike.cerberus.auth.connector.AuthResponse in project cerberus by Nike-Inc.

the class MfaStateHandlerTest method handleMfaChallenge.

// ///////////////////////
// Test Methods
// ///////////////////////
@Test
public void handleMfaChallenge() throws Exception {
    String email = "email";
    String id = "id";
    AuthStatus status = AuthStatus.MFA_CHALLENGE;
    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);
    // do the call
    mfaStateHandler.handleMfaChallenge(expectedResponse);
    AuthResponse actualResponse = authenticationResponseFuture.get(1, TimeUnit.SECONDS);
    // verify results
    assertEquals(id, actualResponse.getData().getUserId());
    assertEquals(email, actualResponse.getData().getUsername());
    assertEquals(status, actualResponse.getStatus());
}
Also used : User(com.okta.authn.sdk.resource.User) AuthStatus(com.nike.cerberus.auth.connector.AuthStatus) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Aggregations

AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)30 Test (org.junit.Test)19 AuthData (com.nike.cerberus.auth.connector.AuthData)9 AuthStatus (com.nike.cerberus.auth.connector.AuthStatus)7 AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)7 User (com.okta.authn.sdk.resource.User)7 MfaStateHandler (com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler)6 ApiException (com.nike.backstopper.exception.ApiException)5 FactorValidationException (com.okta.authn.sdk.FactorValidationException)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 InitialLoginStateHandler (com.nike.cerberus.auth.connector.okta.statehandlers.InitialLoginStateHandler)3 DefaultVerifyPassCodeFactorRequest (com.okta.authn.sdk.impl.resource.DefaultVerifyPassCodeFactorRequest)3 UserCredentials (com.nike.cerberus.domain.UserCredentials)2 DefaultFactor (com.okta.authn.sdk.impl.resource.DefaultFactor)2 FactorProvider (com.okta.authn.sdk.resource.FactorProvider)2 FactorType (com.okta.authn.sdk.resource.FactorType)2 PrincipalType (com.nike.cerberus.PrincipalType)1 PushStateHandler (com.nike.cerberus.auth.connector.okta.statehandlers.PushStateHandler)1 CerberusAuthToken (com.nike.cerberus.domain.CerberusAuthToken)1 MfaCheckRequest (com.nike.cerberus.domain.MfaCheckRequest)1