|
3 | 3 | import org.apereo.cas.authentication.principal.Service; |
4 | 4 | import org.apereo.cas.authentication.principal.ServiceFactory; |
5 | 5 | 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; |
7 | 8 | import org.apereo.cas.services.RegexRegisteredService; |
| 9 | +import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy; |
8 | 10 | import org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer; |
9 | 11 | import org.apereo.cas.support.oauth.services.OAuth20ServiceRegistry; |
10 | | -import org.apereo.cas.util.RandomUtils; |
11 | 12 |
|
12 | 13 | import lombok.val; |
13 | 14 |
|
|
23 | 24 | import org.springframework.context.annotation.Configuration; |
24 | 25 | import org.springframework.core.Ordered; |
25 | 26 |
|
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.List; |
| 29 | + |
26 | 30 | /** |
27 | 31 | * This is {@link CasOAuth20ServicesConfiguration}. |
28 | 32 | * |
@@ -56,14 +60,28 @@ public Service oauthCallbackService() { |
56 | 60 | @Bean |
57 | 61 | @ConditionalOnMissingBean(name = "oauthServiceRegistryExecutionPlanConfigurer") |
58 | 62 | 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 |
59 | 76 | return plan -> { |
60 | 77 | val service = new RegexRegisteredService(); |
61 | | - service.setId(RandomUtils.nextLong()); |
| 78 | + service.setId(983450982340993434L); |
62 | 79 | service.setEvaluationOrder(Ordered.HIGHEST_PRECEDENCE); |
63 | | - service.setName(service.getClass().getSimpleName()); |
| 80 | + service.setName("OSF Authorization"); |
64 | 81 | service.setDescription("OAuth Authentication Callback Request URL"); |
65 | 82 | service.setServiceId(oauthCallbackService().getId()); |
66 | | - service.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy()); |
| 83 | + service.setAccessStrategy(accessStrategy); |
| 84 | + service.setAttributeReleasePolicy(new ReturnAllowedAttributeReleasePolicy(new ArrayList<>())); |
67 | 85 | plan.registerServiceRegistry(new OAuth20ServiceRegistry(applicationContext, service)); |
68 | 86 | }; |
69 | 87 | } |
|
0 commit comments