├── .gitignore
├── README.adoc
├── build.gradle
├── gradle.properties
├── gradle
├── asciidoc.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jc
├── build.gradle
├── spring-security-3-jc
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ ├── AppInitializer.java
│ │ │ │ ├── HelloWorldMessageService.java
│ │ │ │ ├── MessageService.java
│ │ │ │ ├── SecurityConfig.java
│ │ │ │ ├── SecurityInitializer.java
│ │ │ │ └── mvc
│ │ │ │ ├── AuthenticationPrincipalController.java
│ │ │ │ ├── HomeController.java
│ │ │ │ ├── LoginController.java
│ │ │ │ └── MvcConfig.java
│ │ ├── resources
│ │ │ └── log4j.xml
│ │ └── webapp
│ │ │ └── WEB-INF
│ │ │ └── views
│ │ │ ├── home.jsp
│ │ │ └── login.jsp
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ ├── acl
│ │ ├── AclImplTests.java
│ │ └── EhCacheBasedAclCacheTests.java
│ │ ├── cas
│ │ ├── CasAuthenticationFilterDefaultUrlsTests.java
│ │ └── ServiceAuthenticationDetailsSourceTests.java
│ │ ├── config
│ │ └── HeadersTests.java
│ │ ├── core
│ │ ├── AbstractAccessDecisionManagerTests.java
│ │ ├── AnonymousAuthenticationProviderTests.java
│ │ ├── AuthenticationDetailsSourceImplTests.java
│ │ ├── AuthenticationExceptionTests.java
│ │ ├── CustomWebAuthenticationDetails.java
│ │ ├── GrantedAuthorityImplTests.java
│ │ ├── InMemoryDaoImplTests.java
│ │ ├── ProviderManagerTests.java
│ │ ├── RememberMeAuthenticationProviderTests.java
│ │ ├── SecurityConfigTests.java
│ │ ├── UserDetailsServiceWrapperTests.java
│ │ └── UserDetailsWrapperTests.java
│ │ ├── openid
│ │ └── OpenID4JavaConsumerTests.java
│ │ ├── role_
│ │ ├── HelloWorldMessageService.java
│ │ ├── MessageService.java
│ │ └── RolePrefixTests.java
│ │ └── web
│ │ ├── AbstractAuthenticationProcessingFilterTests.java
│ │ ├── AbstractRememberMeServicesTests.java
│ │ ├── AnonymousAuthenticationFilterTests.java
│ │ ├── AuthenticationPrincipalTests.java
│ │ ├── BasicAuthenticationFilterTests.java
│ │ ├── ConcurrentSessionControlStrategyTests.java
│ │ ├── ConcurrentSessionFilterTests.java
│ │ ├── ExceptionTranslationFilterTests.java
│ │ ├── FilterChainProxyTests.java
│ │ ├── LoginUrlAuthenticationEntryPointTests.java
│ │ ├── LogoutFilterTests.java
│ │ ├── PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests.java
│ │ ├── RememberMeAuthenticationFilterTests.java
│ │ ├── RequestCacheAwareFilterTests.java
│ │ ├── RequestMatcherTests.java
│ │ ├── SecurityContextPersistenceFilterTests.java
│ │ ├── SessionFixationProtectionStrategyTests.java
│ │ ├── SessionManagementFilterTests.java
│ │ ├── SwitchUserFilterTests.java
│ │ └── WebSecurityExpressionHandlerTests.java
├── spring-security-4-jc
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ ├── AppInitializer.java
│ │ │ │ ├── HelloWorldMessageService.java
│ │ │ │ ├── MessageService.java
│ │ │ │ ├── SecurityConfig.java
│ │ │ │ ├── SecurityInitializer.java
│ │ │ │ └── mvc
│ │ │ │ ├── AuthenticationPrincipalController.java
│ │ │ │ ├── HomeController.java
│ │ │ │ ├── LoginController.java
│ │ │ │ └── MvcConfig.java
│ │ ├── resources
│ │ │ └── log4j.xml
│ │ └── webapp
│ │ │ └── WEB-INF
│ │ │ └── views
│ │ │ ├── home.jsp
│ │ │ └── login.jsp
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ ├── acl
│ │ ├── AclImplTests.java
│ │ └── EhCacheBasedAclCacheTests.java
│ │ ├── cas
│ │ ├── CasAuthenticationFilterDefaultUrlsTests.java
│ │ └── ServiceAuthenticationDetailsSourceTests.java
│ │ ├── config
│ │ └── HeadersTests.java
│ │ ├── core
│ │ ├── AbstractAccessDecisionManagerTests.java
│ │ ├── AnonymousAuthenticationProviderTests.java
│ │ ├── AuthenticationDetailsSourceImplTests.java
│ │ ├── AuthenticationExceptionTests.java
│ │ ├── CustomWebAuthenticationDetails.java
│ │ ├── GrantedAuthorityImplTests.java
│ │ ├── InMemoryDaoImplTests.java
│ │ ├── ProviderManagerTests.java
│ │ ├── RememberMeAuthenticationProviderTests.java
│ │ ├── SecurityConfigTests.java
│ │ ├── UserDetailsServiceWrapperTests.java
│ │ └── UserDetailsWrapperTests.java
│ │ ├── openid
│ │ └── OpenID4JavaConsumerTests.java
│ │ ├── role_
│ │ ├── DefaultRolesPrefixPostProcessor.java
│ │ ├── HelloWorldMessageService.java
│ │ ├── MessageService.java
│ │ └── RolePrefixTests.java
│ │ └── web
│ │ ├── AbstractAuthenticationProcessingFilterTests.java
│ │ ├── AbstractRememberMeServicesTests.java
│ │ ├── AnonymousAuthenticationFilterTests.java
│ │ ├── AuthenticationPrincipalTests.java
│ │ ├── BasicAuthenticationFilterTests.java
│ │ ├── ConcurrentSessionControlStrategyTests.java
│ │ ├── ConcurrentSessionFilterTests.java
│ │ ├── ExceptionTranslationFilterTests.java
│ │ ├── FilterChainProxyTests.java
│ │ ├── LoginUrlAuthenticationEntryPointTests.java
│ │ ├── LogoutFilterTests.java
│ │ ├── PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests.java
│ │ ├── RememberMeAuthenticationFilterTests.java
│ │ ├── RequestCacheAwareFilterTests.java
│ │ ├── RequestMatcherTests.java
│ │ ├── SecurityContextPersistenceFilterTests.java
│ │ ├── SessionFixationProtectionStrategyTests.java
│ │ ├── SessionManagementFilterTests.java
│ │ ├── SwitchUserFilterTests.java
│ │ └── WebSecurityExpressionHandlerTests.java
└── src
│ └── docs
│ └── asciidoc
│ └── migrate-3-to-4-jc.adoc
├── push-changes.sh
├── settings.gradle
└── xml
├── build.gradle
├── spring-security-3-xml
├── .gitignore
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── sample
│ │ │ ├── AuthenticationPrincipalController.java
│ │ │ ├── HelloWorldMessageService.java
│ │ │ ├── HomeController.java
│ │ │ ├── LoginController.java
│ │ │ └── MessageService.java
│ ├── resources
│ │ └── log4j.xml
│ └── webapp
│ │ └── WEB-INF
│ │ ├── spring
│ │ ├── mvc
│ │ │ └── servlet-context.xml
│ │ ├── root-context.xml
│ │ └── security.xml
│ │ ├── views
│ │ ├── home.jsp
│ │ └── login.jsp
│ │ └── web.xml
│ └── test
│ ├── java
│ └── sample
│ │ ├── SampleTests.java
│ │ ├── acl
│ │ ├── AclImplTests.java
│ │ └── EhCacheBasedAclCacheTests.java
│ │ ├── cas
│ │ ├── CasAuthenticationFilterDefaultUrlsTests.java
│ │ └── ServiceAuthenticationDetailsSourceTests.java
│ │ ├── config
│ │ ├── FilterChainMapPathTypeTests.java
│ │ ├── FilterInvocationDefinitionSourceTests.java
│ │ ├── FilterSecurityMetadataSourcePathTypeTests.java
│ │ ├── HeadersTests.java
│ │ ├── HttpAccessDeniedPageTests.java
│ │ └── HttpPathTypeTests.java
│ │ ├── core
│ │ ├── AbstractAccessDecisionManagerTests.java
│ │ ├── AnonymousAuthenticationProviderTests.java
│ │ ├── AuthenticationDetailsSourceImplTests.java
│ │ ├── AuthenticationExceptionTests.java
│ │ ├── CustomWebAuthenticationDetails.java
│ │ ├── GrantedAuthorityImplTests.java
│ │ ├── InMemoryDaoImplTests.java
│ │ ├── ProviderManagerTests.java
│ │ ├── RememberMeAuthenticationProviderTests.java
│ │ ├── SecurityConfigTests.java
│ │ ├── UserDetailsServiceWrapperTests.java
│ │ └── UserDetailsWrapperTests.java
│ │ ├── openid
│ │ ├── OpenID4JavaConsumerTests.java
│ │ └── OpenIDTests.java
│ │ ├── role_
│ │ ├── HelloWorldMessageService.java
│ │ ├── MessageService.java
│ │ └── RolePrefixTests.java
│ │ └── web
│ │ ├── AbstractAuthenticationProcessingFilterTests.java
│ │ ├── AbstractRememberMeServicesTests.java
│ │ ├── AnonymousAuthenticationFilterTests.java
│ │ ├── AuthenticationPrincipalTests.java
│ │ ├── BasicAuthenticationFilterTests.java
│ │ ├── ConcurrentSessionControlStrategyTests.java
│ │ ├── ConcurrentSessionFilterTests.java
│ │ ├── ExceptionTranslationFilterTests.java
│ │ ├── FilterChainProxyTests.java
│ │ ├── LoginUrlAuthenticationEntryPointTests.java
│ │ ├── LogoutFilterTests.java
│ │ ├── PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests.java
│ │ ├── RememberMeAuthenticationFilterTests.java
│ │ ├── RequestCacheAwareFilterTests.java
│ │ ├── RequestMatcherTests.java
│ │ ├── SecurityContextPersistenceFilterTests.java
│ │ ├── SessionFixationProtectionStrategyTests.java
│ │ ├── SessionManagementFilterTests.java
│ │ ├── SwitchUserFilterTests.java
│ │ └── WebSecurityExpressionHandlerTests.java
│ └── resources
│ ├── log4j.xml
│ └── sample
│ ├── cas
│ ├── CasAuthenticationFilterDefaultUrlsTests-context.xml
│ └── ServiceAuthenticationDetailsSourceTests-context.xml
│ ├── config
│ ├── FilterChainMapPathTypeTests-context.xml
│ ├── FilterInvocationDefinitionSourceTests-context.xml
│ ├── FilterSecurityMetadataSourcePathTypeTests-context.xml
│ ├── HeadersTests-context.xml
│ ├── HttpAccessDeniedPageTests-context.xml
│ └── HttpPathTypeTests-context.xml
│ ├── core
│ ├── AbstractAccessDecisionManagerTests-context.xml
│ ├── InMemoryDaoImplTests-context.xml
│ ├── ProviderManagerTests-context.xml
│ ├── RememberMeAuthenticationProviderTests-context.xml
│ └── UserDetailsServiceWrapperTests-context.xml
│ ├── openid
│ ├── OpenID4JavaConsumerTests-context.xml
│ └── OpenIDTests-context.xml
│ ├── role_
│ └── RolePrefixTests-context.xml
│ └── web
│ ├── AbstractRememberMeServicesTests-context.xml
│ ├── AnonymousAuthenticationFilterTests-context.xml
│ ├── AuthenticationPrincipalTests-context.xml
│ ├── BasicAuthenticationFilterTests-context.xml
│ ├── ConcurrentSessionControlStrategyTests-context.xml
│ ├── ConcurrentSessionFilterTests-context.xml
│ ├── ExceptionTranslationFilterTests-context.xml
│ ├── FilterChainProxyTests-context.xml
│ ├── LoginUrlAuthenticationEntryPointTests-context.xml
│ ├── LogoutFilterTests-context.xml
│ ├── RememberMeAuthenticationFilterTests-context.xml
│ ├── RequestCacheAwareFilterTests-context.xml
│ ├── RequestMatcherTests-context.xml
│ ├── SecurityContextPersistenceFilterTests-context.xml
│ ├── SessionManagementFilterTests-context.xml
│ ├── SwitchUserFilterTests-context.xml
│ └── WebSecurityExpressionHandlerTests-context.xml
├── spring-security-4-xml
├── .gitignore
├── build.gradle
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── sample
│ │ │ ├── AuthenticationPrincipalController.java
│ │ │ ├── HelloWorldMessageService.java
│ │ │ ├── HomeController.java
│ │ │ ├── LoginController.java
│ │ │ ├── MessageService.java
│ │ │ └── Sec2919PostProcessor.java
│ ├── resources
│ │ └── log4j.xml
│ └── webapp
│ │ └── WEB-INF
│ │ ├── spring
│ │ ├── mvc
│ │ │ └── servlet-context.xml
│ │ ├── root-context.xml
│ │ └── security.xml
│ │ ├── views
│ │ ├── home.jsp
│ │ └── login.jsp
│ │ └── web.xml
│ └── test
│ ├── java
│ └── sample
│ │ ├── SampleTests.java
│ │ ├── acl
│ │ ├── AclImplTests.java
│ │ └── EhCacheBasedAclCacheTests.java
│ │ ├── cas
│ │ ├── CasAuthenticationFilterDefaultUrlsTests.java
│ │ └── ServiceAuthenticationDetailsSourceTests.java
│ │ ├── config
│ │ ├── FilterChainMapPathTypeTests.java
│ │ ├── FilterInvocationDefinitionSourceTests.java
│ │ ├── FilterSecurityMetadataSourcePathTypeTests.java
│ │ ├── HeadersTests.java
│ │ ├── HttpAccessDeniedPageTests.java
│ │ └── HttpPathTypeTests.java
│ │ ├── core
│ │ ├── AbstractAccessDecisionManagerTests.java
│ │ ├── AnonymousAuthenticationProviderTests.java
│ │ ├── AuthenticationDetailsSourceImplTests.java
│ │ ├── AuthenticationExceptionTests.java
│ │ ├── CustomWebAuthenticationDetails.java
│ │ ├── GrantedAuthorityImplTests.java
│ │ ├── InMemoryDaoImplTests.java
│ │ ├── ProviderManagerTests.java
│ │ ├── RememberMeAuthenticationProviderTests.java
│ │ ├── SecurityConfigTests.java
│ │ ├── UserDetailsServiceWrapperTests.java
│ │ └── UserDetailsWrapperTests.java
│ │ ├── openid
│ │ ├── OpenID4JavaConsumerTests.java
│ │ └── OpenIDTests.java
│ │ ├── role_
│ │ ├── DefaultRolesPrefixPostProcessor.java
│ │ ├── HelloWorldMessageService.java
│ │ ├── MessageService.java
│ │ └── RolePrefixTests.java
│ │ └── web
│ │ ├── AbstractAuthenticationProcessingFilterTests.java
│ │ ├── AbstractRememberMeServicesTests.java
│ │ ├── AnonymousAuthenticationFilterTests.java
│ │ ├── AuthenticationPrincipalTests.java
│ │ ├── BasicAuthenticationFilterTests.java
│ │ ├── ConcurrentSessionControlStrategyTests.java
│ │ ├── ConcurrentSessionFilterTests.java
│ │ ├── ExceptionTranslationFilterTests.java
│ │ ├── FilterChainProxyTests.java
│ │ ├── LoginUrlAuthenticationEntryPointTests.java
│ │ ├── LogoutFilterTests.java
│ │ ├── PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests.java
│ │ ├── RememberMeAuthenticationFilterTests.java
│ │ ├── RequestCacheAwareFilterTests.java
│ │ ├── RequestMatcherTests.java
│ │ ├── SecurityContextPersistenceFilterTests.java
│ │ ├── SessionFixationProtectionStrategyTests.java
│ │ ├── SessionManagementFilterTests.java
│ │ ├── SwitchUserFilterTests.java
│ │ └── WebSecurityExpressionHandlerTests.java
│ └── resources
│ ├── log4j.xml
│ └── sample
│ ├── cas
│ ├── CasAuthenticationFilterDefaultUrlsTests-context.xml
│ └── ServiceAuthenticationDetailsSourceTests-context.xml
│ ├── config
│ ├── FilterChainMapPathTypeTests-context.xml
│ ├── FilterInvocationDefinitionSourceTests-context.xml
│ ├── FilterSecurityMetadataSourcePathTypeTests-context.xml
│ ├── HeadersTests-context.xml
│ ├── HttpAccessDeniedPageTests-context.xml
│ └── HttpPathTypeTests-context.xml
│ ├── core
│ ├── AbstractAccessDecisionManagerTests-context.xml
│ ├── InMemoryDaoImplTests-context.xml
│ ├── ProviderManagerTests-context.xml
│ ├── RememberMeAuthenticationProviderTests-context.xml
│ └── UserDetailsServiceWrapperTests-context.xml
│ ├── openid
│ ├── OpenID4JavaConsumerTests-context.xml
│ └── OpenIDTests-context.xml
│ ├── role_
│ └── RolePrefixTests-context.xml
│ └── web
│ ├── AbstractRememberMeServicesTests-context.xml
│ ├── AnonymousAuthenticationFilterTests-context.xml
│ ├── AuthenticationPrincipalTests-context.xml
│ ├── BasicAuthenticationFilterTests-context.xml
│ ├── ConcurrentSessionControlStrategyTests-context.xml
│ ├── ConcurrentSessionFilterTests-context.xml
│ ├── ExceptionTranslationFilterTests-context.xml
│ ├── FilterChainProxyTests-context.xml
│ ├── LoginUrlAuthenticationEntryPointTests-context.xml
│ ├── LogoutFilterTests-context.xml
│ ├── RememberMeAuthenticationFilterTests-context.xml
│ ├── RequestCacheAwareFilterTests-context.xml
│ ├── RequestMatcherTests-context.xml
│ ├── SecurityContextPersistenceFilterTests-context.xml
│ ├── SessionManagementFilterTests-context.xml
│ ├── SwitchUserFilterTests-context.xml
│ └── WebSecurityExpressionHandlerTests-context.xml
└── src
└── docs
└── asciidoc
└── migrate-3-to-4-xml.adoc
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | */src/*/java/META-INF
3 | */src/META-INF/
4 | */src/*/java/META-INF/
5 | .classpath
6 | .springBeans
7 | .project
8 | .DS_Store
9 | .settings/
10 | .idea/
11 | out/
12 | bin/
13 | intellij/
14 | build/
15 | *.log
16 | *.log.*
17 | *.iml
18 | *.ipr
19 | *.iws
20 | .gradle/
21 | atlassian-ide-plugin.xml
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = Migrating from Spring Security 3.x to 4.x
2 |
3 | This project demonstrates how to migrate from Spring Security 3.x to Spring Security 4.x.
4 | You can find detailed instructions in the http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#m3to4[Spring Security 4 Reference]
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'eclipse'
3 |
4 | group = 'org.springframework.security.migrate'
5 |
6 | ext.ASCIIDOC_GRADLE = "$rootDir/gradle/asciidoc.gradle"
7 |
8 | ext.springVersion = '4.1.7.RELEASE'
9 |
10 | task docsZip(type: Zip) {
11 | baseName = rootProject.name
12 | classifier = 'docs'
13 | duplicatesStrategy = 'EXCLUDE'
14 | from { [project(':xml'), project(':jc')]*.tasks*.asciidoctor*.outputs }
15 | into 'migrate'
16 | }
17 |
18 | tasks.build.dependsOn docsZip
19 |
20 | configurations.archives.artifacts.clear()
21 |
22 | artifacts {
23 | archives docsZip
24 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | version=1.0.0-CI-SNAPSHOT
--------------------------------------------------------------------------------
/gradle/asciidoc.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | asciidoctor {
4 | options = [
5 | eruby: 'erubis'
6 | ]
7 | attributes copycss : '',
8 | icons : 'font',
9 | 'source-highlighter': 'prettify',
10 | sectanchors : '',
11 | toc: 'left',
12 | idprefix: '',
13 | idseparator: '-',
14 | doctype: 'book',
15 | numbered: '',
16 |
17 | 'spring-security-docs-url' : 'https://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#',
18 | 'spring-security-migration-github-url' : 'https://github.com/spring-projects/spring-security-migrate-3-to-4/'
19 | }
20 |
21 | tasks.build.dependsOn asciidoctor
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-security-migrate-3-to-4/da1ea227ba56e6a7efed5f54bfb66078ff151d96/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 20 09:40:53 CDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/jc/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'org.asciidoctor.convert' version '1.5.2'
3 | }
4 | apply from: ASCIIDOC_GRADLE
5 |
6 | tasks.findByPath("artifactoryPublish")?.enabled = false
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | bin
4 | .classpath
5 | .settings
6 | .project
7 | .idea
8 | *~
9 | .springBeans
10 | .gradle
11 | *.iml
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-security-migrate-3-to-4/da1ea227ba56e6a7efed5f54bfb66078ff151d96/jc/spring-security-3-jc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 18 08:16:34 CDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/AppInitializer.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4 |
5 | import sample.mvc.MvcConfig;
6 |
7 | public class AppInitializer extends
8 | AbstractAnnotationConfigDispatcherServletInitializer {
9 |
10 | @Override
11 | protected Class>[] getRootConfigClasses() {
12 | return new Class[] {SecurityConfig.class};
13 | }
14 |
15 | @Override
16 | protected Class>[] getServletConfigClasses() {
17 | return new Class[] {MvcConfig.class};
18 | }
19 |
20 | @Override
21 | protected String[] getServletMappings() {
22 | return new String[] {"/"};
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.security.access.prepost.PreAuthorize;
19 |
20 | /**
21 | * @author Rob Winch
22 | */
23 | public class HelloWorldMessageService implements MessageService {
24 |
25 | @PreAuthorize("hasRole('ROLE_USER')")
26 | public String getMessage() {
27 | return "Hello World";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | }
9 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/SecurityInitializer.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
4 |
5 | public class SecurityInitializer extends
6 | AbstractSecurityWebApplicationInitializer {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/mvc/AuthenticationPrincipalController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sample.mvc;
17 |
18 | import org.springframework.security.web.bind.annotation.AuthenticationPrincipal;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 | import org.springframework.web.bind.annotation.RestController;
21 |
22 | /**
23 | * Demonstrates the use of {@link AuthenticationPrincipal} on a method argument.
24 | * See test sample.web.AuthenticationPrincipalTests.
25 | *
26 | * @author Joe Grandja
27 | */
28 | @RestController
29 | public class AuthenticationPrincipalController {
30 |
31 | @RequestMapping("/principal")
32 | public String principal(@AuthenticationPrincipal String principal) {
33 | return principal;
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/mvc/LoginController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.mvc;
17 |
18 | import org.springframework.stereotype.Controller;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 |
21 | /**
22 | * @author Rob Winch
23 | */
24 | @Controller
25 | public class LoginController {
26 | @RequestMapping("/login")
27 | public String login() {
28 | return "login";
29 | }
30 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/java/sample/mvc/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package sample.mvc;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.ComponentScan;
5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6 | import org.springframework.web.servlet.view.InternalResourceViewResolver;
7 |
8 | @EnableWebMvc
9 | @ComponentScan
10 | public class MvcConfig {
11 | @Bean
12 | public InternalResourceViewResolver viewResolver() {
13 | InternalResourceViewResolver resolver = new InternalResourceViewResolver();
14 | resolver.setPrefix("/WEB-INF/views/");
15 | resolver.setSuffix(".jsp");
16 | return resolver;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/webapp/WEB-INF/views/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
3 | <%@taglib prefix="sec"
4 | uri="http://www.springframework.org/security/tags"%>
5 | <%@ page session="false"%>
6 |
7 |
8 | Home
9 |
10 |
11 |
12 | Message
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | Must have ROLE_ADMIN and ROLE_USER
22 |
23 |
24 | Must have ROLE_ADMIN or ROLE_USER
25 |
26 |
27 | Must not have ROLE_ADMIN
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/main/webapp/WEB-INF/views/login.jsp:
--------------------------------------------------------------------------------
1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2 | <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ page pageEncoding="UTF-8"%>
4 |
5 |
6 |
7 | Login
8 |
9 |
10 |
11 | Login
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/acl/AclImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.Mock;
9 | import org.mockito.runners.MockitoJUnitRunner;
10 | import org.springframework.security.acls.domain.AclAuthorizationStrategy;
11 | import org.springframework.security.acls.domain.AclImpl;
12 | import org.springframework.security.acls.domain.AuditLogger;
13 | import org.springframework.security.acls.model.Acl;
14 | import org.springframework.security.acls.model.ObjectIdentity;
15 | import org.springframework.security.acls.model.Sid;
16 |
17 |
18 | @RunWith(MockitoJUnitRunner.class)
19 | public class AclImplTests {
20 | @Mock
21 | ObjectIdentity objectIdentity;
22 | @Mock
23 | AclAuthorizationStrategy aclAuthorizationStrategy;
24 | @Mock
25 | AuditLogger auditLogger;
26 | @Mock
27 | Acl parentAcl;
28 | final boolean entriesInheriting = true;
29 | @Mock
30 | Sid owner;
31 | @Mock
32 | List loadedSids;
33 | Serializable id = "id";
34 |
35 | @Test
36 | public void constructor() {
37 | new AclImpl(objectIdentity, id, aclAuthorizationStrategy, auditLogger,
38 | parentAcl, loadedSids, entriesInheriting, owner);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/acl/EhCacheBasedAclCacheTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import net.sf.ehcache.Ehcache;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.acls.domain.EhCacheBasedAclCache;
10 |
11 | @RunWith(MockitoJUnitRunner.class)
12 | public class EhCacheBasedAclCacheTests {
13 |
14 | @Mock
15 | Ehcache ehCache;
16 |
17 | @Test
18 | public void constructor() throws Exception {
19 | new EhCacheBasedAclCache(ehCache);
20 | }
21 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/cas/ServiceAuthenticationDetailsSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.cas;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.springframework.security.cas.ServiceProperties;
6 | import org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource;
7 |
8 | public class ServiceAuthenticationDetailsSourceTests {
9 | final String artifactId = "TICKET";
10 |
11 | ServiceProperties serviceProperties;
12 |
13 | @Before
14 | public void setup() {
15 | serviceProperties = new ServiceProperties();
16 | }
17 |
18 | @Test
19 | public void constructor() {
20 | new ServiceAuthenticationDetailsSource();
21 | }
22 |
23 | @Test
24 | public void constructorString() {
25 | new ServiceAuthenticationDetailsSource(artifactId);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/AnonymousAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AnonymousAuthenticationProvider;
5 |
6 | public class AnonymousAuthenticationProviderTests {
7 |
8 | final String key = "key";
9 |
10 | @Test
11 | public void constructor() {
12 | AnonymousAuthenticationProvider provider = new AnonymousAuthenticationProvider();
13 | provider.setKey(key);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/AuthenticationDetailsSourceImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AuthenticationDetailsSourceImpl;
5 |
6 | public class AuthenticationDetailsSourceImplTests {
7 |
8 | @Test
9 | public void test() {
10 | AuthenticationDetailsSourceImpl source = new AuthenticationDetailsSourceImpl();
11 | source.setClazz(CustomWebAuthenticationDetails.class);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/CustomWebAuthenticationDetails.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
6 |
7 | @SuppressWarnings("serial")
8 | public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {
9 | private String customProperty;
10 |
11 | public CustomWebAuthenticationDetails(HttpServletRequest request) {
12 | super(request);
13 | this.customProperty = request.getHeader("custom");
14 | }
15 |
16 | public String getCustomProperty() {
17 | return customProperty;
18 | }
19 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/GrantedAuthorityImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.core.authority.GrantedAuthorityImpl;
5 |
6 | public class GrantedAuthorityImplTests {
7 |
8 | @Test
9 | public void constructor() {
10 | new GrantedAuthorityImpl("ROLE_USER");
11 | }
12 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/InMemoryDaoImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.Properties;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.core.userdetails.UserDetailsService;
10 | import org.springframework.security.core.userdetails.memory.InMemoryDaoImpl;
11 |
12 |
13 |
14 | @RunWith(MockitoJUnitRunner.class)
15 | public class InMemoryDaoImplTests {
16 |
17 | @Mock
18 | UserDetailsService uds;
19 |
20 | @Test
21 | public void javaExample() {
22 | Properties properties = new Properties();
23 | properties.put("user", "password,ROLE_USER");
24 |
25 | InMemoryDaoImpl uds = new InMemoryDaoImpl();
26 | uds.setUserProperties(properties);
27 | }
28 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/RememberMeAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.authentication.RememberMeAuthenticationProvider;
8 |
9 | @RunWith(MockitoJUnitRunner.class)
10 | public class RememberMeAuthenticationProviderTests {
11 | final String key = "key";
12 |
13 | @Mock
14 | RememberMeAuthenticationProvider provider;
15 |
16 | @Test
17 | public void javaCompiles() {
18 | RememberMeAuthenticationProvider provider = new RememberMeAuthenticationProvider();
19 | provider.setKey(key);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/SecurityConfigTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.List;
6 |
7 | import org.junit.Test;
8 | import org.springframework.security.access.ConfigAttribute;
9 | import org.springframework.security.access.SecurityConfig;
10 |
11 | public class SecurityConfigTests {
12 |
13 | @Test
14 | public void createSingleAttributeList() {
15 | List attrs =
16 | SecurityConfig.createSingleAttributeList("ROLE_USER");
17 |
18 | assertThat(attrs).onProperty("attribute").containsOnly("ROLE_USER");
19 | }
20 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/core/UserDetailsWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.Collection;
6 | import java.util.List;
7 |
8 | import org.junit.Test;
9 | import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
10 | import org.springframework.security.access.hierarchicalroles.UserDetailsWrapper;
11 | import org.springframework.security.core.GrantedAuthority;
12 | import org.springframework.security.core.authority.AuthorityUtils;
13 | import org.springframework.security.core.userdetails.User;
14 | import org.springframework.security.core.userdetails.UserDetails;
15 |
16 | public class UserDetailsWrapperTests {
17 |
18 | @Test
19 | public void test() {
20 | List authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
21 | UserDetails userDetails = new User("admin", "notused", authorities);
22 | RoleHierarchyImpl roleHiearchy = new RoleHierarchyImpl();
23 | roleHiearchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
24 |
25 | UserDetailsWrapper authenticate = new UserDetailsWrapper(userDetails, roleHiearchy);
26 |
27 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/openid/OpenID4JavaConsumerTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.springframework.security.openid.OpenID4JavaConsumer;
9 | import org.springframework.security.openid.OpenIDAttribute;
10 |
11 | public class OpenID4JavaConsumerTests {
12 |
13 | List attributes;
14 |
15 | @Before
16 | public void setup() {
17 | attributes = Arrays.asList(new OpenIDAttribute("email",
18 | "http://axschema.org/contact/email"));
19 | }
20 |
21 | @Test
22 | public void constructor() throws Exception {
23 | new OpenID4JavaConsumer(attributes);
24 | }
25 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/role_/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.role_;
17 |
18 | import javax.annotation.security.RolesAllowed;
19 |
20 | import org.springframework.security.access.prepost.PreAuthorize;
21 |
22 | /**
23 | * @author Rob Winch
24 | */
25 | public class HelloWorldMessageService implements MessageService {
26 |
27 | @PreAuthorize("hasRole('USER')")
28 | public String getMessage() {
29 | return "Hello World";
30 | }
31 |
32 | @RolesAllowed("USER")
33 | public String getJsrMessage() {
34 | return "Hello JSR";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/role_/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample.role_;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | String getJsrMessage();
9 | }
10 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/AbstractRememberMeServicesTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.core.userdetails.UserDetailsService;
8 | import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
9 | import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
10 | import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
11 |
12 | @RunWith(MockitoJUnitRunner.class)
13 | public class AbstractRememberMeServicesTests {
14 | final String key = "key";
15 |
16 | @Mock
17 | UserDetailsService userDetailsService;
18 |
19 | @Mock
20 | PersistentTokenRepository tokenRepository;
21 |
22 | @Test
23 | public void deprecatedPropertiesPersistentTokenBasedRememberMeServices() {
24 | PersistentTokenBasedRememberMeServices services = new PersistentTokenBasedRememberMeServices();
25 | services.setKey(key);
26 | services.setUserDetailsService(userDetailsService);
27 | services.setTokenRepository(tokenRepository);
28 | }
29 |
30 | @Test
31 | public void deprecatedPropertiesTokenBasedRememberMeServices() {
32 | TokenBasedRememberMeServices services = new TokenBasedRememberMeServices();
33 | services.setKey(key);
34 | services.setUserDetailsService(userDetailsService);
35 | }
36 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/AnonymousAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.springframework.security.core.authority.AuthorityUtils;
6 | import org.springframework.security.core.userdetails.memory.UserAttribute;
7 | import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
8 |
9 | public class AnonymousAuthenticationFilterTests {
10 | final String key = "key";
11 | UserAttribute attrs;
12 |
13 | @Before
14 | public void setup() {
15 | attrs = new UserAttribute();
16 | attrs.setPassword("anonymous");
17 | attrs.setAuthorities(AuthorityUtils
18 | .createAuthorityList("ROLE_ANONYMOUS"));
19 | }
20 |
21 | @Test
22 | public void deprecatedProperties() {
23 | AnonymousAuthenticationFilter filter = new AnonymousAuthenticationFilter();
24 | filter.setKey(key);
25 | filter.setUserAttribute(attrs);
26 | }
27 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/BasicAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.authentication.AuthenticationManager;
8 | import org.springframework.security.web.AuthenticationEntryPoint;
9 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
10 |
11 | @RunWith(MockitoJUnitRunner.class)
12 | public class BasicAuthenticationFilterTests {
13 | @Mock
14 | AuthenticationManager authenticationManager;
15 |
16 | @Mock
17 | AuthenticationEntryPoint entryPoint;
18 |
19 | final boolean ignoreFailure = false;
20 |
21 | @Test
22 | public void deprecated() {
23 | BasicAuthenticationFilter filter = new BasicAuthenticationFilter();
24 | filter.setAuthenticationManager(authenticationManager);
25 | filter.setAuthenticationEntryPoint(entryPoint);
26 | filter.setIgnoreFailure(ignoreFailure);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/ConcurrentSessionControlStrategyTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.core.session.SessionRegistry;
8 | import org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy;
9 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
10 |
11 | @RunWith(MockitoJUnitRunner.class)
12 | public class ConcurrentSessionControlStrategyTests {
13 |
14 | @Mock
15 | SessionRegistry sessionRegistry;
16 | @Mock
17 | SessionAuthenticationStrategy sas;
18 |
19 | @Test
20 | public void deprecated() {
21 | ConcurrentSessionControlStrategy strategy = new ConcurrentSessionControlStrategy(
22 | sessionRegistry);
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/ConcurrentSessionFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.core.session.SessionRegistry;
10 | import org.springframework.security.web.session.ConcurrentSessionFilter;
11 |
12 | @RunWith(MockitoJUnitRunner.class)
13 | public class ConcurrentSessionFilterTests {
14 | @Mock
15 | SessionRegistry sessionRegistry;
16 | @Mock
17 | Filter filter;
18 |
19 | @Test
20 | public void deprecated() {
21 | ConcurrentSessionFilter filter = new ConcurrentSessionFilter();
22 | filter.setSessionRegistry(sessionRegistry);
23 | filter.setExpiredUrl("/expired");
24 | }
25 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/ExceptionTranslationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.web.AuthenticationEntryPoint;
5 | import org.springframework.security.web.access.ExceptionTranslationFilter;
6 | import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
7 | import org.springframework.security.web.savedrequest.NullRequestCache;
8 | import org.springframework.security.web.savedrequest.RequestCache;
9 |
10 | public class ExceptionTranslationFilterTests {
11 |
12 | @Test
13 | public void deprecatedSetters() {
14 | RequestCache requestCache = new NullRequestCache();
15 | AuthenticationEntryPoint entryPoint = new Http403ForbiddenEntryPoint();
16 |
17 | ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
18 | filter.setAuthenticationEntryPoint(entryPoint);
19 | filter.setRequestCache(requestCache);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/LoginUrlAuthenticationEntryPointTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
5 |
6 |
7 |
8 | public class LoginUrlAuthenticationEntryPointTests {
9 |
10 | @Test
11 | public void deprecatedProperties() {
12 | LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint();
13 | entryPoint.setLoginFormUrl("/login");
14 | }
15 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/RequestCacheAwareFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.security.web.savedrequest.NullRequestCache;
11 | import org.springframework.security.web.savedrequest.RequestCache;
12 | import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class RequestCacheAwareFilterTests {
19 | @Autowired
20 | RequestCache requestCache;
21 | @Autowired
22 | Filter filter;
23 |
24 | @Test
25 | public void configLoads() {}
26 |
27 | @Configuration
28 | static class Config {
29 |
30 | @Bean
31 | public RequestCacheAwareFilter rememberMeAuthenticationFilter(RequestCache requestCache) {
32 | RequestCacheAwareFilter filter = new RequestCacheAwareFilter();
33 | filter.setRequestCache(requestCache);
34 | return filter;
35 | }
36 |
37 | @Bean
38 | public RequestCache requestCache() {
39 | return new NullRequestCache();
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/jc/spring-security-3-jc/src/test/java/sample/web/SecurityContextPersistenceFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.security.web.context.NullSecurityContextRepository;
8 | import org.springframework.security.web.context.SecurityContextPersistenceFilter;
9 | import org.springframework.security.web.context.SecurityContextRepository;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class SecurityContextPersistenceFilterTests {
18 |
19 | @Test
20 | public void configLoads() {}
21 |
22 | @Configuration
23 | static class Config {
24 | @Bean
25 | public SecurityContextPersistenceFilter securityContextPersistenceFilter(SecurityContextRepository securityContextRepository) {
26 | SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter();
27 | filter.setSecurityContextRepository(securityContextRepository);
28 | return filter;
29 | }
30 |
31 | @Bean
32 | public SecurityContextRepository securityContextRepository() {
33 | return new NullSecurityContextRepository();
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | bin
4 | .classpath
5 | .settings
6 | .project
7 | .idea
8 | *~
9 | .springBeans
10 | .gradle
11 | *.iml
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-security-migrate-3-to-4/da1ea227ba56e6a7efed5f54bfb66078ff151d96/jc/spring-security-4-jc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 18 08:16:34 CDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/AppInitializer.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4 |
5 | import sample.mvc.MvcConfig;
6 |
7 | public class AppInitializer extends
8 | AbstractAnnotationConfigDispatcherServletInitializer {
9 |
10 | @Override
11 | protected Class>[] getRootConfigClasses() {
12 | return new Class[] {SecurityConfig.class};
13 | }
14 |
15 | @Override
16 | protected Class>[] getServletConfigClasses() {
17 | return new Class[] {MvcConfig.class};
18 | }
19 |
20 | @Override
21 | protected String[] getServletMappings() {
22 | return new String[] {"/"};
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.security.access.prepost.PreAuthorize;
19 |
20 | /**
21 | * @author Rob Winch
22 | */
23 | public class HelloWorldMessageService implements MessageService {
24 |
25 | @PreAuthorize("hasRole('ROLE_USER')")
26 | public String getMessage() {
27 | return "Hello World";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | }
9 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/SecurityInitializer.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
4 |
5 | public class SecurityInitializer extends
6 | AbstractSecurityWebApplicationInitializer {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/mvc/AuthenticationPrincipalController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sample.mvc;
17 |
18 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
19 | import org.springframework.security.core.userdetails.User;
20 | import org.springframework.web.bind.annotation.RequestMapping;
21 | import org.springframework.web.bind.annotation.RestController;
22 |
23 | /**
24 | * Demonstrates the use of {@link AuthenticationPrincipal} on a method argument.
25 | * See test sample.web.AuthenticationPrincipalTests.
26 | *
27 | * @author Joe Grandja
28 | */
29 | @RestController
30 | public class AuthenticationPrincipalController {
31 |
32 | @RequestMapping("/principal")
33 | public String principal(@AuthenticationPrincipal User principal) {
34 | return principal.getUsername();
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/mvc/LoginController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.mvc;
17 |
18 | import org.springframework.stereotype.Controller;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 |
21 | /**
22 | * @author Rob Winch
23 | */
24 | @Controller
25 | public class LoginController {
26 | @RequestMapping("/login")
27 | public String login() {
28 | return "login";
29 | }
30 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/java/sample/mvc/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package sample.mvc;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.ComponentScan;
5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6 | import org.springframework.web.servlet.view.InternalResourceViewResolver;
7 |
8 | @EnableWebMvc
9 | @ComponentScan
10 | public class MvcConfig {
11 | @Bean
12 | public InternalResourceViewResolver viewResolver() {
13 | InternalResourceViewResolver resolver = new InternalResourceViewResolver();
14 | resolver.setPrefix("/WEB-INF/views/");
15 | resolver.setSuffix(".jsp");
16 | return resolver;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/webapp/WEB-INF/views/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
3 | <%@taglib prefix="sec"
4 | uri="http://www.springframework.org/security/tags"%>
5 | <%@ page session="false"%>
6 |
7 |
8 | Home
9 |
10 |
11 |
12 | Message
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | Must have ROLE_ADMIN and ROLE_USER
22 |
23 |
24 | Must have ROLE_ADMIN or ROLE_USER
25 |
26 |
27 | Must not have ROLE_ADMIN or ROLE_USER
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/main/webapp/WEB-INF/views/login.jsp:
--------------------------------------------------------------------------------
1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2 | <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ page pageEncoding="UTF-8"%>
4 |
5 |
6 |
7 | Login
8 |
9 |
10 |
11 | Login
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/acl/EhCacheBasedAclCacheTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import net.sf.ehcache.Ehcache;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.acls.domain.AclAuthorizationStrategy;
10 | import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl;
11 | import org.springframework.security.acls.domain.AuditLogger;
12 | import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy;
13 | import org.springframework.security.acls.domain.EhCacheBasedAclCache;
14 | import org.springframework.security.acls.model.PermissionGrantingStrategy;
15 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
16 |
17 | @RunWith(MockitoJUnitRunner.class)
18 | public class EhCacheBasedAclCacheTests {
19 |
20 | @Mock
21 | Ehcache ehCache;
22 | @Mock
23 | AuditLogger auditLogger;
24 |
25 | @Test
26 | public void constructor() throws Exception {
27 | PermissionGrantingStrategy permissionGrantingStrategy =
28 | new DefaultPermissionGrantingStrategy(auditLogger);
29 | AclAuthorizationStrategy aclAuthorizationStrategy =
30 | new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_ACL_ADMIN"));
31 | new EhCacheBasedAclCache(ehCache, permissionGrantingStrategy, aclAuthorizationStrategy);
32 | }
33 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/cas/ServiceAuthenticationDetailsSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.cas;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.springframework.security.cas.ServiceProperties;
6 | import org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource;
7 |
8 | public class ServiceAuthenticationDetailsSourceTests {
9 | final String artifactId = "TICKET";
10 |
11 | ServiceProperties serviceProperties;
12 |
13 | @Before
14 | public void setup() {
15 | serviceProperties = new ServiceProperties();
16 | }
17 |
18 | @Test
19 | public void constructor() {
20 | new ServiceAuthenticationDetailsSource(serviceProperties);
21 | }
22 |
23 | @Test
24 | public void constructorString() {
25 | new ServiceAuthenticationDetailsSource(serviceProperties, artifactId);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/AbstractAccessDecisionManagerTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.mockito.Mockito.mock;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 | import org.mockito.Mock;
12 | import org.mockito.runners.MockitoJUnitRunner;
13 | import org.springframework.security.access.AccessDecisionManager;
14 | import org.springframework.security.access.AccessDecisionVoter;
15 | import org.springframework.security.access.vote.AffirmativeBased;
16 | import org.springframework.security.access.vote.ConsensusBased;
17 | import org.springframework.security.access.vote.UnanimousBased;
18 |
19 | @RunWith(MockitoJUnitRunner.class)
20 | public class AbstractAccessDecisionManagerTests {
21 | @Mock
22 | List adm;
23 |
24 | List> voters;
25 |
26 | @Before
27 | public void setup() {
28 | voters = Arrays
29 | .> asList(mock(AccessDecisionVoter.class));
30 | }
31 |
32 | @Test
33 | public void affirmativeBased() {
34 | AffirmativeBased adm = new AffirmativeBased(voters);
35 | }
36 |
37 | @Test
38 | public void consensusBased() {
39 | ConsensusBased adm = new ConsensusBased(voters);
40 | }
41 |
42 | @Test
43 | public void unanimousBased() {
44 | UnanimousBased adm = new UnanimousBased(voters);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/AnonymousAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AnonymousAuthenticationProvider;
5 |
6 | public class AnonymousAuthenticationProviderTests {
7 |
8 | final String key = "key";
9 |
10 | @Test
11 | public void constructor() {
12 | AnonymousAuthenticationProvider provider = new AnonymousAuthenticationProvider(key);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/AuthenticationDetailsSourceImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.junit.Test;
6 | import org.springframework.security.authentication.AuthenticationDetailsSource;
7 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
8 |
9 | public class AuthenticationDetailsSourceImplTests {
10 |
11 | @Test
12 | public void test() {
13 | CustomWebAuthenticationDetailsSource source = new CustomWebAuthenticationDetailsSource();
14 | }
15 |
16 | public class CustomWebAuthenticationDetailsSource implements AuthenticationDetailsSource {
17 |
18 | public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
19 | return new CustomWebAuthenticationDetails(context);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/CustomWebAuthenticationDetails.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
6 |
7 | @SuppressWarnings("serial")
8 | public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {
9 | private String customProperty;
10 |
11 | public CustomWebAuthenticationDetails(HttpServletRequest request) {
12 | super(request);
13 | this.customProperty = request.getHeader("custom");
14 | }
15 |
16 | public String getCustomProperty() {
17 | return customProperty;
18 | }
19 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/GrantedAuthorityImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
5 |
6 | public class GrantedAuthorityImplTests {
7 |
8 | @Test
9 | public void constructor() {
10 | new SimpleGrantedAuthority("ROLE_USER");
11 | }
12 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/InMemoryDaoImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.Properties;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.core.userdetails.UserDetailsService;
10 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
11 |
12 |
13 |
14 | @RunWith(MockitoJUnitRunner.class)
15 | public class InMemoryDaoImplTests {
16 |
17 | @Mock
18 | UserDetailsService uds;
19 |
20 | @Test
21 | public void javaExample() {
22 | Properties properties = new Properties();
23 | properties.put("user", "password,ROLE_USER");
24 |
25 | InMemoryUserDetailsManager uds = new InMemoryUserDetailsManager(properties);
26 | }
27 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/RememberMeAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.authentication.RememberMeAuthenticationProvider;
8 |
9 | @RunWith(MockitoJUnitRunner.class)
10 | public class RememberMeAuthenticationProviderTests {
11 | final String key = "key";
12 |
13 | @Mock
14 | RememberMeAuthenticationProvider provider;
15 |
16 | @Test
17 | public void javaCompiles() {
18 | RememberMeAuthenticationProvider provider = new RememberMeAuthenticationProvider(key);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/SecurityConfigTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.List;
6 |
7 | import org.junit.Test;
8 | import org.springframework.security.access.ConfigAttribute;
9 | import org.springframework.security.access.SecurityConfig;
10 |
11 | public class SecurityConfigTests {
12 |
13 | @Test
14 | public void createSingleAttributeList() {
15 | List attrs =
16 | SecurityConfig.createList("ROLE_USER");
17 |
18 | assertThat(attrs).onProperty("attribute").containsOnly("ROLE_USER");
19 | }
20 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/core/UserDetailsWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.Collection;
6 | import java.util.List;
7 |
8 | import org.junit.Test;
9 | import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
10 | import org.springframework.security.core.GrantedAuthority;
11 | import org.springframework.security.core.authority.AuthorityUtils;
12 | import org.springframework.security.core.userdetails.User;
13 | import org.springframework.security.core.userdetails.UserDetails;
14 |
15 | public class UserDetailsWrapperTests {
16 |
17 | @Test
18 | public void test() {
19 | List authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
20 | UserDetails userDetails = new User("admin", "notused", authorities);
21 | RoleHierarchyImpl roleHiearchy = new RoleHierarchyImpl();
22 | roleHiearchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
23 |
24 | Collection allAuthorities =
25 | roleHiearchy.getReachableGrantedAuthorities(userDetails.getAuthorities());
26 | UserDetails authenticate =
27 | new User(userDetails.getUsername(), userDetails.getPassword(), allAuthorities);
28 |
29 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/openid/OpenID4JavaConsumerTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.springframework.security.openid.OpenID4JavaConsumer;
11 | import org.springframework.security.openid.OpenIDAttribute;
12 | import org.springframework.security.openid.RegexBasedAxFetchListFactory;
13 |
14 | public class OpenID4JavaConsumerTests {
15 |
16 | List attributes;
17 |
18 | @Before
19 | public void setup() {
20 | attributes = Arrays.asList(new OpenIDAttribute("email",
21 | "http://axschema.org/contact/email"));
22 | }
23 |
24 | @Test
25 | public void constructor() throws Exception {
26 | Map> regexMap = new HashMap>();
27 | regexMap.put(".*", attributes);
28 | RegexBasedAxFetchListFactory factory = new RegexBasedAxFetchListFactory(regexMap);
29 | new OpenID4JavaConsumer(factory);
30 | }
31 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/role_/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.role_;
17 |
18 | import javax.annotation.security.RolesAllowed;
19 |
20 | import org.springframework.security.access.prepost.PreAuthorize;
21 |
22 | /**
23 | * @author Rob Winch
24 | */
25 | public class HelloWorldMessageService implements MessageService {
26 |
27 | @PreAuthorize("hasRole('USER')")
28 | public String getMessage() {
29 | return "Hello World";
30 | }
31 |
32 | @RolesAllowed("USER")
33 | public String getJsrMessage() {
34 | return "Hello JSR";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/role_/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample.role_;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | String getJsrMessage();
9 | }
10 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/AbstractRememberMeServicesTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.core.userdetails.UserDetailsService;
8 | import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
9 | import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
10 | import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
11 |
12 | @RunWith(MockitoJUnitRunner.class)
13 | public class AbstractRememberMeServicesTests {
14 | final String key = "key";
15 |
16 | @Mock
17 | UserDetailsService userDetailsService;
18 |
19 | @Mock
20 | PersistentTokenRepository tokenRepository;
21 |
22 |
23 | @Test
24 | public void deprecatedPropertiesPersistentTokenBasedRememberMeServices() {
25 | PersistentTokenBasedRememberMeServices services = new PersistentTokenBasedRememberMeServices(
26 | key, userDetailsService, tokenRepository);
27 | }
28 |
29 | @Test
30 | public void deprecatedPropertiesTokenBasedRememberMeServices() {
31 | TokenBasedRememberMeServices services = new TokenBasedRememberMeServices(
32 | key, userDetailsService);
33 | }
34 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/AnonymousAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.springframework.security.core.authority.AuthorityUtils;
6 | import org.springframework.security.core.userdetails.memory.UserAttribute;
7 | import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
8 |
9 | public class AnonymousAuthenticationFilterTests {
10 | final String key = "key";
11 | UserAttribute attrs;
12 |
13 | @Before
14 | public void setup() {
15 | attrs = new UserAttribute();
16 | attrs.setPassword("anonymous");
17 | attrs.setAuthorities(AuthorityUtils
18 | .createAuthorityList("ROLE_ANONYMOUS"));
19 | }
20 |
21 | @Test
22 | public void deprecatedProperties() {
23 | AnonymousAuthenticationFilter filter =
24 | new AnonymousAuthenticationFilter(key,attrs.getPassword(),attrs.getAuthorities());
25 | }
26 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/BasicAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mock;
6 | import org.mockito.runners.MockitoJUnitRunner;
7 | import org.springframework.security.authentication.AuthenticationManager;
8 | import org.springframework.security.web.AuthenticationEntryPoint;
9 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
10 |
11 | @RunWith(MockitoJUnitRunner.class)
12 | public class BasicAuthenticationFilterTests {
13 | @Mock
14 | AuthenticationManager authenticationManager;
15 |
16 | @Mock
17 | AuthenticationEntryPoint entryPoint;
18 |
19 | final boolean ignoreFailure = false;
20 |
21 |
22 | @Test
23 | public void deprecated() {
24 | BasicAuthenticationFilter filter =
25 | new BasicAuthenticationFilter(authenticationManager,entryPoint);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/ConcurrentSessionFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.core.session.SessionRegistry;
10 | import org.springframework.security.web.session.ConcurrentSessionFilter;
11 |
12 | @RunWith(MockitoJUnitRunner.class)
13 | public class ConcurrentSessionFilterTests {
14 | @Mock
15 | SessionRegistry sessionRegistry;
16 | @Mock
17 | Filter filter;
18 |
19 | @Test
20 | public void deprecated() {
21 | ConcurrentSessionFilter filter = new ConcurrentSessionFilter(sessionRegistry,"/expired");
22 | }
23 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/ExceptionTranslationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.web.AuthenticationEntryPoint;
5 | import org.springframework.security.web.access.ExceptionTranslationFilter;
6 | import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
7 | import org.springframework.security.web.savedrequest.NullRequestCache;
8 | import org.springframework.security.web.savedrequest.RequestCache;
9 |
10 | public class ExceptionTranslationFilterTests {
11 |
12 | @Test
13 | public void deprecatedSetters() {
14 | RequestCache requestCache = new NullRequestCache();
15 | AuthenticationEntryPoint entryPoint = new Http403ForbiddenEntryPoint();
16 |
17 | ExceptionTranslationFilter filter = new ExceptionTranslationFilter(entryPoint, requestCache);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/LoginUrlAuthenticationEntryPointTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
5 |
6 |
7 |
8 | public class LoginUrlAuthenticationEntryPointTests {
9 |
10 | @Test
11 | public void deprecatedProperties() {
12 | LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint("/login");
13 | }
14 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/RequestCacheAwareFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.security.web.savedrequest.NullRequestCache;
11 | import org.springframework.security.web.savedrequest.RequestCache;
12 | import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class RequestCacheAwareFilterTests {
19 | @Autowired
20 | RequestCache requestCache;
21 | @Autowired
22 | Filter filter;
23 |
24 | @Test
25 | public void configLoads() {}
26 |
27 | @Configuration
28 | static class Config {
29 |
30 | @Bean
31 | public RequestCacheAwareFilter rememberMeAuthenticationFilter(RequestCache requestCache) {
32 | RequestCacheAwareFilter filter = new RequestCacheAwareFilter(requestCache);
33 | return filter;
34 | }
35 |
36 | @Bean
37 | public RequestCache requestCache() {
38 | return new NullRequestCache();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/jc/spring-security-4-jc/src/test/java/sample/web/SecurityContextPersistenceFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.security.web.context.NullSecurityContextRepository;
8 | import org.springframework.security.web.context.SecurityContextPersistenceFilter;
9 | import org.springframework.security.web.context.SecurityContextRepository;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class SecurityContextPersistenceFilterTests {
18 |
19 | @Test
20 | public void configLoads() {}
21 |
22 | @Configuration
23 | static class Config {
24 | @Bean
25 | public SecurityContextPersistenceFilter securityContextPersistenceFilter(SecurityContextRepository securityContextRepository) {
26 | SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(securityContextRepository);
27 | return filter;
28 | }
29 |
30 | @Bean
31 | public SecurityContextRepository securityContextRepository() {
32 | return new NullSecurityContextRepository();
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/push-changes.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash --
2 |
3 | git checkout jc
4 | git reset --hard master
5 | cp -r jc/spring-security-4-jc/* jc/spring-security-3-jc/
6 | git add .
7 | git commit -m 'Migrate to Spring Security 4'
8 | git push -f origin jc
9 | git checkout xml
10 | git reset --hard master
11 | cp -r xml/spring-security-4-xml/* xml/spring-security-3-xml/
12 | git add .
13 | git commit -m 'Migrate to Spring Security 4'
14 | git push -f origin xml
15 | git checkout master
16 | git push -f origin master
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'spring-security-migrate-3-to-4'
2 |
3 | include ':xml:spring-security-4-xml'
4 | include ':xml:spring-security-3-xml'
5 | include ':jc:spring-security-4-jc'
6 | include ':jc:spring-security-3-jc'
7 |
--------------------------------------------------------------------------------
/xml/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'org.asciidoctor.convert' version '1.5.2'
3 | }
4 | apply from: ASCIIDOC_GRADLE
5 |
6 | tasks.findByPath("artifactoryPublish")?.enabled = false
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | bin
4 | .classpath
5 | .settings
6 | .project
7 | .idea
8 | *~
9 | .springBeans
10 | .gradle
11 | *.iml
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-security-migrate-3-to-4/da1ea227ba56e6a7efed5f54bfb66078ff151d96/xml/spring-security-3-xml/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 18 08:16:34 CDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/java/sample/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.security.access.prepost.PreAuthorize;
19 |
20 | /**
21 | * @author Rob Winch
22 | */
23 | public class HelloWorldMessageService implements MessageService {
24 |
25 | @PreAuthorize("hasRole('ROLE_USER')")
26 | public String getMessage() {
27 | return "Hello World";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/java/sample/HomeController.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import java.util.Locale;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.ui.Model;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 |
13 | /**
14 | * Handles requests for the application home page.
15 | */
16 | @Controller
17 | public class HomeController {
18 |
19 | private final MessageService messageService;
20 |
21 | @Autowired
22 | public HomeController(MessageService messageService) {
23 | this.messageService = messageService;
24 | }
25 |
26 | /**
27 | * Simply selects the home view to render by returning its name.
28 | */
29 | @RequestMapping(value = "/", method = RequestMethod.GET)
30 | public String home(Locale locale, Model model) {
31 |
32 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
33 | if (principal instanceof UserDetails) {
34 | model.addAttribute("username", ((UserDetails) principal).getUsername());
35 | } else {
36 | model.addAttribute("username", principal);
37 | }
38 | model.addAttribute("message", messageService.getMessage());
39 | return "home";
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/java/sample/LoginController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.stereotype.Controller;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 |
21 | /**
22 | * @author Rob Winch
23 | */
24 | @Controller
25 | public class LoginController {
26 | @RequestMapping("/login")
27 | public String login() {
28 | return "login";
29 | }
30 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/java/sample/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | }
9 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/webapp/WEB-INF/spring/root-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/webapp/WEB-INF/spring/security.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/webapp/WEB-INF/views/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2 | <%@taglib prefix="sec"
3 | uri="http://www.springframework.org/security/tags"%>
4 | <%@ page session="false"%>
5 |
6 |
7 | Home
8 |
9 |
10 |
11 | Message
12 |
13 |
14 | Log Out
15 |
16 |
17 |
18 | Must have ROLE_ADMIN and ROLE_USER
19 |
20 |
21 | Must have ROLE_ADMIN or ROLE_USER
22 |
23 |
24 | Must not have ROLE_ADMIN
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/main/webapp/WEB-INF/views/login.jsp:
--------------------------------------------------------------------------------
1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2 | <%@ page pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 | Login
7 |
8 |
9 |
10 | Login
11 |
12 |
13 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/acl/AclImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.Mock;
9 | import org.mockito.runners.MockitoJUnitRunner;
10 | import org.springframework.security.acls.domain.AclAuthorizationStrategy;
11 | import org.springframework.security.acls.domain.AclImpl;
12 | import org.springframework.security.acls.domain.AuditLogger;
13 | import org.springframework.security.acls.model.Acl;
14 | import org.springframework.security.acls.model.ObjectIdentity;
15 | import org.springframework.security.acls.model.Sid;
16 |
17 |
18 | @RunWith(MockitoJUnitRunner.class)
19 | public class AclImplTests {
20 | @Mock
21 | ObjectIdentity objectIdentity;
22 | @Mock
23 | AclAuthorizationStrategy aclAuthorizationStrategy;
24 | @Mock
25 | AuditLogger auditLogger;
26 | @Mock
27 | Acl parentAcl;
28 | final boolean entriesInheriting = true;
29 | @Mock
30 | Sid owner;
31 | @Mock
32 | List loadedSids;
33 | Serializable id = "id";
34 |
35 | @Test
36 | public void constructor() {
37 | new AclImpl(objectIdentity, id, aclAuthorizationStrategy, auditLogger,
38 | parentAcl, loadedSids, entriesInheriting, owner);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/acl/EhCacheBasedAclCacheTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import net.sf.ehcache.Ehcache;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.acls.domain.EhCacheBasedAclCache;
10 |
11 | @RunWith(MockitoJUnitRunner.class)
12 | public class EhCacheBasedAclCacheTests {
13 |
14 | @Mock
15 | Ehcache ehCache;
16 |
17 | @Test
18 | public void constructor() throws Exception {
19 | new EhCacheBasedAclCache(ehCache);
20 | }
21 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/cas/ServiceAuthenticationDetailsSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.cas;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.security.cas.ServiceProperties;
7 | import org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource;
8 | import org.springframework.test.context.ContextConfiguration;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 |
11 |
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class ServiceAuthenticationDetailsSourceTests {
16 | final String artifactId = "TICKET";
17 |
18 | ServiceProperties serviceProperties;
19 |
20 | @Before
21 | public void setup() {
22 | serviceProperties = new ServiceProperties();
23 | }
24 |
25 | @Test
26 | public void xmlConfigurationLoads() {}
27 |
28 | @Test
29 | public void constructor() {
30 | new ServiceAuthenticationDetailsSource();
31 | }
32 |
33 | @Test
34 | public void constructorString() {
35 | new ServiceAuthenticationDetailsSource(artifactId);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/config/FilterInvocationDefinitionSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.config;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | @RunWith(SpringJUnit4ClassRunner.class)
11 | @ContextConfiguration
12 | public class FilterInvocationDefinitionSourceTests {
13 |
14 | @Autowired
15 | FilterInvocationSecurityMetadataSource sms;
16 |
17 | @Test
18 | public void loads() {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/config/HeadersTests.java:
--------------------------------------------------------------------------------
1 | package sample.config;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.mock.web.MockFilterChain;
10 | import org.springframework.mock.web.MockHttpServletRequest;
11 | import org.springframework.mock.web.MockHttpServletResponse;
12 | import org.springframework.security.web.FilterChainProxy;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class HeadersTests {
19 |
20 | MockHttpServletRequest request;
21 | MockHttpServletResponse response;
22 | MockFilterChain chain;
23 |
24 | @Autowired
25 | FilterChainProxy springSecurityFilterChain;
26 |
27 | @Before
28 | public void setup() {
29 | request = new MockHttpServletRequest();
30 | response = new MockHttpServletResponse();
31 | chain = new MockFilterChain();
32 | }
33 |
34 | @Test
35 | public void headers() throws Exception {
36 | springSecurityFilterChain.doFilter(request, response, chain);
37 |
38 | assertThat(response.getHeader("X-Frame-Options")).isEqualTo("SAMEORIGIN");
39 | assertThat(response.getHeaderNames().size()).isEqualTo(1);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/AnonymousAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AnonymousAuthenticationProvider;
5 |
6 | public class AnonymousAuthenticationProviderTests {
7 |
8 | final String key = "key";
9 |
10 | @Test
11 | public void constructor() {
12 | AnonymousAuthenticationProvider provider = new AnonymousAuthenticationProvider();
13 | provider.setKey(key);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/AuthenticationDetailsSourceImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AuthenticationDetailsSourceImpl;
5 |
6 | public class AuthenticationDetailsSourceImplTests {
7 |
8 | @Test
9 | public void test() {
10 | AuthenticationDetailsSourceImpl source = new AuthenticationDetailsSourceImpl();
11 | source.setClazz(CustomWebAuthenticationDetails.class);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/CustomWebAuthenticationDetails.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
6 |
7 | @SuppressWarnings("serial")
8 | public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {
9 | private String customProperty;
10 |
11 | public CustomWebAuthenticationDetails(HttpServletRequest request) {
12 | super(request);
13 | this.customProperty = request.getHeader("custom");
14 | }
15 |
16 | public String getCustomProperty() {
17 | return customProperty;
18 | }
19 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/GrantedAuthorityImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.core.authority.GrantedAuthorityImpl;
5 |
6 | public class GrantedAuthorityImplTests {
7 |
8 | @Test
9 | public void constructor() {
10 | new GrantedAuthorityImpl("ROLE_USER");
11 | }
12 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/InMemoryDaoImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.Properties;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.springframework.security.core.userdetails.memory.InMemoryDaoImpl;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class InMemoryDaoImplTests {
18 |
19 | @Autowired
20 | UserDetailsService uds;
21 |
22 | @Test
23 | public void findUser() {
24 | uds.loadUserByUsername("user");
25 | }
26 |
27 | @Test
28 | public void javaExample() {
29 | Properties properties = new Properties();
30 | properties.put("user","password,ROLE_USER");
31 |
32 | InMemoryDaoImpl uds = new InMemoryDaoImpl();
33 | uds.setUserProperties(properties);
34 | }
35 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/ProviderManagerTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.List;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.security.authentication.AuthenticationProvider;
10 | import org.springframework.security.authentication.ProviderManager;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class ProviderManagerTests {
19 |
20 | @Autowired
21 | List providers;
22 |
23 | @Qualifier("parent")
24 | @Autowired
25 | ProviderManager parent;
26 |
27 | @Test
28 | public void contextLoads() {
29 | }
30 |
31 | @Test
32 | public void javaCompiles() {
33 | ProviderManager provider = new ProviderManager();
34 | provider.setParent(parent);
35 | provider.setProviders(providers);
36 | provider.setClearExtraInformation(true);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/RememberMeAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.RememberMeAuthenticationProvider;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 |
11 |
12 | @RunWith(SpringJUnit4ClassRunner.class)
13 | @ContextConfiguration
14 | public class RememberMeAuthenticationProviderTests {
15 | final String key = "key";
16 |
17 | @Autowired
18 | RememberMeAuthenticationProvider provider;
19 |
20 | @Test
21 | public void contextLoads() {}
22 |
23 | @Test
24 | public void javaCompiles() {
25 | RememberMeAuthenticationProvider provider = new RememberMeAuthenticationProvider();
26 | provider.setKey(key);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/SecurityConfigTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.List;
6 |
7 | import org.junit.Test;
8 | import org.springframework.security.access.ConfigAttribute;
9 | import org.springframework.security.access.SecurityConfig;
10 |
11 | public class SecurityConfigTests {
12 |
13 | @Test
14 | public void createSingleAttributeList() {
15 | List attrs =
16 | SecurityConfig.createSingleAttributeList("ROLE_USER");
17 |
18 | assertThat(attrs).onProperty("attribute").containsOnly("ROLE_USER");
19 | }
20 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/UserDetailsServiceWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.*;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.authentication.AuthenticationManager;
9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
10 | import org.springframework.security.core.Authentication;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class UserDetailsServiceWrapperTests {
18 |
19 | @Autowired
20 | AuthenticationManager auth;
21 |
22 | @Test
23 | public void hasHierarchy() {
24 | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "password");
25 |
26 | Authentication authenticate = auth.authenticate(token);
27 |
28 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
29 | }
30 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/core/UserDetailsWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.Collection;
6 | import java.util.List;
7 |
8 | import org.junit.Test;
9 | import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
10 | import org.springframework.security.access.hierarchicalroles.UserDetailsWrapper;
11 | import org.springframework.security.core.GrantedAuthority;
12 | import org.springframework.security.core.authority.AuthorityUtils;
13 | import org.springframework.security.core.userdetails.User;
14 | import org.springframework.security.core.userdetails.UserDetails;
15 |
16 | public class UserDetailsWrapperTests {
17 |
18 | @Test
19 | public void test() {
20 | List authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
21 | UserDetails userDetails = new User("admin", "notused", authorities);
22 | RoleHierarchyImpl roleHiearchy = new RoleHierarchyImpl();
23 | roleHiearchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
24 |
25 | UserDetailsWrapper authenticate = new UserDetailsWrapper(userDetails, roleHiearchy);
26 |
27 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/openid/OpenID4JavaConsumerTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.security.openid.OpenID4JavaConsumer;
10 | import org.springframework.security.openid.OpenIDAttribute;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class OpenID4JavaConsumerTests {
17 |
18 | List attributes;
19 |
20 | @Before
21 | public void setup() {
22 | attributes = Arrays.asList(new OpenIDAttribute("email", "http://axschema.org/contact/email"));
23 | }
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void constructor() throws Exception {
30 | new OpenID4JavaConsumer(attributes);
31 | }
32 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/openid/OpenIDTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.mock.web.MockFilterChain;
10 | import org.springframework.mock.web.MockHttpServletRequest;
11 | import org.springframework.mock.web.MockHttpServletResponse;
12 | import org.springframework.security.web.FilterChainProxy;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class OpenIDTests {
19 |
20 | @Autowired
21 | FilterChainProxy springSecurityFilter;
22 |
23 | MockHttpServletRequest request;
24 | MockHttpServletResponse response;
25 | MockFilterChain chain;
26 |
27 | @Before
28 | public void setup() {
29 | request = new MockHttpServletRequest();
30 | response = new MockHttpServletResponse();
31 | chain = new MockFilterChain();
32 | }
33 |
34 | @Test
35 | public void filterProcessUrl() throws Exception {
36 | request.setRequestURI("/j_spring_openid_security_check");
37 |
38 | springSecurityFilter.doFilter(request, response, chain);
39 |
40 | assertThat(response.getRedirectedUrl()).isNotNull();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/role_/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.role_;
17 |
18 | import javax.annotation.security.RolesAllowed;
19 |
20 | import org.springframework.security.access.prepost.PreAuthorize;
21 |
22 | /**
23 | * @author Rob Winch
24 | */
25 | public class HelloWorldMessageService implements MessageService {
26 |
27 | @PreAuthorize("hasRole('USER')")
28 | public String getMessage() {
29 | return "Hello World";
30 | }
31 |
32 | @RolesAllowed("USER")
33 | public String getJsrMessage() {
34 | return "Hello JSR";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/role_/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample.role_;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | String getJsrMessage();
9 | }
10 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/BasicAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.AuthenticationManager;
7 | import org.springframework.security.web.AuthenticationEntryPoint;
8 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
9 | import org.springframework.test.context.ContextConfiguration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 |
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class BasicAuthenticationFilterTests {
17 | @Autowired
18 | AuthenticationManager authenticationManager;
19 |
20 | @Autowired
21 | AuthenticationEntryPoint entryPoint;
22 |
23 | final boolean ignoreFailure = false;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | BasicAuthenticationFilter filter = new BasicAuthenticationFilter();
31 | filter.setAuthenticationManager(authenticationManager);
32 | filter.setAuthenticationEntryPoint(entryPoint);
33 | filter.setIgnoreFailure(ignoreFailure);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/ConcurrentSessionControlStrategyTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.core.session.SessionRegistry;
7 | import org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy;
8 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
9 | import org.springframework.test.context.ContextConfiguration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 |
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class ConcurrentSessionControlStrategyTests {
17 |
18 | @Autowired
19 | SessionRegistry sessionRegistry;
20 |
21 | @Autowired
22 | SessionAuthenticationStrategy sas;
23 |
24 | @Test
25 | public void configLoads() {}
26 |
27 | @Test
28 | public void deprecated() {
29 | ConcurrentSessionControlStrategy strategy = new ConcurrentSessionControlStrategy(sessionRegistry);
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/ConcurrentSessionFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.session.SessionRegistry;
9 | import org.springframework.security.web.session.ConcurrentSessionFilter;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class ConcurrentSessionFilterTests {
16 | @Autowired
17 | SessionRegistry sessionRegistry;
18 | @Autowired
19 | Filter filter;
20 |
21 | @Test
22 | public void configLoads() {}
23 |
24 | @Test
25 | public void deprecated() {
26 | ConcurrentSessionFilter filter = new ConcurrentSessionFilter();
27 | filter.setSessionRegistry(sessionRegistry);
28 | filter.setExpiredUrl("/expired");
29 | }
30 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/ExceptionTranslationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.AuthenticationEntryPoint;
7 | import org.springframework.security.web.access.ExceptionTranslationFilter;
8 | import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
9 | import org.springframework.security.web.savedrequest.NullRequestCache;
10 | import org.springframework.security.web.savedrequest.RequestCache;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class ExceptionTranslationFilterTests {
19 | @Autowired
20 | ExceptionTranslationFilter etf;
21 |
22 | @Test
23 | public void configLoads() {}
24 |
25 | @Test
26 | public void deprecatedSetters() {
27 | RequestCache requestCache = new NullRequestCache();
28 | AuthenticationEntryPoint entryPoint = new Http403ForbiddenEntryPoint();
29 |
30 | ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
31 | filter.setAuthenticationEntryPoint(entryPoint);
32 | filter.setRequestCache(requestCache);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/LoginUrlAuthenticationEntryPointTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.authority.AuthorityUtils;
9 | import org.springframework.security.core.context.SecurityContextHolder;
10 | import org.springframework.security.core.userdetails.memory.UserAttribute;
11 | import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
12 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 |
17 |
18 | @RunWith(SpringJUnit4ClassRunner.class)
19 | @ContextConfiguration
20 | public class LoginUrlAuthenticationEntryPointTests {
21 | @Test
22 | public void configLoads() {}
23 |
24 | @Test
25 | public void deprecatedProperties() {
26 | LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint();
27 | entryPoint.setLoginFormUrl("/login");
28 | }
29 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/RememberMeAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.AuthenticationManager;
7 | import org.springframework.security.web.authentication.RememberMeServices;
8 | import org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter;
9 | import org.springframework.test.context.ContextConfiguration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 |
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class RememberMeAuthenticationFilterTests {
17 | @Autowired
18 | AuthenticationManager authenticationManager;
19 | @Autowired
20 | RememberMeServices rememberMeServices;
21 |
22 | @Autowired
23 | RememberMeAuthenticationFilter filter;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | RememberMeAuthenticationFilter filter = new RememberMeAuthenticationFilter();
31 | filter.setAuthenticationManager(authenticationManager);
32 | filter.setRememberMeServices(rememberMeServices);
33 | }
34 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/RequestCacheAwareFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.web.savedrequest.RequestCache;
9 | import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class RequestCacheAwareFilterTests {
16 | @Autowired
17 | RequestCache requestCache;
18 | @Autowired
19 | Filter filter;
20 |
21 | @Test
22 | public void configLoads() {}
23 |
24 | @Test
25 | public void deprecated() {
26 | RequestCacheAwareFilter filter = new RequestCacheAwareFilter();
27 | filter.setRequestCache(requestCache);
28 | }
29 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/SecurityContextPersistenceFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.context.SecurityContextPersistenceFilter;
7 | import org.springframework.security.web.context.SecurityContextRepository;
8 | import org.springframework.test.context.ContextConfiguration;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 |
11 |
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class SecurityContextPersistenceFilterTests {
16 | @Autowired
17 | SecurityContextRepository securityContextRepository;
18 |
19 | @Test
20 | public void configLoads() {}
21 |
22 | @Test
23 | public void deprecated() {
24 | SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter();
25 | filter.setSecurityContextRepository(securityContextRepository);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/java/sample/web/SessionManagementFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.session.SessionRegistry;
9 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
10 | import org.springframework.security.web.context.SecurityContextRepository;
11 | import org.springframework.security.web.session.SessionManagementFilter;
12 | import org.springframework.test.context.ContextConfiguration;
13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class SessionManagementFilterTests {
18 | @Autowired
19 | SecurityContextRepository securityContextRepository;
20 | @Autowired
21 | SessionAuthenticationStrategy sessionAuthenticationStrategy;
22 | @Autowired
23 | Filter filter;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | SessionManagementFilter filter = new SessionManagementFilter(securityContextRepository);
31 | filter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy);
32 | }
33 | }
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/cas/CasAuthenticationFilterDefaultUrlsTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/cas/ServiceAuthenticationDetailsSourceTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/FilterChainMapPathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/FilterInvocationDefinitionSourceTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/FilterSecurityMetadataSourcePathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/HeadersTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/HttpAccessDeniedPageTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/config/HttpPathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/core/AbstractAccessDecisionManagerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/core/InMemoryDaoImplTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 | user=password,ROLE_USER
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/core/RememberMeAuthenticationProviderTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/core/UserDetailsServiceWrapperTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ROLE_ADMIN > ROLE_USER
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/openid/OpenID4JavaConsumerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/openid/OpenIDTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/role_/RolePrefixTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/AbstractRememberMeServicesTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/AnonymousAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/BasicAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/ConcurrentSessionControlStrategyTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/ConcurrentSessionFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/ExceptionTranslationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/FilterChainProxyTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/LoginUrlAuthenticationEntryPointTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/LogoutFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/RememberMeAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/RequestCacheAwareFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/RequestMatcherTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/SecurityContextPersistenceFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/SessionManagementFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/SwitchUserFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/xml/spring-security-3-xml/src/test/resources/sample/web/WebSecurityExpressionHandlerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | bin
4 | .classpath
5 | .settings
6 | .project
7 | .idea
8 | *~
9 | .springBeans
10 | .gradle
11 | *.iml
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/java/sample/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.security.access.prepost.PreAuthorize;
19 |
20 | /**
21 | * @author Rob Winch
22 | */
23 | public class HelloWorldMessageService implements MessageService {
24 |
25 | @PreAuthorize("hasRole('ROLE_USER')")
26 | public String getMessage() {
27 | return "Hello World";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/java/sample/HomeController.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import java.util.Locale;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.ui.Model;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 |
13 | /**
14 | * Handles requests for the application home page.
15 | */
16 | @Controller
17 | public class HomeController {
18 |
19 | private final MessageService messageService;
20 |
21 | @Autowired
22 | public HomeController(MessageService messageService) {
23 | this.messageService = messageService;
24 | }
25 |
26 | /**
27 | * Simply selects the home view to render by returning its name.
28 | */
29 | @RequestMapping(value = "/", method = RequestMethod.GET)
30 | public String home(Locale locale, Model model) {
31 |
32 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
33 | if (principal instanceof UserDetails) {
34 | model.addAttribute("username", ((UserDetails) principal).getUsername());
35 | } else {
36 | model.addAttribute("username", principal);
37 | }
38 | model.addAttribute("message", messageService.getMessage());
39 | return "home";
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/java/sample/LoginController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample;
17 |
18 | import org.springframework.stereotype.Controller;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 |
21 | /**
22 | * @author Rob Winch
23 | */
24 | @Controller
25 | public class LoginController {
26 | @RequestMapping("/login")
27 | public String login() {
28 | return "login";
29 | }
30 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/java/sample/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | }
9 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/webapp/WEB-INF/spring/root-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/webapp/WEB-INF/spring/security.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/webapp/WEB-INF/views/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2 | <%@taglib prefix="sec"
3 | uri="http://www.springframework.org/security/tags"%>
4 | <%@ page session="false"%>
5 |
6 |
7 | Home
8 |
9 |
10 |
11 | Message
12 |
13 |
14 | Log Out
15 |
16 |
17 |
18 | Must have ROLE_ADMIN and ROLE_USER
19 |
20 |
21 | Must have ROLE_ADMIN or ROLE_USER
22 |
23 |
24 | Must not have ROLE_ADMIN or ROLE_USER
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/main/webapp/WEB-INF/views/login.jsp:
--------------------------------------------------------------------------------
1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2 | <%@ page pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 | Login
7 |
8 |
9 |
10 | Login
11 |
12 |
13 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/acl/EhCacheBasedAclCacheTests.java:
--------------------------------------------------------------------------------
1 | package sample.acl;
2 |
3 | import net.sf.ehcache.Ehcache;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 | import org.springframework.security.acls.domain.AclAuthorizationStrategy;
10 | import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl;
11 | import org.springframework.security.acls.domain.AuditLogger;
12 | import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy;
13 | import org.springframework.security.acls.domain.EhCacheBasedAclCache;
14 | import org.springframework.security.acls.model.PermissionGrantingStrategy;
15 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
16 |
17 | @RunWith(MockitoJUnitRunner.class)
18 | public class EhCacheBasedAclCacheTests {
19 |
20 | @Mock
21 | Ehcache ehCache;
22 | @Mock
23 | AuditLogger auditLogger;
24 |
25 | @Test
26 | public void constructor() throws Exception {
27 | PermissionGrantingStrategy permissionGrantingStrategy =
28 | new DefaultPermissionGrantingStrategy(auditLogger);
29 | AclAuthorizationStrategy aclAuthorizationStrategy =
30 | new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_ACL_ADMIN"));
31 | new EhCacheBasedAclCache(ehCache, permissionGrantingStrategy, aclAuthorizationStrategy);
32 | }
33 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/cas/ServiceAuthenticationDetailsSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.cas;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.security.cas.ServiceProperties;
7 | import org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource;
8 | import org.springframework.test.context.ContextConfiguration;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 |
11 |
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class ServiceAuthenticationDetailsSourceTests {
16 | final String artifactId = "TICKET";
17 |
18 | ServiceProperties serviceProperties;
19 |
20 | @Before
21 | public void setup() {
22 | serviceProperties = new ServiceProperties();
23 | }
24 |
25 | @Test
26 | public void xmlConfigurationLoads() {}
27 |
28 | @Test
29 | public void constructor() {
30 | new ServiceAuthenticationDetailsSource(serviceProperties);
31 | }
32 |
33 | @Test
34 | public void constructorString() {
35 | new ServiceAuthenticationDetailsSource(serviceProperties, artifactId);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/config/FilterInvocationDefinitionSourceTests.java:
--------------------------------------------------------------------------------
1 | package sample.config;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | @RunWith(SpringJUnit4ClassRunner.class)
11 | @ContextConfiguration
12 | public class FilterInvocationDefinitionSourceTests {
13 |
14 | @Autowired
15 | FilterInvocationSecurityMetadataSource sms;
16 |
17 | @Test
18 | public void loads() {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/config/HeadersTests.java:
--------------------------------------------------------------------------------
1 | package sample.config;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.mock.web.MockFilterChain;
10 | import org.springframework.mock.web.MockHttpServletRequest;
11 | import org.springframework.mock.web.MockHttpServletResponse;
12 | import org.springframework.security.web.FilterChainProxy;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class HeadersTests {
19 |
20 | MockHttpServletRequest request;
21 | MockHttpServletResponse response;
22 | MockFilterChain chain;
23 |
24 | @Autowired
25 | FilterChainProxy springSecurityFilterChain;
26 |
27 | @Before
28 | public void setup() {
29 | request = new MockHttpServletRequest();
30 | response = new MockHttpServletResponse();
31 | chain = new MockFilterChain();
32 | }
33 |
34 | @Test
35 | public void headers() throws Exception {
36 | springSecurityFilterChain.doFilter(request, response, chain);
37 |
38 | assertThat(response.getHeader("X-Frame-Options")).isEqualTo("SAMEORIGIN");
39 | assertThat(response.getHeaderNames().size()).isEqualTo(1);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/AnonymousAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.authentication.AnonymousAuthenticationProvider;
5 |
6 | public class AnonymousAuthenticationProviderTests {
7 |
8 | final String key = "key";
9 |
10 | @Test
11 | public void constructor() {
12 | AnonymousAuthenticationProvider provider = new AnonymousAuthenticationProvider(key);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/AuthenticationDetailsSourceImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.junit.Test;
6 | import org.springframework.security.authentication.AuthenticationDetailsSource;
7 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
8 |
9 | public class AuthenticationDetailsSourceImplTests {
10 |
11 | @Test
12 | public void test() {
13 | CustomWebAuthenticationDetailsSource source = new CustomWebAuthenticationDetailsSource();
14 | }
15 |
16 | public class CustomWebAuthenticationDetailsSource implements AuthenticationDetailsSource {
17 |
18 | public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
19 | return new CustomWebAuthenticationDetails(context);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/CustomWebAuthenticationDetails.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.springframework.security.web.authentication.WebAuthenticationDetails;
6 |
7 | @SuppressWarnings("serial")
8 | public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {
9 | private String customProperty;
10 |
11 | public CustomWebAuthenticationDetails(HttpServletRequest request) {
12 | super(request);
13 | this.customProperty = request.getHeader("custom");
14 | }
15 |
16 | public String getCustomProperty() {
17 | return customProperty;
18 | }
19 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/GrantedAuthorityImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
5 |
6 | public class GrantedAuthorityImplTests {
7 |
8 | @Test
9 | public void constructor() {
10 | new SimpleGrantedAuthority("ROLE_USER");
11 | }
12 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/InMemoryDaoImplTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.Properties;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class InMemoryDaoImplTests {
18 |
19 | @Autowired
20 | UserDetailsService uds;
21 |
22 | @Test
23 | public void findUser() {
24 | uds.loadUserByUsername("user");
25 | }
26 |
27 | @Test
28 | public void javaExample() {
29 | Properties properties = new Properties();
30 | properties.put("user","password,ROLE_USER");
31 |
32 | InMemoryUserDetailsManager uds = new InMemoryUserDetailsManager(properties);
33 | }
34 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/ProviderManagerTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import java.util.List;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.security.authentication.AuthenticationProvider;
10 | import org.springframework.security.authentication.ProviderManager;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class ProviderManagerTests {
19 |
20 | @Autowired
21 | List providers;
22 |
23 | @Qualifier("parent")
24 | @Autowired
25 | ProviderManager parent;
26 |
27 | @Test
28 | public void contextLoads() {
29 | }
30 |
31 | @Test
32 | public void javaCompiles() {
33 | ProviderManager provider = new ProviderManager(providers, parent);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/RememberMeAuthenticationProviderTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.RememberMeAuthenticationProvider;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 |
11 |
12 | @RunWith(SpringJUnit4ClassRunner.class)
13 | @ContextConfiguration
14 | public class RememberMeAuthenticationProviderTests {
15 | final String key = "key";
16 |
17 | @Autowired
18 | RememberMeAuthenticationProvider provider;
19 |
20 | @Test
21 | public void contextLoads() {}
22 |
23 | @Test
24 | public void javaCompiles() {
25 | RememberMeAuthenticationProvider provider = new RememberMeAuthenticationProvider(key);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/SecurityConfigTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.List;
6 |
7 | import org.junit.Test;
8 | import org.springframework.security.access.ConfigAttribute;
9 | import org.springframework.security.access.SecurityConfig;
10 |
11 | public class SecurityConfigTests {
12 |
13 | @Test
14 | public void createSingleAttributeList() {
15 | List attrs =
16 | SecurityConfig.createList("ROLE_USER");
17 |
18 | assertThat(attrs).onProperty("attribute").containsOnly("ROLE_USER");
19 | }
20 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/UserDetailsServiceWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.*;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.authentication.AuthenticationManager;
9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
10 | import org.springframework.security.core.Authentication;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class UserDetailsServiceWrapperTests {
18 |
19 | @Autowired
20 | AuthenticationManager auth;
21 |
22 | @Test
23 | public void hasHierarchy() {
24 | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "password");
25 |
26 | Authentication authenticate = auth.authenticate(token);
27 |
28 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
29 | }
30 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/core/UserDetailsWrapperTests.java:
--------------------------------------------------------------------------------
1 | package sample.core;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import java.util.Collection;
6 | import java.util.List;
7 |
8 | import org.junit.Test;
9 | import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
10 | import org.springframework.security.core.GrantedAuthority;
11 | import org.springframework.security.core.authority.AuthorityUtils;
12 | import org.springframework.security.core.userdetails.User;
13 | import org.springframework.security.core.userdetails.UserDetails;
14 |
15 | public class UserDetailsWrapperTests {
16 |
17 | @Test
18 | public void test() {
19 | List authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
20 | UserDetails userDetails = new User("admin", "notused", authorities);
21 | RoleHierarchyImpl roleHiearchy = new RoleHierarchyImpl();
22 | roleHiearchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
23 |
24 | Collection allAuthorities =
25 | roleHiearchy.getReachableGrantedAuthorities(userDetails.getAuthorities());
26 | UserDetails authenticate =
27 | new User(userDetails.getUsername(), userDetails.getPassword(), allAuthorities);
28 |
29 | assertThat(authenticate.getAuthorities()).onProperty("authority").containsOnly("ROLE_USER","ROLE_ADMIN");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/openid/OpenID4JavaConsumerTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 | import org.springframework.security.openid.OpenID4JavaConsumer;
12 | import org.springframework.security.openid.OpenIDAttribute;
13 | import org.springframework.security.openid.RegexBasedAxFetchListFactory;
14 | import org.springframework.test.context.ContextConfiguration;
15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16 |
17 | @RunWith(SpringJUnit4ClassRunner.class)
18 | @ContextConfiguration
19 | public class OpenID4JavaConsumerTests {
20 |
21 | List attributes;
22 |
23 | @Before
24 | public void setup() {
25 | attributes = Arrays.asList(new OpenIDAttribute("email", "http://axschema.org/contact/email"));
26 | }
27 |
28 | @Test
29 | public void configLoads() {}
30 |
31 | @Test
32 | public void constructor() throws Exception {
33 | Map> regexMap = new HashMap>();
34 | regexMap.put(".*", attributes);
35 | RegexBasedAxFetchListFactory factory = new RegexBasedAxFetchListFactory(regexMap);
36 | new OpenID4JavaConsumer(factory);
37 | }
38 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/openid/OpenIDTests.java:
--------------------------------------------------------------------------------
1 | package sample.openid;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.mock.web.MockFilterChain;
10 | import org.springframework.mock.web.MockHttpServletRequest;
11 | import org.springframework.mock.web.MockHttpServletResponse;
12 | import org.springframework.security.web.FilterChainProxy;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class OpenIDTests {
19 |
20 | @Autowired
21 | FilterChainProxy springSecurityFilter;
22 |
23 | MockHttpServletRequest request;
24 | MockHttpServletResponse response;
25 | MockFilterChain chain;
26 |
27 | @Before
28 | public void setup() {
29 | request = new MockHttpServletRequest();
30 | request.setMethod("GET");
31 | response = new MockHttpServletResponse();
32 | chain = new MockFilterChain();
33 | }
34 |
35 | @Test
36 | public void filterProcessUrl() throws Exception {
37 | request.setServletPath("/j_spring_openid_security_check");
38 |
39 | springSecurityFilter.doFilter(request, response, chain);
40 |
41 | assertThat(response.getRedirectedUrl()).isNotNull();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/role_/HelloWorldMessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package sample.role_;
17 |
18 | import javax.annotation.security.RolesAllowed;
19 |
20 | import org.springframework.security.access.prepost.PreAuthorize;
21 |
22 | /**
23 | * @author Rob Winch
24 | */
25 | public class HelloWorldMessageService implements MessageService {
26 |
27 | @PreAuthorize("hasRole('USER')")
28 | public String getMessage() {
29 | return "Hello World";
30 | }
31 |
32 | @RolesAllowed("USER")
33 | public String getJsrMessage() {
34 | return "Hello JSR";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/role_/MessageService.java:
--------------------------------------------------------------------------------
1 | package sample.role_;
2 |
3 | /**
4 | * @author Rob Winch
5 | */
6 | public interface MessageService {
7 | String getMessage();
8 | String getJsrMessage();
9 | }
10 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/BasicAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.AuthenticationManager;
7 | import org.springframework.security.web.AuthenticationEntryPoint;
8 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
9 | import org.springframework.test.context.ContextConfiguration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 |
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class BasicAuthenticationFilterTests {
17 | @Autowired
18 | AuthenticationManager authenticationManager;
19 |
20 | @Autowired
21 | AuthenticationEntryPoint entryPoint;
22 |
23 | final boolean ignoreFailure = false;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | BasicAuthenticationFilter filter =
31 | new BasicAuthenticationFilter(authenticationManager,entryPoint);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/ConcurrentSessionFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.session.SessionRegistry;
9 | import org.springframework.security.web.session.ConcurrentSessionFilter;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class ConcurrentSessionFilterTests {
16 | @Autowired
17 | SessionRegistry sessionRegistry;
18 | @Autowired
19 | Filter filter;
20 |
21 | @Test
22 | public void configLoads() {}
23 |
24 | @Test
25 | public void deprecated() {
26 | ConcurrentSessionFilter filter = new ConcurrentSessionFilter(sessionRegistry,"/expired");
27 | }
28 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/ExceptionTranslationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.AuthenticationEntryPoint;
7 | import org.springframework.security.web.access.ExceptionTranslationFilter;
8 | import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
9 | import org.springframework.security.web.savedrequest.NullRequestCache;
10 | import org.springframework.security.web.savedrequest.RequestCache;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @ContextConfiguration
18 | public class ExceptionTranslationFilterTests {
19 | @Autowired
20 | ExceptionTranslationFilter etf;
21 |
22 | @Test
23 | public void configLoads() {}
24 |
25 | @Test
26 | public void deprecatedSetters() {
27 | RequestCache requestCache = new NullRequestCache();
28 | AuthenticationEntryPoint entryPoint = new Http403ForbiddenEntryPoint();
29 |
30 | ExceptionTranslationFilter filter = new ExceptionTranslationFilter(entryPoint, requestCache);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/LoginUrlAuthenticationEntryPointTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
6 | import org.springframework.test.context.ContextConfiguration;
7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8 |
9 | @RunWith(SpringJUnit4ClassRunner.class)
10 | @ContextConfiguration
11 | public class LoginUrlAuthenticationEntryPointTests {
12 | @Test
13 | public void configLoads() {
14 | }
15 |
16 | @Test
17 | public void deprecatedProperties() {
18 | LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint("/login");
19 | }
20 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/RememberMeAuthenticationFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.AuthenticationManager;
7 | import org.springframework.security.web.authentication.RememberMeServices;
8 | import org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter;
9 | import org.springframework.test.context.ContextConfiguration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 |
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class)
15 | @ContextConfiguration
16 | public class RememberMeAuthenticationFilterTests {
17 | @Autowired
18 | AuthenticationManager authenticationManager;
19 | @Autowired
20 | RememberMeServices rememberMeServices;
21 |
22 | @Autowired
23 | RememberMeAuthenticationFilter filter;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | RememberMeAuthenticationFilter filter =
31 | new RememberMeAuthenticationFilter(authenticationManager,rememberMeServices);
32 | }
33 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/RequestCacheAwareFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.web.savedrequest.RequestCache;
9 | import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class RequestCacheAwareFilterTests {
16 | @Autowired
17 | RequestCache requestCache;
18 | @Autowired
19 | Filter filter;
20 |
21 | @Test
22 | public void configLoads() {}
23 |
24 | @Test
25 | public void deprecated() {
26 | RequestCacheAwareFilter filter = new RequestCacheAwareFilter(requestCache);
27 | }
28 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/SecurityContextPersistenceFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.web.context.SecurityContextPersistenceFilter;
7 | import org.springframework.security.web.context.SecurityContextRepository;
8 | import org.springframework.test.context.ContextConfiguration;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 |
11 |
12 |
13 | @RunWith(SpringJUnit4ClassRunner.class)
14 | @ContextConfiguration
15 | public class SecurityContextPersistenceFilterTests {
16 | @Autowired
17 | SecurityContextRepository securityContextRepository;
18 |
19 | @Test
20 | public void configLoads() {}
21 |
22 | @Test
23 | public void deprecated() {
24 | SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(securityContextRepository);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/SessionManagementFilterTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.security.core.session.SessionRegistry;
9 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
10 | import org.springframework.security.web.context.SecurityContextRepository;
11 | import org.springframework.security.web.session.SessionManagementFilter;
12 | import org.springframework.test.context.ContextConfiguration;
13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration
17 | public class SessionManagementFilterTests {
18 | @Autowired
19 | SecurityContextRepository securityContextRepository;
20 | @Autowired
21 | SessionAuthenticationStrategy sessionAuthenticationStrategy;
22 | @Autowired
23 | Filter filter;
24 |
25 | @Test
26 | public void configLoads() {}
27 |
28 | @Test
29 | public void deprecated() {
30 | SessionManagementFilter filter = new SessionManagementFilter(securityContextRepository, sessionAuthenticationStrategy);
31 | }
32 | }
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/java/sample/web/WebSecurityExpressionHandlerTests.java:
--------------------------------------------------------------------------------
1 | package sample.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.context.ApplicationContext;
7 | import org.springframework.expression.EvaluationContext;
8 | import org.springframework.expression.ExpressionParser;
9 | import org.springframework.security.access.expression.SecurityExpressionHandler;
10 | import org.springframework.security.core.Authentication;
11 | import org.springframework.security.web.FilterInvocation;
12 | import org.springframework.test.context.ContextConfiguration;
13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 |
15 |
16 |
17 | @RunWith(SpringJUnit4ClassRunner.class)
18 | @ContextConfiguration
19 | public class WebSecurityExpressionHandlerTests {
20 |
21 | @Autowired
22 | SecurityExpressionHandler handler;
23 |
24 | @Autowired
25 | ApplicationContext context;
26 |
27 | @Test
28 | public void configLoads() {}
29 |
30 | static class CustomWebSecurityExpressionHandler implements SecurityExpressionHandler {
31 |
32 | @Override
33 | public ExpressionParser getExpressionParser() {
34 | return null;
35 | }
36 |
37 | @Override
38 | public EvaluationContext createEvaluationContext(
39 | Authentication authentication, FilterInvocation invocation) {
40 | return null;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/cas/CasAuthenticationFilterDefaultUrlsTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/cas/ServiceAuthenticationDetailsSourceTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/FilterChainMapPathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/FilterInvocationDefinitionSourceTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/FilterSecurityMetadataSourcePathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/HeadersTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/HttpAccessDeniedPageTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/config/HttpPathTypeTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/core/AbstractAccessDecisionManagerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/core/InMemoryDaoImplTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 | user=password,ROLE_USER
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/core/RememberMeAuthenticationProviderTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/openid/OpenID4JavaConsumerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/openid/OpenIDTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/role_/RolePrefixTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/AbstractRememberMeServicesTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/AnonymousAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/BasicAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/ConcurrentSessionControlStrategyTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/ConcurrentSessionFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/ExceptionTranslationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/FilterChainProxyTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/LoginUrlAuthenticationEntryPointTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/LogoutFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/RememberMeAuthenticationFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/RequestCacheAwareFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/RequestMatcherTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/SecurityContextPersistenceFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/SessionManagementFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/SwitchUserFilterTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/xml/spring-security-4-xml/src/test/resources/sample/web/WebSecurityExpressionHandlerTests-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------