use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeRegisteredService.
@Test
public void verifyEncodeDecodeRegisteredService() {
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("helloworld");
final CachedData result = transcoder.encode(service);
assertEquals(service, transcoder.decode(result));
assertEquals(service, transcoder.decode(result));
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class CasRegisteredServiceHazelcastStreamPublisher method getCacheObject.
private DistributedCacheObject<RegisteredService> getCacheObject(final RegisteredService service, final ApplicationEvent event) {
final long time = new Date().getTime();
final DistributedCacheObject<RegisteredService> item = new DistributedCacheObject<>(time, service);
item.getProperties().put("event", event);
return item;
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class SurrogateAuthorizationAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
final Authentication ca = AuthenticationCredentialsThreadLocalBinder.getCurrentAuthentication();
try {
final Service service = WebUtils.getService(requestContext);
final Authentication authentication = WebUtils.getAuthentication(requestContext);
final RegisteredService svc = WebUtils.getRegisteredService(requestContext);
if (svc != null) {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(authentication);
final AuditableContext audit = AuditableContext.builder().service(service).authentication(authentication).registeredService(svc).retrievePrincipalAttributesFromReleasePolicy(Boolean.TRUE).build();
final AuditableExecutionResult accessResult = this.registeredServiceAccessStrategyEnforcer.execute(audit);
accessResult.throwExceptionIfNeeded();
return success();
}
return null;
} finally {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(ca);
}
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class BaseOidcScopeAttributeReleasePolicy method getAttributesInternal.
@Override
public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) {
final ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext();
if (applicationContext == null) {
LOGGER.warn("Could not locate the application context to process attributes");
return new HashMap<>();
}
final Map<String, Object> resolvedAttributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
resolvedAttributes.putAll(attributes);
final Map<String, Object> attributesToRelease = new HashMap<>(resolvedAttributes.size());
LOGGER.debug("Attempting to map and filter claims based on resolved attributes [{}]", resolvedAttributes);
final CasConfigurationProperties properties = applicationContext.getBean(CasConfigurationProperties.class);
final List<String> supportedClaims = properties.getAuthn().getOidc().getClaims();
final Set<String> allowedClaims = new HashSet<>(getAllowedAttributes());
allowedClaims.retainAll(supportedClaims);
LOGGER.debug("[{}] is designed to allow claims [{}] for scope [{}]. After cross-checking with " + "supported claims [{}], the final collection of allowed attributes is [{}]", getClass().getSimpleName(), getAllowedAttributes(), getScopeName(), supportedClaims, allowedClaims);
allowedClaims.stream().map(claim -> mapClaimToAttribute(claim, resolvedAttributes)).filter(p -> p.getValue() != null).forEach(p -> attributesToRelease.put(p.getKey(), p.getValue()));
return attributesToRelease;
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class OidcProfileScopeToAttributesFilter method reconcile.
@Override
public void reconcile(final RegisteredService service) {
if (!(service instanceof OidcRegisteredService)) {
super.reconcile(service);
return;
}
LOGGER.debug("Reconciling OpenId Connect scopes and claims for [{}]", service.getServiceId());
final List<String> otherScopes = new ArrayList<>();
final ChainingAttributeReleasePolicy policy = new ChainingAttributeReleasePolicy();
final OidcRegisteredService oidc = OidcRegisteredService.class.cast(service);
oidc.getScopes().forEach(s -> {
LOGGER.debug("Reviewing scope [{}] for [{}]", s, service.getServiceId());
try {
final OidcConstants.StandardScopes scope = OidcConstants.StandardScopes.valueOf(s.trim().toLowerCase().toUpperCase());
switch(scope) {
case EMAIL:
LOGGER.debug("Mapped [{}] to attribute release policy [{}]", s, OidcEmailScopeAttributeReleasePolicy.class.getSimpleName());
policy.getPolicies().add(new OidcEmailScopeAttributeReleasePolicy());
break;
case ADDRESS:
LOGGER.debug("Mapped [{}] to attribute release policy [{}]", s, OidcAddressScopeAttributeReleasePolicy.class.getSimpleName());
policy.getPolicies().add(new OidcAddressScopeAttributeReleasePolicy());
break;
case PROFILE:
LOGGER.debug("Mapped [{}] to attribute release policy [{}]", s, OidcProfileScopeAttributeReleasePolicy.class.getSimpleName());
policy.getPolicies().add(new OidcProfileScopeAttributeReleasePolicy());
break;
case PHONE:
LOGGER.debug("Mapped [{}] to attribute release policy [{}]", s, OidcProfileScopeAttributeReleasePolicy.class.getSimpleName());
policy.getPolicies().add(new OidcPhoneScopeAttributeReleasePolicy());
break;
case OFFLINE_ACCESS:
LOGGER.debug("Given scope [{}], service [{}] is marked to generate refresh tokens", s, service.getId());
oidc.setGenerateRefreshToken(Boolean.TRUE);
break;
case CUSTOM:
LOGGER.debug("Found custom scope [{}] for service [{}]", s, service.getId());
otherScopes.add(s.trim());
break;
default:
LOGGER.debug("Scope [{}] is unsupported for service [{}]", s, service.getId());
break;
}
} catch (final Exception e) {
LOGGER.debug("[{}] appears to be a user-defined scope and does not match any of the predefined standard scopes. " + "Checking [{}] against user-defined scopes provided as [{}]", s, s, userScopes);
final BaseOidcScopeAttributeReleasePolicy userPolicy = userScopes.stream().filter(t -> t.getScopeName().equals(s.trim())).findFirst().orElse(null);
if (userPolicy != null) {
LOGGER.debug("Mapped user-defined scope [{}] to attribute release policy [{}]", s, userPolicy);
policy.getPolicies().add(userPolicy);
}
}
});
otherScopes.remove(OidcConstants.StandardScopes.OPENID.getScope());
if (!otherScopes.isEmpty()) {
LOGGER.debug("Mapped scopes [{}] to attribute release policy [{}]", otherScopes, OidcCustomScopeAttributeReleasePolicy.class.getSimpleName());
policy.getPolicies().add(new OidcCustomScopeAttributeReleasePolicy(otherScopes));
}
if (policy.getPolicies().isEmpty()) {
LOGGER.debug("No attribute release policy could be determined based on given scopes. " + "No claims/attributes will be released to [{}]", service.getServiceId());
oidc.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy());
} else {
oidc.setAttributeReleasePolicy(policy);
}
LOGGER.debug("Scope/claim reconciliation for service [{}] resulted in the following attribute release policy [{}]", service.getServiceId(), oidc.getAttributeReleasePolicy());
if (!oidc.equals(service)) {
LOGGER.debug("Saving scope/claim reconciliation results for service [{}] into registry", service.getServiceId());
this.servicesManager.save(oidc);
LOGGER.debug("Saved service [{}] into registry", service.getServiceId());
} else {
LOGGER.debug("No changes detected in service [{}] after scope/claim reconciliation", service.getId());
}
}
Aggregations