@Test public void testTwoExistingAuthorizerProfileMatch(final TestContext testContext) throws Exception { profile.setId(VALUE); profile.addRole(ROLE); final Map<String, AsyncAuthorizer> authorizers = new HashMap<>(); authorizers.put(NAME, new IdAuthorizer()); authorizers.put(VALUE, fromNonBlockingAuthorizer(new RequireAnyRoleAuthorizer(ROLE))); assertAuthorizationResults(testContext, () -> checker.isAuthorized(null, profiles, NAME + ELEMENT_SEPRATOR + VALUE, authorizers), b -> assertThat(b, is(true))); }
@Override public CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles, final String authorizerNames, final Map<String, AsyncAuthorizer> authorizersMap) { final List<AsyncAuthorizer> authorizers = new LinkedList<>(); if (isNotBlank(authorizerNames)) { final String[] names = authorizerNames.split(Pac4jConstants.ELEMENT_SEPRATOR); final int nb = names.length; for (int i = 0; i < nb; i++) { final String name = names[i].trim(); if ("hsts".equalsIgnoreCase(name)) { authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); } else if ("nosniff".equalsIgnoreCase(name)) { authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); } else if ("noframe".equalsIgnoreCase(name)) { authorizers.add(X_FRAME_OPTIONS_HEADER); } else if ("xssprotection".equalsIgnoreCase(name)) { authorizers.add(XSS_PROTECTION_HEADER); } else if ("nocache".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); } else if ("securityheaders".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); authorizers.add(X_FRAME_OPTIONS_HEADER); authorizers.add(XSS_PROTECTION_HEADER); } else if ("csrfToken".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); } else if ("csrfCheck".equalsIgnoreCase(name)) { authorizers.add(CSRF_AUTHORIZER); } else if ("csrf".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); authorizers.add(CSRF_AUTHORIZER); } else if ("allowAjaxRequests".equalsIgnoreCase(name)) { authorizers.add(CORS_AUTHORIZER); } else if ("isAnonymous".equalsIgnoreCase(name)) { authorizers.add(IS_ANONYMOUS_AUTHORIZER); } else if ("isAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_AUTHENTICATED_AUTHORIZER); } else if ("isFullyAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_FULLY_AUTHENTICATED_AUTHORIZER); } else if ("isRemembered".equalsIgnoreCase(name)) { authorizers.add(IS_REMEMBERED_AUTHORIZER); } else { assertNotNull("authorizersMap", authorizersMap); AsyncAuthorizer result = null; for (final Map.Entry<String, AsyncAuthorizer> entry : authorizersMap.entrySet()) { if (areEqualsIgnoreCaseAndTrim(entry.getKey(), name)) { result = entry.getValue(); break; } } assertNotNull("authorizersMap['" + name + "']", result); authorizers.add(result); } } } return isAuthorized(context, profiles, authorizers); }
DefaultAsyncAuthorizationChecker implements AsyncAuthorizationChecker<CommonProfile> { @Override public CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles, final String authorizerNames, final Map<String, AsyncAuthorizer> authorizersMap) { final List<AsyncAuthorizer> authorizers = new LinkedList<>(); if (isNotBlank(authorizerNames)) { final String[] names = authorizerNames.split(Pac4jConstants.ELEMENT_SEPRATOR); final int nb = names.length; for (int i = 0; i < nb; i++) { final String name = names[i].trim(); if ("hsts".equalsIgnoreCase(name)) { authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); } else if ("nosniff".equalsIgnoreCase(name)) { authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); } else if ("noframe".equalsIgnoreCase(name)) { authorizers.add(X_FRAME_OPTIONS_HEADER); } else if ("xssprotection".equalsIgnoreCase(name)) { authorizers.add(XSS_PROTECTION_HEADER); } else if ("nocache".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); } else if ("securityheaders".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); authorizers.add(X_FRAME_OPTIONS_HEADER); authorizers.add(XSS_PROTECTION_HEADER); } else if ("csrfToken".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); } else if ("csrfCheck".equalsIgnoreCase(name)) { authorizers.add(CSRF_AUTHORIZER); } else if ("csrf".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); authorizers.add(CSRF_AUTHORIZER); } else if ("allowAjaxRequests".equalsIgnoreCase(name)) { authorizers.add(CORS_AUTHORIZER); } else if ("isAnonymous".equalsIgnoreCase(name)) { authorizers.add(IS_ANONYMOUS_AUTHORIZER); } else if ("isAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_AUTHENTICATED_AUTHORIZER); } else if ("isFullyAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_FULLY_AUTHENTICATED_AUTHORIZER); } else if ("isRemembered".equalsIgnoreCase(name)) { authorizers.add(IS_REMEMBERED_AUTHORIZER); } else { assertNotNull("authorizersMap", authorizersMap); AsyncAuthorizer result = null; for (final Map.Entry<String, AsyncAuthorizer> entry : authorizersMap.entrySet()) { if (areEqualsIgnoreCaseAndTrim(entry.getKey(), name)) { result = entry.getValue(); break; } } assertNotNull("authorizersMap['" + name + "']", result); authorizers.add(result); } } } return isAuthorized(context, profiles, authorizers); } }
DefaultAsyncAuthorizationChecker implements AsyncAuthorizationChecker<CommonProfile> { @Override public CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles, final String authorizerNames, final Map<String, AsyncAuthorizer> authorizersMap) { final List<AsyncAuthorizer> authorizers = new LinkedList<>(); if (isNotBlank(authorizerNames)) { final String[] names = authorizerNames.split(Pac4jConstants.ELEMENT_SEPRATOR); final int nb = names.length; for (int i = 0; i < nb; i++) { final String name = names[i].trim(); if ("hsts".equalsIgnoreCase(name)) { authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); } else if ("nosniff".equalsIgnoreCase(name)) { authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); } else if ("noframe".equalsIgnoreCase(name)) { authorizers.add(X_FRAME_OPTIONS_HEADER); } else if ("xssprotection".equalsIgnoreCase(name)) { authorizers.add(XSS_PROTECTION_HEADER); } else if ("nocache".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); } else if ("securityheaders".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); authorizers.add(X_FRAME_OPTIONS_HEADER); authorizers.add(XSS_PROTECTION_HEADER); } else if ("csrfToken".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); } else if ("csrfCheck".equalsIgnoreCase(name)) { authorizers.add(CSRF_AUTHORIZER); } else if ("csrf".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); authorizers.add(CSRF_AUTHORIZER); } else if ("allowAjaxRequests".equalsIgnoreCase(name)) { authorizers.add(CORS_AUTHORIZER); } else if ("isAnonymous".equalsIgnoreCase(name)) { authorizers.add(IS_ANONYMOUS_AUTHORIZER); } else if ("isAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_AUTHENTICATED_AUTHORIZER); } else if ("isFullyAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_FULLY_AUTHENTICATED_AUTHORIZER); } else if ("isRemembered".equalsIgnoreCase(name)) { authorizers.add(IS_REMEMBERED_AUTHORIZER); } else { assertNotNull("authorizersMap", authorizersMap); AsyncAuthorizer result = null; for (final Map.Entry<String, AsyncAuthorizer> entry : authorizersMap.entrySet()) { if (areEqualsIgnoreCaseAndTrim(entry.getKey(), name)) { result = entry.getValue(); break; } } assertNotNull("authorizersMap['" + name + "']", result); authorizers.add(result); } } } return isAuthorized(context, profiles, authorizers); }  }
DefaultAsyncAuthorizationChecker implements AsyncAuthorizationChecker<CommonProfile> { @Override public CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles, final String authorizerNames, final Map<String, AsyncAuthorizer> authorizersMap) { final List<AsyncAuthorizer> authorizers = new LinkedList<>(); if (isNotBlank(authorizerNames)) { final String[] names = authorizerNames.split(Pac4jConstants.ELEMENT_SEPRATOR); final int nb = names.length; for (int i = 0; i < nb; i++) { final String name = names[i].trim(); if ("hsts".equalsIgnoreCase(name)) { authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); } else if ("nosniff".equalsIgnoreCase(name)) { authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); } else if ("noframe".equalsIgnoreCase(name)) { authorizers.add(X_FRAME_OPTIONS_HEADER); } else if ("xssprotection".equalsIgnoreCase(name)) { authorizers.add(XSS_PROTECTION_HEADER); } else if ("nocache".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); } else if ("securityheaders".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); authorizers.add(X_FRAME_OPTIONS_HEADER); authorizers.add(XSS_PROTECTION_HEADER); } else if ("csrfToken".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); } else if ("csrfCheck".equalsIgnoreCase(name)) { authorizers.add(CSRF_AUTHORIZER); } else if ("csrf".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); authorizers.add(CSRF_AUTHORIZER); } else if ("allowAjaxRequests".equalsIgnoreCase(name)) { authorizers.add(CORS_AUTHORIZER); } else if ("isAnonymous".equalsIgnoreCase(name)) { authorizers.add(IS_ANONYMOUS_AUTHORIZER); } else if ("isAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_AUTHENTICATED_AUTHORIZER); } else if ("isFullyAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_FULLY_AUTHENTICATED_AUTHORIZER); } else if ("isRemembered".equalsIgnoreCase(name)) { authorizers.add(IS_REMEMBERED_AUTHORIZER); } else { assertNotNull("authorizersMap", authorizersMap); AsyncAuthorizer result = null; for (final Map.Entry<String, AsyncAuthorizer> entry : authorizersMap.entrySet()) { if (areEqualsIgnoreCaseAndTrim(entry.getKey(), name)) { result = entry.getValue(); break; } } assertNotNull("authorizersMap['" + name + "']", result); authorizers.add(result); } } } return isAuthorized(context, profiles, authorizers); }  @Override CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles,
                                                   final String authorizerNames,
                                                   final Map<String, AsyncAuthorizer> authorizersMap); }
