CognitoIdentitySecurityContextFactory extends AbstractSecurityContextFactory { @Override protected Principal createPrincipal() { GatewayIdentity identity = getIdentitySafe(); String cognitoIdentityId = identity.getCognitoIdentityId(); String cognitoIdentityPoolId = identity.getCognitoIdentityPoolId(); String cognitoAuthenticationType = identity.getCognitoAuthenticationType(); String cognitoAuthenticationProvider = identity.getCognitoAuthenticationProvider(); String userArn = identity.getUserArn(); String user = identity.getUser(); String accessKey = identity.getAccessKey(); String caller = identity.getCaller(); return new CognitoIdentityPrincipal() { @Override public String getCognitoIdentityId() { return cognitoIdentityId; } @Override public String getCognitoIdentityPoolId() { return cognitoIdentityPoolId; } @Override public String getCognitoAuthenticationType() { return cognitoAuthenticationType; } @Override public String getCognitoAuthenticationProvider() { return cognitoAuthenticationProvider; } @Override public String getUserArn() { return userArn; } @Override public String getUser() { return user; } @Override public String getAccessKey() { return accessKey; } @Override public String getCaller() { return caller; } }; } protected  CognitoIdentitySecurityContextFactory(GatewayRequest request);   }
@Test public void createPrincipal_MinimalDateGiven_ShouldCreatePrincipal() { GatewayRequest request = createRequestMock("cognitoAuthenticationType", "cognitoIdentityId", null, null, null, null, null, null); CognitoIdentityPrincipal principal = (CognitoIdentityPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("cognitoIdentityId", principal.getName()); assertEquals("cognitoIdentityId", principal.getCognitoIdentityId()); assertEquals("cognitoAuthenticationType", principal.getCognitoAuthenticationType()); assertNull(principal.getCognitoAuthenticationProvider()); assertNull(principal.getCognitoIdentityPoolId()); assertNull(principal.getUserArn()); assertNull(principal.getUser()); assertNull(principal.getAccessKey()); assertNull(principal.getCaller()); }
@Test public void createPrincipal_AllDateGiven_ShouldCreatePrincipal() { GatewayRequest request = createRequestMock("cognitoAuthenticationType", "cognitoIdentityId", "cognitoIdentityPoolId", "cognitoAuthenticationProvider", "userArn", "user", "accessKey", "caller"); CognitoIdentityPrincipal principal = (CognitoIdentityPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("cognitoIdentityId", principal.getName()); assertEquals("cognitoIdentityId", principal.getCognitoIdentityId()); assertEquals("cognitoAuthenticationType", principal.getCognitoAuthenticationType()); assertEquals("cognitoAuthenticationProvider", principal.getCognitoAuthenticationProvider()); assertEquals("cognitoIdentityPoolId", principal.getCognitoIdentityPoolId()); assertEquals("userArn", principal.getUserArn()); assertEquals("user", principal.getUser()); assertEquals("accessKey", principal.getAccessKey()); assertEquals("caller", principal.getCaller()); }