Skip to content

Commit

Permalink
use-authorization-manager defaults to true
Browse files Browse the repository at this point in the history
  • Loading branch information
jzheaux committed Oct 6, 2022
1 parent 1aa3f14 commit 12b9f2e
Show file tree
Hide file tree
Showing 162 changed files with 191 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,15 @@ private void createRequestCacheFilter() {
}

private void createFilterSecurity(BeanReference authManager) {
boolean useAuthorizationManager = Boolean.parseBoolean(this.httpElt.getAttribute(ATT_USE_AUTHORIZATION_MGR));
if (useAuthorizationManager) {
if (StringUtils.hasText(this.httpElt.getAttribute(ATT_AUTHORIZATION_MGR))) {
createAuthorizationFilter();
return;
}
if (StringUtils.hasText(this.httpElt.getAttribute(ATT_AUTHORIZATION_MGR))) {
boolean useAuthorizationManager = true;
if (StringUtils.hasText(this.httpElt.getAttribute(ATT_USE_AUTHORIZATION_MGR))) {
useAuthorizationManager = Boolean.parseBoolean(this.httpElt.getAttribute(ATT_USE_AUTHORIZATION_MGR));
}
if (useAuthorizationManager) {
createAuthorizationFilter();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ protected BeanDefinition createInterceptorDefinition(Node node) {

boolean supports(Node node) {
Element interceptMethodsElt = (Element) node;
if (Boolean.parseBoolean(interceptMethodsElt.getAttribute(ATT_USE_AUTHORIZATION_MGR))) {
if (StringUtils.hasText(interceptMethodsElt.getAttribute(ATT_AUTHORIZATION_MGR))) {
return true;
}
return StringUtils.hasText(interceptMethodsElt.getAttribute(ATT_AUTHORIZATION_MGR));
if (StringUtils.hasText(interceptMethodsElt.getAttribute(ATT_USE_AUTHORIZATION_MGR))) {
return Boolean.parseBoolean(interceptMethodsElt.getAttribute(ATT_USE_AUTHORIZATION_MGR));
}
return true;
}

private Pointcut pointcut(Element interceptorElt, Element protectElt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
}

private String parseAuthorization(Element element, ParserContext parserContext) {
boolean useAuthorizationManager = Boolean.parseBoolean(element.getAttribute(USE_AUTHORIZATION_MANAGER_ATTR));
boolean useAuthorizationManager = true;
if (StringUtils.hasText(element.getAttribute(USE_AUTHORIZATION_MANAGER_ATTR))) {
useAuthorizationManager = Boolean.parseBoolean(element.getAttribute(USE_AUTHORIZATION_MANAGER_ATTR));
}
if (useAuthorizationManager) {
return parseAuthorizationManager(element, parserContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ intercept-methods.attlist &=
## Optional AccessDecisionManager bean ID to be used by the created method security interceptor.
attribute access-decision-manager-ref {xsd:token}?
intercept-methods.attlist &=
## Use the AuthorizationManager API instead of AccessDecisionManager (defaults to false)
## Use the AuthorizationManager API instead of AccessDecisionManager (defaults to true)
attribute use-authorization-manager {xsd:boolean}?
intercept-methods.attlist &=
## Use this AuthorizationManager instead of the default (supercedes use-authorization-manager)
Expand Down Expand Up @@ -306,7 +306,7 @@ websocket-message-broker.attrlist &=
## Use this AuthorizationManager instead of deriving one from <intercept-message> elements
attribute authorization-manager-ref {xsd:string}?
websocket-message-broker.attrlist &=
## Use AuthorizationManager API instead of SecurityMetadatasource
## Use AuthorizationManager API instead of SecurityMetadatasource (defaults to true)
attribute use-authorization-manager {xsd:boolean}?
websocket-message-broker.attrlist &=
## Use this SecurityContextHolderStrategy (note only supported in conjunction with the AuthorizationManager API)
Expand Down Expand Up @@ -368,7 +368,7 @@ http.attlist &=
## If available, runs the request as the Subject acquired from the JaasAuthenticationToken. Defaults to "false".
attribute jaas-api-provision {xsd:boolean}?
http.attlist &=
## Use AuthorizationManager API instead of SecurityMetadataSource
## Use AuthorizationManager API instead of SecurityMetadataSource (defaults to true)
attribute use-authorization-manager {xsd:boolean}?
http.attlist &=
## Use this AuthorizationManager instead of deriving one from <intercept-url> elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
</xs:attribute>
<xs:attribute name="use-authorization-manager" type="xs:boolean">
<xs:annotation>
<xs:documentation>Use the AuthorizationManager API instead of AccessDecisionManager (defaults to false)
<xs:documentation>Use the AuthorizationManager API instead of AccessDecisionManager (defaults to true)
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down Expand Up @@ -967,7 +967,7 @@
</xs:attribute>
<xs:attribute name="use-authorization-manager" type="xs:boolean">
<xs:annotation>
<xs:documentation>Use AuthorizationManager API instead of SecurityMetadatasource
<xs:documentation>Use AuthorizationManager API instead of SecurityMetadatasource (defaults to true)
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down Expand Up @@ -1325,7 +1325,7 @@
</xs:attribute>
<xs:attribute name="use-authorization-manager" type="xs:boolean">
<xs:annotation>
<xs:documentation>Use AuthorizationManager API instead of SecurityMetadataSource
<xs:documentation>Use AuthorizationManager API instead of SecurityMetadataSource (defaults to true)
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void interceptUrlsSupportPropertyPlaceholders() {
public void parsingWithinFilterSecurityInterceptorIsSuccessful() {
// @formatter:off
setContext("<b:bean class=\"org.springframework.web.servlet.handler.HandlerMappingIntrospector\" name=\"mvcHandlerMappingIntrospector\"/>" +
"<http auto-config='true' use-expressions='false'/>"
"<http auto-config='true' use-expressions='false' use-authorization-manager='false'/>"
+ "<b:bean id='fsi' class='org.springframework.security.web.access.intercept.FilterSecurityInterceptor' autowire='byType'>"
+ " <b:property name='securityMetadataSource'>"
+ " <filter-security-metadata-source use-expressions='false'>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.access.ExceptionTranslationFilter;
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
import org.springframework.security.web.access.intercept.AuthorizationFilter;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
Expand Down Expand Up @@ -849,8 +850,7 @@ private void assertThatFiltersMatchExpectedAutoConfigList(String url) {
assertThat(filters.next()).isInstanceOf(SecurityContextHolderAwareRequestFilter.class);
assertThat(filters.next()).isInstanceOf(AnonymousAuthenticationFilter.class);
assertThat(filters.next()).isInstanceOf(ExceptionTranslationFilter.class);
assertThat(filters.next()).isInstanceOf(FilterSecurityInterceptor.class)
.hasFieldOrPropertyWithValue("observeOncePerRequest", false);
assertThat(filters.next()).isInstanceOf(AuthorizationFilter.class);
}

private <T extends Filter> T getFilter(Class<T> filterClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void httpBasicWithPasswordEncoder() throws Exception {
@Test
public void httpBasicCustomSecurityContextHolderStrategy() throws Exception {
// @formatter:off
loadContext("<http auto-config=\"true\" use-expressions=\"false\" security-context-holder-strategy-ref=\"ref\"/>\n"
loadContext("<http auto-config=\"true\" use-expressions=\"false\" security-context-holder-strategy-ref=\"ref\" use-authorization-manager=\"false\"/>\n"
+ "<authentication-manager id=\"authenticationManager\">\n"
+ " <authentication-provider>\n"
+ " <user-service>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<http-firewall ref="firewall"/>
<http auto-config="true"/>
<http auto-config="true">
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:import resource="CsrfConfigTests-shared-userservice.xml"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<http auto-config="true">
<csrf disabled="true"/>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:import resource="CsrfConfigTests-shared-userservice.xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<http-firewall ref="firewall"/>
<http auto-config="true">
<intercept-url pattern="/authenticated/**" access="authenticated"/>
<intercept-url pattern="/**" access="permitAll"/>
<csrf/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<csrf request-matcher-ref="requestMatcher"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<session-management invalid-session-url="/error/sessionError"/>
<csrf/>
</http>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<http auto-config="true">
<csrf request-handler-ref="requestHandler"/>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean id="requestHandler" class="org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<form-login login-page="/login"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<form-login login-page="/login"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<form-login default-target-url="noLeadingSlash"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<form-login login-page="noLeadingSlash"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login
default-target-url="#{T(org.springframework.security.config.http.WebConfigUtilsTests).URL}/default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false" request-matcher="ant">
<http auto-config="true" use-expressions="false" request-matcher="ant" use-authorization-manager="false">
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login/>
</http>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<csrf disabled="true"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<csrf disabled="false"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false" security-context-holder-strategy-ref="ref">
<http auto-config="true" security-context-holder-strategy-ref="ref">
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean id="ref" class="org.mockito.Mockito" factory-method="spy">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login always-use-default-target="true" default-target-url="/default"/>
</http>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false" request-matcher="ant">
<http auto-config="true" use-expressions="false" request-matcher="ant" use-authorization-manager="false">
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login authentication-success-handler-ref="fsh" authentication-failure-handler-ref="fsh"/>
</http>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<form-login username-parameter="xname" password-parameter="xpass"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<intercept-url pattern="/**" access="ROLE_USER"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-authorization-manager="true">
<http auto-config="true">
<intercept-url pattern="/**" access="hasRole('USER')"/>
</http>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
https://www.springframework.org/schema/beans/spring-beans.xsd">


<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<cors/>
</http>
</b:beans>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<headers>
<cache-control disabled="true"/>
</headers>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<headers>
<content-security-policy policy-directives=""/>
</headers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<headers>
<content-security-policy policy-directives="default-src 'self'"/>
</headers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true" use-expressions="false">
<http auto-config="true" use-expressions="false" use-authorization-manager="false">
<headers>
<content-security-policy
policy-directives="default-src https:; report-uri https://example.org/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<headers>
<content-type-options disabled="true"/>
</headers>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<http auto-config="true"/>
<http auto-config="true">
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<headers defaults-disabled="true">
<cache-control/>
</headers>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<headers defaults-disabled="true">
<content-security-policy policy-directives="default-src 'self'"/>
</headers>
<intercept-url pattern="/**" access="permitAll"/>
</http>

<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>
Expand Down
Loading

0 comments on commit 12b9f2e

Please sign in to comment.