Search in sources :

Example 1 with Authorizer

use of org.pac4j.core.authorization.authorizer.Authorizer in project cas by apereo.

the class CasConsentReviewConfiguration method casConsentPac4jConfig.

@Bean
@RefreshScope
public Config casConsentPac4jConfig() {
    final CasConfiguration conf = new CasConfiguration(casProperties.getServer().getLoginUrl());
    final CasClient client = new CasClient(conf);
    client.setName(CAS_CONSENT_CLIENT);
    client.setCallbackUrl(casProperties.getServer().getPrefix().concat("/consentReview/callback"));
    client.setAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
    final Clients clients = new Clients(client);
    final Config config = new Config(clients);
    config.setAuthorizer(new IsAuthenticatedAuthorizer());
    config.setCallbackLogic(new DefaultCallbackLogic());
    config.setLogoutLogic(new DefaultLogoutLogic());
    // get role authorizer from admin pages for smooth integration
    final Map<String, Authorizer> adminAuthorizers = casAdminPagesPac4jConfig.getAuthorizers();
    final String auth = RequireAnyRoleAuthorizer.class.getSimpleName();
    if (adminAuthorizers.containsKey(auth)) {
        config.addAuthorizer(auth, adminAuthorizers.get(auth));
        final BaseClient adminClient = casAdminPagesPac4jConfig.getClients().findClient(DirectCasClient.class);
        client.addAuthorizationGenerators(adminClient.getAuthorizationGenerators());
    }
    return config;
}
Also used : IsAuthenticatedAuthorizer(org.pac4j.core.authorization.authorizer.IsAuthenticatedAuthorizer) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Config(org.pac4j.core.config.Config) RequireAnyRoleAuthorizer(org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer) IsAuthenticatedAuthorizer(org.pac4j.core.authorization.authorizer.IsAuthenticatedAuthorizer) Authorizer(org.pac4j.core.authorization.authorizer.Authorizer) Clients(org.pac4j.core.client.Clients) DefaultLogoutLogic(org.pac4j.core.engine.DefaultLogoutLogic) DefaultCallbackLogic(org.pac4j.core.engine.DefaultCallbackLogic) BaseClient(org.pac4j.core.client.BaseClient) CasClient(org.pac4j.cas.client.CasClient) DirectCasClient(org.pac4j.cas.client.direct.DirectCasClient) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

CasClient (org.pac4j.cas.client.CasClient)1 DirectCasClient (org.pac4j.cas.client.direct.DirectCasClient)1 CasConfiguration (org.pac4j.cas.config.CasConfiguration)1 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)1 IsAuthenticatedAuthorizer (org.pac4j.core.authorization.authorizer.IsAuthenticatedAuthorizer)1 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)1 BaseClient (org.pac4j.core.client.BaseClient)1 Clients (org.pac4j.core.client.Clients)1 Config (org.pac4j.core.config.Config)1 DefaultCallbackLogic (org.pac4j.core.engine.DefaultCallbackLogic)1 DefaultLogoutLogic (org.pac4j.core.engine.DefaultLogoutLogic)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1