use of org.apereo.cas.configuration.model.support.oidc.OidcProperties in project cas by apereo.
the class OidcConfiguration method oidcServiceJsonWebKeystoreCache.
@Bean
public LoadingCache<OidcRegisteredService, Optional<RsaJsonWebKey>> oidcServiceJsonWebKeystoreCache() {
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final LoadingCache<OidcRegisteredService, Optional<RsaJsonWebKey>> cache = Caffeine.newBuilder().maximumSize(1).expireAfterWrite(oidc.getJwksCacheInMinutes(), TimeUnit.MINUTES).build(oidcServiceJsonWebKeystoreCacheLoader());
return cache;
}
use of org.apereo.cas.configuration.model.support.oidc.OidcProperties in project cas by apereo.
the class OidcIdTokenGeneratorService method produceIdTokenClaims.
/**
* Produce id token claims jwt claims.
*
* @param request the request
* @param accessTokenId the access token id
* @param timeout the timeout
* @param service the service
* @param profile the user profile
* @param context the context
* @param responseType the response type
* @return the jwt claims
*/
protected JwtClaims produceIdTokenClaims(final HttpServletRequest request, final AccessToken accessTokenId, final long timeout, final OidcRegisteredService service, final UserProfile profile, final J2EContext context, final OAuth20ResponseTypes responseType) {
final Authentication authentication = accessTokenId.getAuthentication();
final Principal principal = authentication.getPrincipal();
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final JwtClaims claims = new JwtClaims();
claims.setJwtId(getOAuthServiceTicket(accessTokenId.getTicketGrantingTicket()).getKey());
claims.setIssuer(oidc.getIssuer());
claims.setAudience(service.getClientId());
final NumericDate expirationDate = NumericDate.now();
expirationDate.addSeconds(timeout);
claims.setExpirationTime(expirationDate);
claims.setIssuedAtToNow();
claims.setNotBeforeMinutesInThePast(oidc.getSkew());
claims.setSubject(principal.getId());
final MultifactorAuthenticationProperties mfa = casProperties.getAuthn().getMfa();
final Map<String, Object> attributes = authentication.getAttributes();
if (attributes.containsKey(mfa.getAuthenticationContextAttribute())) {
final Collection<Object> val = CollectionUtils.toCollection(attributes.get(mfa.getAuthenticationContextAttribute()));
claims.setStringClaim(OidcConstants.ACR, val.iterator().next().toString());
}
if (attributes.containsKey(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS)) {
final Collection<Object> val = CollectionUtils.toCollection(attributes.get(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
claims.setStringListClaim(OidcConstants.AMR, val.toArray(new String[] {}));
}
claims.setClaim(OAuth20Constants.STATE, attributes.get(OAuth20Constants.STATE));
claims.setClaim(OAuth20Constants.NONCE, attributes.get(OAuth20Constants.NONCE));
claims.setClaim(OidcConstants.CLAIM_AT_HASH, generateAccessTokenHash(accessTokenId, service));
principal.getAttributes().entrySet().stream().filter(entry -> oidc.getClaims().contains(entry.getKey())).forEach(entry -> claims.setClaim(entry.getKey(), entry.getValue()));
if (!claims.hasClaim(OidcConstants.CLAIM_PREFERRED_USERNAME)) {
claims.setClaim(OidcConstants.CLAIM_PREFERRED_USERNAME, profile.getId());
}
return claims;
}
use of org.apereo.cas.configuration.model.support.oidc.OidcProperties in project cas by apereo.
the class OidcRestfulJsonWebKeystoreGeneratorServiceTests method verifyFailsOperation.
@Test
public void verifyFailsOperation() throws Exception {
var oidcProperties = new OidcProperties();
oidcProperties.getJwks().getRest().setUrl("https://localhost:1234");
oidcProperties.getJwks().getRest().setMethod("get");
val resource = new OidcRestfulJsonWebKeystoreGeneratorService(oidcProperties).generate();
assertNull(resource);
}
use of org.apereo.cas.configuration.model.support.oidc.OidcProperties in project cas by apereo.
the class OidcConfiguration method oauthInterceptor.
@Bean
public HandlerInterceptorAdapter oauthInterceptor() {
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final OidcConstants.DynamicClientRegistrationMode mode = OidcConstants.DynamicClientRegistrationMode.valueOf(StringUtils.defaultIfBlank(oidc.getDynamicClientRegistrationMode(), OidcConstants.DynamicClientRegistrationMode.PROTECTED.name()));
return new OidcHandlerInterceptorAdapter(requiresAuthenticationAccessTokenInterceptor, requiresAuthenticationAuthorizeInterceptor(), requiresAuthenticationDynamicRegistrationInterceptor(), mode, accessTokenGrantRequestExtractors);
}
use of org.apereo.cas.configuration.model.support.oidc.OidcProperties in project cas by apereo.
the class OidcConfiguration method oidcDefaultJsonWebKeystoreCache.
@Bean
public LoadingCache<String, Optional<RsaJsonWebKey>> oidcDefaultJsonWebKeystoreCache() {
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final LoadingCache<String, Optional<RsaJsonWebKey>> cache = Caffeine.newBuilder().maximumSize(1).expireAfterWrite(oidc.getJwksCacheInMinutes(), TimeUnit.MINUTES).build(oidcDefaultJsonWebKeystoreCacheLoader());
return cache;
}
Aggregations