Search in sources :

Example 6 with User

use of com.okta.authn.sdk.resource.User in project okta-auth-java by okta.

the class OktaRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    AuthenticationResponse authenticationResponse = ((OktaSuccessLoginToken) token).getAuthenticationResponse();
    // auth already verified, just check the status
    if (authenticationResponse != null && authenticationResponse.getStatus() == AuthenticationStatus.SUCCESS && authenticationResponse.getSessionToken() != null) {
        // if we have a valid User (see below) return an AuthenticationInfo
        User result = authenticationResponse.getUser();
        if (result != null) {
            SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(result.getLogin(), getName());
            principalCollection.add(result, getName());
            return new SimpleAuthenticationInfo(principalCollection, null);
        }
    }
    // returning null means the user is NOT authenticated
    return null;
}
Also used : User(com.okta.authn.sdk.resource.User) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse)

Example 7 with User

use of com.okta.authn.sdk.resource.User in project cerberus by Nike-Inc.

the class InitialLoginStateHandlerTest method handleMfaRequired.

// ///////////////////////
// Test Methods
// ///////////////////////
@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());
}
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 8 with User

use of com.okta.authn.sdk.resource.User in project cerberus by Nike-Inc.

the class PushStateHandlerTest method handleMfaSuccessHappy.

@Test
public void handleMfaSuccessHappy() throws InterruptedException, ExecutionException, TimeoutException {
    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);
    when(expectedResponse.getStatus()).thenReturn(AuthenticationStatus.SUCCESS);
    // do the call
    pushStateHandler.handleSuccess(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

AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)8 User (com.okta.authn.sdk.resource.User)8 AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)7 AuthStatus (com.nike.cerberus.auth.connector.AuthStatus)7 Test (org.junit.Test)7 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 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1