-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish AuthorizeReturnObject SUpport
- Remove dependency on concrete implementation - Simplify AuthorizationAdvisorProxyFactory construction - Add ability to configure alternative proxying behaviors
- Loading branch information
Showing
12 changed files
with
683 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...urity/config/annotation/method/configuration/ReactiveAuthorizationProxyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.config.annotation.method.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
|
||
import org.springframework.aop.framework.AopInfrastructureBean; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Role; | ||
import org.springframework.security.authorization.AuthorizationProxyFactory; | ||
import org.springframework.security.authorization.AuthorizationProxyFactoryPredicate; | ||
import org.springframework.security.authorization.ReactiveAuthorizationAdvisorProxyFactory; | ||
import org.springframework.security.authorization.method.AuthorizationAdvisor; | ||
import org.springframework.security.authorization.method.AuthorizationProxyMethodInterceptor; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
final class ReactiveAuthorizationProxyConfiguration implements AopInfrastructureBean { | ||
|
||
@Bean | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) | ||
static DelegatingAuthorizationProxyFactory authorizationProxyFactory(ObjectProvider<AuthorizationAdvisor> provider, | ||
List<AuthorizationProxyFactoryPredicate> predicates) { | ||
DelegatingAuthorizationProxyFactory delegating = new DelegatingAuthorizationProxyFactory(predicates); | ||
List<AuthorizationAdvisor> advisors = new ArrayList<>(); | ||
provider.forEach(advisors::add); | ||
delegating.defaults.setAdvisors(advisors); | ||
return delegating; | ||
} | ||
|
||
@Bean | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) | ||
static MethodInterceptor authorizationProxyMethodInterceptor(ObjectProvider<AuthorizationAdvisor> provider, | ||
DelegatingAuthorizationProxyFactory authorizationProxyFactory) { | ||
AuthorizationProxyMethodInterceptor interceptor = new AuthorizationProxyMethodInterceptor( | ||
authorizationProxyFactory); | ||
List<AuthorizationAdvisor> advisors = new ArrayList<>(); | ||
provider.forEach(advisors::add); | ||
advisors.add(interceptor); | ||
authorizationProxyFactory.defaults.setAdvisors(advisors); | ||
return interceptor; | ||
} | ||
|
||
private static class DelegatingAuthorizationProxyFactory implements AuthorizationProxyFactory { | ||
|
||
private final List<AuthorizationProxyFactoryPredicate> predicates; | ||
|
||
private final ReactiveAuthorizationAdvisorProxyFactory defaults = new ReactiveAuthorizationAdvisorProxyFactory(); | ||
|
||
DelegatingAuthorizationProxyFactory(List<AuthorizationProxyFactoryPredicate> predicates) { | ||
this.predicates = new ArrayList<>(predicates); | ||
} | ||
|
||
@Override | ||
public Object proxy(Object object) { | ||
for (AuthorizationProxyFactoryPredicate factory : this.predicates) { | ||
if (factory.proxies(object)) { | ||
return factory.proxy(object); | ||
} | ||
} | ||
return this.defaults.proxy(object); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.