CustomAuthorizerSecurityContextFactory extends AbstractSecurityContextFactory { @Override protected Principal createPrincipal() { Map<String, Object> authorizerData = getAuthorizerDataSafe(); String principalId = (String) getRawPrincipalIdSafe(authorizerData); CustomAuthorizerClaims claims = createCustomAuthorizerClaims(authorizerData, principalId); CustomAuthorizerPrincipal principal = () -> claims; return principal; } protected  CustomAuthorizerSecurityContextFactory(GatewayRequest request);   }
@Test public void createPrincipal_PrincipalIdGiven_ShouldCreatePrincipal() { GatewayRequest request = createRequestMock("principalId"); CustomAuthorizerPrincipal principal = (CustomAuthorizerPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("principalId", principal.getName()); assertEquals("principalId", principal.getClaims().getPrincipalId()); assertEquals("principalId", principal.getClaims().getAllClaims().get("principalId")); }
@Test public void createPrincipal_PrincipalIdWithAdditionalClaimsGiven_ShouldCreatePrincipal() { Map<String, Object> claims = new HashMap<>(); claims.put("principalId", "principalId"); claims.put("someOtherClaim", "someOtherClaimValue"); GatewayRequest request = createRequestMock(claims); CustomAuthorizerPrincipal principal = (CustomAuthorizerPrincipal) createSecurityContextFactory(request) .createPrincipal(); assertEquals("principalId", principal.getName()); assertEquals("principalId", principal.getClaims().getPrincipalId()); assertEquals("principalId", principal.getClaims().getAllClaims().get("principalId")); assertEquals("someOtherClaimValue", principal.getClaims().getAllClaims().get("someOtherClaim")); }