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