Search in sources :

Example 6 with AuthData

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

the class InitialLoginStateHandler method handleMfaResponse.

/**
 * Handles MFA states by determining valid user MFA factors.
 *
 * @param mfaResponse - Authentication response from the Completable Future
 */
private void handleMfaResponse(AuthenticationResponse mfaResponse) {
    final String userId = mfaResponse.getUser().getId();
    final String userLogin = mfaResponse.getUser().getLogin();
    final AuthData authData = AuthData.builder().userId(userId).username(userLogin).build();
    final AuthResponse authResponse = AuthResponse.builder().data(authData).build();
    authData.setStateToken(mfaResponse.getStateToken());
    authResponse.setStatus(AuthStatus.MFA_REQUIRED);
    final List<Factor> factors = new ArrayList<>(mfaResponse.getFactors());
    factors.removeIf(this::isPush);
    validateUserFactors(factors);
    factors.forEach(factor -> authData.getDevices().add(AuthMfaDevice.builder().id(factor.getId()).name(getDeviceName(factor)).requiresTrigger(isTriggerRequired(factor)).isPush(isPush(factor)).build()));
    authenticationResponseFuture.complete(authResponse);
}
Also used : AuthData(com.nike.cerberus.auth.connector.AuthData) Factor(com.okta.authn.sdk.resource.Factor) ArrayList(java.util.ArrayList) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse)

Example 7 with AuthData

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

the class PushStateHandler method handleSuccess.

/**
 * 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 handleSuccess(AuthenticationResponse mfaChallengeResponse) {
    final String userId = mfaChallengeResponse.getUser().getId();
    final String userLogin = mfaChallengeResponse.getUser().getLogin();
    final String factorResult = mfaChallengeResponse.getStatus().toString();
    final AuthData authData = AuthData.builder().userId(userId).username(userLogin).factorResult(factorResult).build();
    AuthResponse authResponse = AuthResponse.builder().data(authData).status(AuthStatus.SUCCESS).build();
    authenticationResponseFuture.complete(authResponse);
}
Also used : AuthData(com.nike.cerberus.auth.connector.AuthData) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse)

Example 8 with AuthData

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

the class PushStateHandler 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 String factorResult = mfaChallengeResponse.getFactorResult();
    final AuthData authData = AuthData.builder().userId(userId).username(userLogin).factorResult(factorResult).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 9 with AuthData

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

the class OktaAuthConnectorTest method triggerChallengeSuccess.

@Test
public void triggerChallengeSuccess() throws Exception {
    String stateToken = "state token";
    String deviceId = "device id";
    AuthResponse expectedResponse = mock(AuthResponse.class);
    AuthData expectedData = mock(AuthData.class);
    when(expectedData.getStateToken()).thenReturn(stateToken);
    when(expectedResponse.getData()).thenReturn(expectedData);
    doAnswer(invocation -> {
        MfaStateHandler stateHandler = (MfaStateHandler) invocation.getArguments()[2];
        stateHandler.authenticationResponseFuture.complete(expectedResponse);
        return null;
    }).when(client).challengeFactor(any(), any(), any());
    // do the call
    AuthResponse actualResponse = this.oktaAuthConnector.triggerChallenge(stateToken, deviceId);
    // verify results
    assertEquals(expectedResponse, actualResponse);
    assertEquals(expectedResponse.getData().getStateToken(), actualResponse.getData().getStateToken());
}
Also used : AuthData(com.nike.cerberus.auth.connector.AuthData) MfaStateHandler(com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler) AuthResponse(com.nike.cerberus.auth.connector.AuthResponse) Test(org.junit.Test)

Aggregations

AuthData (com.nike.cerberus.auth.connector.AuthData)9 AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)9 Test (org.junit.Test)3 MfaStateHandler (com.nike.cerberus.auth.connector.okta.statehandlers.MfaStateHandler)2 MfaCheckRequest (com.nike.cerberus.domain.MfaCheckRequest)1 Factor (com.okta.authn.sdk.resource.Factor)1 ArrayList (java.util.ArrayList)1 Matchers.anyString (org.mockito.Matchers.anyString)1