Skip to content

Commit f89c26d

Browse files
committed
Merge branch 'hotfix/callback-authorize-update' into hotfix/21.1.2
2 parents dfad59c + d34bcf8 commit f89c26d

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

src/main/java/org/apereo/cas/config/CasOAuth20ServicesConfiguration.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import org.apereo.cas.authentication.principal.Service;
44
import org.apereo.cas.authentication.principal.ServiceFactory;
55
import org.apereo.cas.configuration.CasConfigurationProperties;
6-
import org.apereo.cas.services.DenyAllAttributeReleasePolicy;
6+
import org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy;
7+
import org.apereo.cas.services.DefaultRegisteredServiceDelegatedAuthenticationPolicy;
78
import org.apereo.cas.services.RegexRegisteredService;
9+
import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy;
810
import org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer;
911
import org.apereo.cas.support.oauth.services.OAuth20ServiceRegistry;
10-
import org.apereo.cas.util.RandomUtils;
1112

1213
import lombok.val;
1314

@@ -23,6 +24,9 @@
2324
import org.springframework.context.annotation.Configuration;
2425
import org.springframework.core.Ordered;
2526

27+
import java.util.ArrayList;
28+
import java.util.List;
29+
2630
/**
2731
* This is {@link CasOAuth20ServicesConfiguration}.
2832
*
@@ -56,14 +60,28 @@ public Service oauthCallbackService() {
5660
@Bean
5761
@ConditionalOnMissingBean(name = "oauthServiceRegistryExecutionPlanConfigurer")
5862
public ServiceRegistryExecutionPlanConfigurer oauthServiceRegistryExecutionPlanConfigurer() {
63+
64+
// TODO: Currently, "login to authorize" is not supported for ORCiD, thus only add institution clients. Fortunately, unlike
65+
// oldCAS, newCAS supports this feature to be implemented using JPA OSF data access model without OSF side changes.
66+
final List<String> allowedProviders = new ArrayList<>(casProperties.getAuthn().getOsfPostgres().getInstitutionClients());
67+
final DefaultRegisteredServiceDelegatedAuthenticationPolicy delegatedAuthenticationPolicy = new DefaultRegisteredServiceDelegatedAuthenticationPolicy();
68+
delegatedAuthenticationPolicy.setAllowedProviders(allowedProviders);
69+
delegatedAuthenticationPolicy.setPermitUndefined(false);
70+
final DefaultRegisteredServiceAccessStrategy accessStrategy = new DefaultRegisteredServiceAccessStrategy();
71+
accessStrategy.setDelegatedAuthenticationPolicy(delegatedAuthenticationPolicy);
72+
73+
// OSF CAS customization: re-use oldCAS service ID which is fixed instead of random, use a new user-friendly service name that
74+
// informs users that this is the login to authorize, temporarily disable ORCiD login via access strategy due to the aforementioned
75+
// oldCAS limitation, and return allowed attributes via release strategy
5976
return plan -> {
6077
val service = new RegexRegisteredService();
61-
service.setId(RandomUtils.nextLong());
78+
service.setId(983450982340993434L);
6279
service.setEvaluationOrder(Ordered.HIGHEST_PRECEDENCE);
63-
service.setName(service.getClass().getSimpleName());
80+
service.setName("OSF Authorization");
6481
service.setDescription("OAuth Authentication Callback Request URL");
6582
service.setServiceId(oauthCallbackService().getId());
66-
service.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy());
83+
service.setAccessStrategy(accessStrategy);
84+
service.setAttributeReleasePolicy(new ReturnAllowedAttributeReleasePolicy(new ArrayList<>()));
6785
plan.registerServiceRegistry(new OAuth20ServiceRegistry(applicationContext, service));
6886
};
6987
}

0 commit comments

Comments
 (0)