use of org.pac4j.cas.config.CasConfiguration in project cas by apereo.
the class CasSecurityContextConfiguration method config.
@RefreshScope
@Bean
public Config config() {
try {
final AdminPagesSecurityProperties adminProps = casProperties.getAdminPagesSecurity();
if (StringUtils.isNotBlank(adminProps.getLoginUrl()) && StringUtils.isNotBlank(adminProps.getService())) {
final CasConfiguration casConfig = new CasConfiguration(adminProps.getLoginUrl());
final DirectCasClient client = new DirectCasClient(casConfig);
client.setName(CAS_CLIENT_NAME);
final Config cfg = new Config(adminProps.getService(), client);
if (adminProps.getUsers() == null) {
LOGGER.warn("List of authorized users for admin pages security is not defined. " + "Allowing access for all authenticated users");
client.setAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
cfg.setAuthorizer(new IsAuthenticatedAuthorizer());
} else {
final Resource file = ResourceUtils.prepareClasspathResourceIfNeeded(adminProps.getUsers());
if (file != null && file.exists()) {
LOGGER.debug("Loading list of authorized users from [{}]", file);
final Properties properties = new Properties();
properties.load(file.getInputStream());
client.setAuthorizationGenerator(new SpringSecurityPropertiesAuthorizationGenerator(properties));
cfg.setAuthorizer(new RequireAnyRoleAuthorizer(adminProps.getAdminRoles()));
}
}
return cfg;
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return new Config();
}
use of org.pac4j.cas.config.CasConfiguration in project cas by apereo.
the class OAuth20DefaultCasClientRedirectActionBuilder method build.
@Override
public RedirectAction build(final CasClient casClient, final WebContext context) {
try {
final CasConfiguration casConfiguration = casClient.getConfiguration();
final String redirectionUrl = CommonUtils.constructRedirectUrl(casConfiguration.getLoginUrl(), CasProtocolConstants.PARAMETER_SERVICE, casClient.computeFinalCallbackUrl(context), casConfiguration.isRenew(), casConfiguration.isGateway());
LOGGER.debug("Final redirect url is [{}]", redirectionUrl);
return RedirectAction.redirect(redirectionUrl);
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
}
use of org.pac4j.cas.config.CasConfiguration in project cas by apereo.
the class CasManagementWebAppConfiguration method casClient.
@Bean
public Client casClient() {
final CasConfiguration cfg = new CasConfiguration(casProperties.getServer().getLoginUrl());
final DirectCasClient client = new DirectCasClient(cfg);
client.setAuthorizationGenerator(authorizationGenerator());
client.setName("CasClient");
return client;
}
use of org.pac4j.cas.config.CasConfiguration in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureCasClient.
private void configureCasClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getCas().stream().filter(cas -> StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
final CasConfiguration cfg = new CasConfiguration(cas.getLoginUrl(), cas.getProtocol());
final CasClient client = new CasClient(cfg);
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
use of org.pac4j.cas.config.CasConfiguration in project cas by apereo.
the class CasOAuthConfiguration method oauthSecConfig.
@RefreshScope
@Bean
public Config oauthSecConfig() {
final CasConfiguration cfg = new CasConfiguration(casProperties.getServer().getLoginUrl());
final CasClient oauthCasClient = new CasClient(cfg);
oauthCasClient.setRedirectActionBuilder(webContext -> oauthCasClientRedirectActionBuilder().build(oauthCasClient, webContext));
oauthCasClient.setName(Authenticators.CAS_OAUTH_CLIENT);
oauthCasClient.setUrlResolver(casCallbackUrlResolver());
final Authenticator authenticator = oAuthClientAuthenticator();
final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(authenticator);
basicAuthClient.setName(Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN);
final DirectFormClient directFormClient = new DirectFormClient(authenticator);
directFormClient.setName(Authenticators.CAS_OAUTH_CLIENT_DIRECT_FORM);
directFormClient.setUsernameParameter(CLIENT_ID);
directFormClient.setPasswordParameter(CLIENT_SECRET);
final DirectFormClient userFormClient = new DirectFormClient(oAuthUserAuthenticator());
userFormClient.setName(Authenticators.CAS_OAUTH_CLIENT_USER_FORM);
return new Config(OAuthUtils.casOAuthCallbackUrl(casProperties.getServer().getPrefix()), oauthCasClient, basicAuthClient, directFormClient, userFormClient);
}
Aggregations