DefaultAsyncAuthorizationChecker implements AsyncAuthorizationChecker<CommonProfile> { @Override public CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles, final String authorizerNames, final Map<String, AsyncAuthorizer> authorizersMap) { final List<AsyncAuthorizer> authorizers = new LinkedList<>(); if (isNotBlank(authorizerNames)) { final String[] names = authorizerNames.split(Pac4jConstants.ELEMENT_SEPRATOR); final int nb = names.length; for (int i = 0; i < nb; i++) { final String name = names[i].trim(); if ("hsts".equalsIgnoreCase(name)) { authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); } else if ("nosniff".equalsIgnoreCase(name)) { authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); } else if ("noframe".equalsIgnoreCase(name)) { authorizers.add(X_FRAME_OPTIONS_HEADER); } else if ("xssprotection".equalsIgnoreCase(name)) { authorizers.add(XSS_PROTECTION_HEADER); } else if ("nocache".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); } else if ("securityheaders".equalsIgnoreCase(name)) { authorizers.add(CACHE_CONTROL_HEADER); authorizers.add(X_CONTENT_TYPE_OPTIONS_HEADER); authorizers.add(STRICT_TRANSPORT_SECURITY_HEADER); authorizers.add(X_FRAME_OPTIONS_HEADER); authorizers.add(XSS_PROTECTION_HEADER); } else if ("csrfToken".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); } else if ("csrfCheck".equalsIgnoreCase(name)) { authorizers.add(CSRF_AUTHORIZER); } else if ("csrf".equalsIgnoreCase(name)) { authorizers.add(CSRF_TOKEN_GENERATOR_AUTHORIZER); authorizers.add(CSRF_AUTHORIZER); } else if ("allowAjaxRequests".equalsIgnoreCase(name)) { authorizers.add(CORS_AUTHORIZER); } else if ("isAnonymous".equalsIgnoreCase(name)) { authorizers.add(IS_ANONYMOUS_AUTHORIZER); } else if ("isAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_AUTHENTICATED_AUTHORIZER); } else if ("isFullyAuthenticated".equalsIgnoreCase(name)) { authorizers.add(IS_FULLY_AUTHENTICATED_AUTHORIZER); } else if ("isRemembered".equalsIgnoreCase(name)) { authorizers.add(IS_REMEMBERED_AUTHORIZER); } else { assertNotNull("authorizersMap", authorizersMap); AsyncAuthorizer result = null; for (final Map.Entry<String, AsyncAuthorizer> entry : authorizersMap.entrySet()) { if (areEqualsIgnoreCaseAndTrim(entry.getKey(), name)) { result = entry.getValue(); break; } } assertNotNull("authorizersMap['" + name + "']", result); authorizers.add(result); } } } return isAuthorized(context, profiles, authorizers); }  @Override CompletableFuture<Boolean> isAuthorized(final AsyncWebContext context, final List<CommonProfile> profiles,
                                                   final String authorizerNames,
                                                   final Map<String, AsyncAuthorizer> authorizersMap);  }