Skip to content

Commit c67ff42

Browse files
author
Rob Winch
committed
SEC-2783: XML Configuration Defaults Should Match JavaConfig
* j_username -> username * j_password -> password * j_spring_security_check -> login * j_spring_cas_security_check -> login/cas * j_spring_cas_security_proxyreceptor -> login/cas/proxyreceptor * j_spring_openid_security_login -> login/openid * j_spring_security_switch_user -> login/impersonate * j_spring_security_exit_user -> logout/impersonate * login_error -> error * use-expressions=true by default
1 parent b56e5ed commit c67ff42

File tree

125 files changed

+8122
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+8122
-395
lines changed

cas/src/main/java/org/springframework/security/cas/ServiceProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void afterPropertiesSet() throws Exception {
6060
* This service is the callback URL belonging to the local Spring Security System for Spring secured application.
6161
* For example,
6262
* <pre>
63-
* https://www.mycompany.com/application/j_spring_cas_security_check
63+
* https://www.mycompany.com/application/login/cas
6464
* </pre>
6565
*
6666
* @return the URL of the service the user is authenticating to

cas/src/main/java/org/springframework/security/cas/web/CasAuthenticationFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* presented in the <code>ticket</code> request parameter.
5252
* <p>
5353
* This filter monitors the <code>service</code> URL so it can
54-
* receive the service ticket and process it. By default this filter processes the URL <tt>/j_spring_cas_security_check</tt>.
54+
* receive the service ticket and process it. By default this filter processes the URL <tt>/login/cas</tt>.
5555
* When processing this URL, the value of {@link ServiceProperties#getService()} is used as the <tt>service</tt> when validating
5656
* the <code>ticket</code>. This means that it is important that {@link ServiceProperties#getService()} specifies the same value
5757
* as the <tt>filterProcessesUrl</tt>.
@@ -92,7 +92,7 @@
9292
* <pre>
9393
* &lt;b:bean id=&quot;serviceProperties&quot;
9494
* class=&quot;org.springframework.security.cas.ServiceProperties&quot;
95-
* p:service=&quot;https://service.example.com/cas-sample/j_spring_cas_security_check&quot;
95+
* p:service=&quot;https://service.example.com/cas-sample/login/cas&quot;
9696
* p:authenticateAllArtifacts=&quot;true&quot;/&gt;
9797
* &lt;b:bean id=&quot;casEntryPoint&quot;
9898
* class=&quot;org.springframework.security.cas.web.CasAuthenticationEntryPoint&quot;
@@ -102,7 +102,7 @@
102102
* p:authenticationManager-ref=&quot;authManager&quot;
103103
* p:serviceProperties-ref=&quot;serviceProperties&quot;
104104
* p:proxyGrantingTicketStorage-ref=&quot;pgtStorage&quot;
105-
* p:proxyReceptorUrl=&quot;/j_spring_cas_security_proxyreceptor&quot;&gt;
105+
* p:proxyReceptorUrl=&quot;/login/cas/proxyreceptor&quot;&gt;
106106
* &lt;b:property name=&quot;authenticationDetailsSource&quot;&gt;
107107
* &lt;b:bean class=&quot;org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource&quot;/&gt;
108108
* &lt;/b:property&gt;
@@ -129,7 +129,7 @@
129129
* &lt;b:bean
130130
* class=&quot;org.jasig.cas.client.validation.Cas20ProxyTicketValidator&quot;
131131
* p:acceptAnyProxy=&quot;true&quot;
132-
* p:proxyCallbackUrl=&quot;https://service.example.com/cas-sample/j_spring_cas_security_proxyreceptor&quot;
132+
* p:proxyCallbackUrl=&quot;https://service.example.com/cas-sample/login/cas/proxyreceptor&quot;
133133
* p:proxyGrantingTicketStorage-ref=&quot;pgtStorage&quot;&gt;
134134
* &lt;b:constructor-arg value=&quot;https://login.example.org/cas&quot; /&gt;
135135
* &lt;/b:bean&gt;
@@ -188,7 +188,7 @@ public class CasAuthenticationFilter extends AbstractAuthenticationProcessingFil
188188
//~ Constructors ===================================================================================================
189189

190190
public CasAuthenticationFilter() {
191-
super("/j_spring_cas_security_check");
191+
super("/login/cas");
192192
setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler());
193193
}
194194

cas/src/main/java/org/springframework/security/cas/web/authentication/DefaultServiceAuthenticationDetails.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2011 the original author or authors.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -135,7 +135,7 @@ static Pattern createArtifactPattern(String artifactParameterName) {
135135

136136
/**
137137
* Gets the port from the casServiceURL ensuring to return the proper value if the default port is being used.
138-
* @param casServiceUrl the casServerUrl to be used (i.e. "https://example.com/context/j_spring_security_cas_check")
138+
* @param casServiceUrl the casServerUrl to be used (i.e. "https://example.com/context/login/cas")
139139
* @return the port that is configured for the casServerUrl
140140
*/
141141
private static int getServicePort(URL casServiceUrl) {

cas/src/test/java/org/springframework/security/cas/authentication/AbstractStatelessTicketCacheTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class AbstractStatelessTicketCacheTests {
1919

2020
protected CasAuthenticationToken getToken() {
2121
List<String> proxyList = new ArrayList<String>();
22-
proxyList.add("https://localhost/newPortal/j_spring_cas_security_check");
22+
proxyList.add("https://localhost/newPortal/login/cas");
2323

2424
User user = new User("rod", "password", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
2525
final Assertion assertion = new AssertionImpl("rod");

cas/src/test/java/org/springframework/security/cas/web/CasAuthenticationEntryPointTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testGettersSetters() {
6969
public void testNormalOperationWithRenewFalse() throws Exception {
7070
ServiceProperties sp = new ServiceProperties();
7171
sp.setSendRenew(false);
72-
sp.setService("https://mycompany.com/bigWebApp/j_spring_cas_security_check");
72+
sp.setService("https://mycompany.com/bigWebApp/login/cas");
7373

7474
CasAuthenticationEntryPoint ep = new CasAuthenticationEntryPoint();
7575
ep.setLoginUrl("https://cas/login");
@@ -84,14 +84,14 @@ public void testNormalOperationWithRenewFalse() throws Exception {
8484
ep.commence(request, response, null);
8585

8686
assertEquals("https://cas/login?service="
87-
+ URLEncoder.encode("https://mycompany.com/bigWebApp/j_spring_cas_security_check", "UTF-8"),
87+
+ URLEncoder.encode("https://mycompany.com/bigWebApp/login/cas", "UTF-8"),
8888
response.getRedirectedUrl());
8989
}
9090

9191
public void testNormalOperationWithRenewTrue() throws Exception {
9292
ServiceProperties sp = new ServiceProperties();
9393
sp.setSendRenew(true);
94-
sp.setService("https://mycompany.com/bigWebApp/j_spring_cas_security_check");
94+
sp.setService("https://mycompany.com/bigWebApp/login/cas");
9595

9696
CasAuthenticationEntryPoint ep = new CasAuthenticationEntryPoint();
9797
ep.setLoginUrl("https://cas/login");
@@ -105,7 +105,7 @@ public void testNormalOperationWithRenewTrue() throws Exception {
105105
ep.afterPropertiesSet();
106106
ep.commence(request, response, null);
107107
assertEquals("https://cas/login?service="
108-
+ URLEncoder.encode("https://mycompany.com/bigWebApp/j_spring_cas_security_check", "UTF-8") + "&renew=true",
108+
+ URLEncoder.encode("https://mycompany.com/bigWebApp/login/cas", "UTF-8") + "&renew=true",
109109
response.getRedirectedUrl());
110110
}
111111
}

cas/src/test/java/org/springframework/security/cas/web/CasAuthenticationFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testGettersSetters() {
7171
@Test
7272
public void testNormalOperation() throws Exception {
7373
MockHttpServletRequest request = new MockHttpServletRequest();
74-
request.setServletPath("/j_spring_cas_security_check");
74+
request.setServletPath("/login/cas");
7575
request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
7676

7777
CasAuthenticationFilter filter = new CasAuthenticationFilter();

config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ public AnonymousConfigurer<HttpSecurity> anonymous() throws Exception {
948948
* .antMatchers(&quot;/**&quot;).hasRole(&quot;USER&quot;)
949949
* .and()
950950
* .formLogin()
951-
* .usernameParameter("j_username") // default is username
952-
* .passwordParameter("j_password") // default is password
951+
* .usernameParameter("username") // default is username
952+
* .passwordParameter("password") // default is password
953953
* .loginPage("/authentication/login") // default is /login with an HTTP get
954954
* .failureUrl("/authentication/login?failed") // default is /login?error
955955
* .loginProcessingUrl("/authentication/login/process"); // default is /login with an HTTP post

config/src/main/java/org/springframework/security/config/authentication/AuthenticationManagerFactoryBean.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
import org.springframework.beans.factory.FactoryBean;
77
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
88
import org.springframework.security.authentication.AuthenticationManager;
9+
import org.springframework.security.authentication.AuthenticationProvider;
910
import org.springframework.security.authentication.ProviderManager;
11+
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
1012
import org.springframework.security.config.BeanIds;
13+
import org.springframework.security.core.userdetails.UserDetailsService;
14+
15+
import java.util.Arrays;
1116

1217
/**
1318
* Factory bean for the namespace AuthenticationManager, which allows a more meaningful error message
@@ -28,6 +33,13 @@ public AuthenticationManager getObject() throws Exception {
2833
return (AuthenticationManager) bf.getBean(BeanIds.AUTHENTICATION_MANAGER);
2934
} catch (NoSuchBeanDefinitionException e) {
3035
if (BeanIds.AUTHENTICATION_MANAGER.equals(e.getBeanName())) {
36+
try {
37+
UserDetailsService uds = bf.getBean(UserDetailsService.class);
38+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
39+
provider.setUserDetailsService(uds);
40+
provider.afterPropertiesSet();
41+
return new ProviderManager(Arrays.<AuthenticationProvider>asList(provider));
42+
} catch(NoSuchBeanDefinitionException noUds) {}
3143
throw new NoSuchBeanDefinitionException(BeanIds.AUTHENTICATION_MANAGER, MISSING_BEAN_ERROR_MESSAGE);
3244
}
3345
throw e;

config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ final class AuthenticationConfigBuilder {
130130
private String loginProcessingUrl;
131131
private String openidLoginProcessingUrl;
132132

133-
public AuthenticationConfigBuilder(Element element, ParserContext pc, SessionCreationPolicy sessionPolicy,
133+
public AuthenticationConfigBuilder(Element element, boolean forceAutoConfig, ParserContext pc, SessionCreationPolicy sessionPolicy,
134134
BeanReference requestCache, BeanReference authenticationManager, BeanReference sessionStrategy, BeanReference portMapper, BeanReference portResolver, BeanMetadataElement csrfLogoutHandler) {
135135
this.httpElt = element;
136136
this.pc = pc;
137137
this.requestCache = requestCache;
138-
autoConfig = "true".equals(element.getAttribute(ATT_AUTO_CONFIG));
138+
autoConfig = forceAutoConfig | "true".equals(element.getAttribute(ATT_AUTO_CONFIG));
139139
this.allowSessionCreation = sessionPolicy != SessionCreationPolicy.NEVER
140140
&& sessionPolicy != SessionCreationPolicy.STATELESS;
141141
this.portMapper = portMapper;
@@ -193,7 +193,7 @@ void createFormLoginFilter(BeanReference sessionStrategy, BeanReference authMana
193193
RootBeanDefinition formFilter = null;
194194

195195
if (formLoginElt != null || autoConfig) {
196-
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/j_spring_security_check",
196+
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/login", "POST",
197197
AUTHENTICATION_PROCESSING_FILTER_CLASS, requestCache, sessionStrategy, allowSessionCreation, portMapper, portResolver);
198198

199199
parser.parse(formLoginElt, pc);
@@ -218,7 +218,7 @@ void createOpenIDLoginFilter(BeanReference sessionStrategy, BeanReference authMa
218218
RootBeanDefinition openIDFilter = null;
219219

220220
if (openIDLoginElt != null) {
221-
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/j_spring_openid_security_check",
221+
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/login/openid", null,
222222
OPEN_ID_AUTHENTICATION_PROCESSING_FILTER_CLASS, requestCache, sessionStrategy, allowSessionCreation, portMapper, portResolver);
223223

224224
parser.parse(openIDLoginElt, pc);
@@ -492,7 +492,11 @@ void createLoginPageFilterIfNeeded() {
492492
void createLogoutFilter() {
493493
Element logoutElt = DomUtils.getChildElementByTagName(httpElt, Elements.LOGOUT);
494494
if (logoutElt != null || autoConfig) {
495-
LogoutBeanDefinitionParser logoutParser = new LogoutBeanDefinitionParser(rememberMeServicesId, csrfLogoutHandler);
495+
String formLoginPage = getLoginFormUrl(formEntryPoint);
496+
if(formLoginPage == null) {
497+
formLoginPage = DefaultLoginPageGeneratingFilter.DEFAULT_LOGIN_PAGE_URL;
498+
}
499+
LogoutBeanDefinitionParser logoutParser = new LogoutBeanDefinitionParser(formLoginPage,rememberMeServicesId, csrfLogoutHandler);
496500
logoutFilter = logoutParser.parse(logoutElt, pc);
497501
logoutHandlers = logoutParser.getLogoutHandlers();
498502
}

config/src/main/java/org/springframework/security/config/http/FilterInvocationSecurityMetadataSourceParser.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
4848
}
4949
}
5050

51-
BeanDefinition mds = createSecurityMetadataSource(interceptUrls, element, parserContext);
51+
BeanDefinition mds = createSecurityMetadataSource(interceptUrls, false, element, parserContext);
5252

5353
String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
5454

@@ -60,16 +60,16 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
6060
return mds;
6161
}
6262

63-
static RootBeanDefinition createSecurityMetadataSource(List<Element> interceptUrls, Element elt, ParserContext pc) {
64-
MatcherType matcherType = MatcherType.fromElement(elt);
65-
boolean useExpressions = isUseExpressions(elt);
63+
static RootBeanDefinition createSecurityMetadataSource(List<Element> interceptUrls, boolean addAllAuth, Element httpElt, ParserContext pc) {
64+
MatcherType matcherType = MatcherType.fromElement(httpElt);
65+
boolean useExpressions = isUseExpressions(httpElt);
6666

6767
ManagedMap<BeanDefinition, BeanDefinition> requestToAttributesMap = parseInterceptUrlsForFilterInvocationRequestMap(
68-
matcherType, interceptUrls, useExpressions, pc);
68+
matcherType, interceptUrls, useExpressions, addAllAuth, pc);
6969
BeanDefinitionBuilder fidsBuilder;
7070

7171
if (useExpressions) {
72-
Element expressionHandlerElt = DomUtils.getChildElementByTagName(elt, Elements.EXPRESSION_HANDLER);
72+
Element expressionHandlerElt = DomUtils.getChildElementByTagName(httpElt, Elements.EXPRESSION_HANDLER);
7373
String expressionHandlerRef = expressionHandlerElt == null ? null : expressionHandlerElt.getAttribute("ref");
7474

7575
if (StringUtils.hasText(expressionHandlerRef)) {
@@ -86,7 +86,7 @@ static RootBeanDefinition createSecurityMetadataSource(List<Element> interceptUr
8686
fidsBuilder.addConstructorArgValue(requestToAttributesMap);
8787
}
8888

89-
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(elt));
89+
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(httpElt));
9090

9191
return (RootBeanDefinition) fidsBuilder.getBeanDefinition();
9292
}
@@ -100,12 +100,13 @@ static String registerDefaultExpressionHandler(ParserContext pc) {
100100
}
101101

102102
static boolean isUseExpressions(Element elt) {
103-
return "true".equals(elt.getAttribute(ATT_USE_EXPRESSIONS));
103+
String useExpressions = elt.getAttribute(ATT_USE_EXPRESSIONS);
104+
return !StringUtils.hasText(useExpressions) || "true".equals(useExpressions);
104105
}
105106

106107
private static ManagedMap<BeanDefinition, BeanDefinition>
107108
parseInterceptUrlsForFilterInvocationRequestMap(MatcherType matcherType,
108-
List<Element> urlElts, boolean useExpressions, ParserContext parserContext) {
109+
List<Element> urlElts, boolean useExpressions, boolean addAuthenticatedAll, ParserContext parserContext) {
109110

110111
ManagedMap<BeanDefinition, BeanDefinition> filterInvocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
111112

@@ -147,6 +148,15 @@ static boolean isUseExpressions(Element elt) {
147148
filterInvocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
148149
}
149150

151+
if(addAuthenticatedAll && filterInvocationDefinitionMap.isEmpty()) {
152+
153+
BeanDefinition matcher = matcherType.createMatcher("/**", null);
154+
BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
155+
attributeBuilder.addConstructorArgValue(new String[] { "authenticated" });
156+
attributeBuilder.setFactoryMethod("createList");
157+
filterInvocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
158+
}
159+
150160
return filterInvocationDefinitionMap;
151161
}
152162

config/src/main/java/org/springframework/security/config/http/FormLoginBeanDefinitionParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ public class FormLoginBeanDefinitionParser {
6666
private RootBeanDefinition filterBean;
6767
private RootBeanDefinition entryPointBean;
6868
private String loginPage;
69+
private String loginMethod;
6970
private String loginProcessingUrl;
7071

71-
FormLoginBeanDefinitionParser(String defaultLoginProcessingUrl, String filterClassName,
72+
FormLoginBeanDefinitionParser(String defaultLoginProcessingUrl, String loginMethod, String filterClassName,
7273
BeanReference requestCache, BeanReference sessionStrategy, boolean allowSessionCreation, BeanReference portMapper, BeanReference portResolver) {
7374
this.defaultLoginProcessingUrl = defaultLoginProcessingUrl;
75+
this.loginMethod = loginMethod;
7476
this.filterClassName = filterClassName;
7577
this.requestCache = requestCache;
7678
this.sessionStrategy = sessionStrategy;
@@ -153,6 +155,9 @@ private RootBeanDefinition createFilterBean(String loginUrl, String defaultTarge
153155

154156
BeanDefinitionBuilder matcherBuilder = BeanDefinitionBuilder.rootBeanDefinition("org.springframework.security.web.util.matcher.AntPathRequestMatcher");
155157
matcherBuilder.addConstructorArgValue(loginUrl);
158+
if(loginMethod != null) {
159+
matcherBuilder.addConstructorArgValue("POST");
160+
}
156161

157162
filterBuilder.addPropertyValue("requiresAuthenticationRequestMatcher", matcherBuilder.getBeanDefinition());
158163

config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ class HttpConfigurationBuilder {
133133
private CsrfBeanDefinitionParser csrfParser;
134134

135135
private BeanDefinition invalidSession;
136+
private boolean addAllAuth;
136137

137-
public HttpConfigurationBuilder(Element element, ParserContext pc,
138+
public HttpConfigurationBuilder(Element element, boolean addAllAuth, ParserContext pc,
138139
BeanReference portMapper, BeanReference portResolver, BeanReference authenticationManager) {
139140
this.httpElt = element;
141+
this.addAllAuth = addAllAuth;
140142
this.pc = pc;
141143
this.portMapper = portMapper;
142144
this.portResolver = portResolver;
@@ -583,7 +585,7 @@ private void createRequestCacheFilter() {
583585

584586
private void createFilterSecurityInterceptor(BeanReference authManager) {
585587
boolean useExpressions = FilterInvocationSecurityMetadataSourceParser.isUseExpressions(httpElt);
586-
RootBeanDefinition securityMds = FilterInvocationSecurityMetadataSourceParser.createSecurityMetadataSource(interceptUrls, httpElt, pc);
588+
RootBeanDefinition securityMds = FilterInvocationSecurityMetadataSourceParser.createSecurityMetadataSource(interceptUrls, addAllAuth, httpElt, pc);
587589

588590
RootBeanDefinition accessDecisionMgr;
589591
ManagedList<BeanDefinition> voters = new ManagedList<BeanDefinition>(2);

0 commit comments

Comments
 (0)