IamSecurityContextFactory extends AbstractSecurityContextFactory { @Override protected Principal createPrincipal() { GatewayIdentity identity = getIdentitySafe(); String userArn = identity.getUserArn(); String user = identity.getUser(); String accessKey = identity.getAccessKey(); String caller = identity.getCaller(); return new IamPrincipal() { @Override public String getUser() { return user; } @Override public String getUserArn() { return userArn; } @Override public String getAccessKey() { return accessKey; } @Override public String getCaller() { return caller; } }; } protected  IamSecurityContextFactory(@Nonnull GatewayRequest request);   }
@Test public void createPrincipal_AccessKeyAndUserArnAndUserAndCallerGiven_ShouldCreateIamPrincipal() { GatewayRequest request = createRequestMock("accessKey", "userArn", "user", "caller"); IamPrincipal principal = (IamPrincipal) createSecurityContextFactory(request).createPrincipal(); assertEquals("accessKey", principal.getAccessKey()); assertEquals("userArn", principal.getUserArn()); assertEquals("user", principal.getUser()); assertEquals("caller", principal.getCaller()); assertEquals(principal.getUserArn(), principal.getName()); }
@Test public void createPrincipal_OnlyAccessKeyGiven_ShouldCreateIamPrincipal() { GatewayRequest request = createRequestMock("accessKey", null, null, null); IamPrincipal principal = (IamPrincipal) createSecurityContextFactory(request).createPrincipal(); assertEquals("accessKey", principal.getAccessKey()); assertNull(principal.getUserArn()); assertNull(principal.getUser()); assertNull(principal.getCaller()); assertEquals(principal.getUserArn(), principal.getName()); }