mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Fixed sandbox build
This commit is contained in:
parent
fc9a1f0242
commit
6a0da5fe67
@ -16,14 +16,21 @@
|
|||||||
<artifactId>spring-security-core</artifactId>
|
<artifactId>spring-security-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>org.springframework.test</artifactId>
|
<artifactId>org.springframework.test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package org.springframework.security.captcha;
|
package org.springframework.security.captcha;
|
||||||
|
|
||||||
import org.springframework.security.ConfigAttribute;
|
import org.springframework.security.ConfigAttribute;
|
||||||
import org.springframework.security.ConfigAttributeDefinition;
|
|
||||||
|
|
||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
|
|
||||||
@ -77,8 +76,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
|
|||||||
Assert.hasLength(keyword, "keyword required");
|
Assert.hasLength(keyword, "keyword required");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decide(FilterInvocation invocation, ConfigAttributeDefinition config)
|
public void decide(FilterInvocation invocation, java.util.List<ConfigAttribute> config) throws IOException, ServletException {
|
||||||
throws IOException, ServletException {
|
|
||||||
if ((invocation == null) || (config == null)) {
|
if ((invocation == null) || (config == null)) {
|
||||||
throw new IllegalArgumentException("Nulls cannot be provided");
|
throw new IllegalArgumentException("Nulls cannot be provided");
|
||||||
}
|
}
|
||||||
@ -86,7 +84,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
|
|||||||
CaptchaSecurityContext context = null;
|
CaptchaSecurityContext context = null;
|
||||||
context = (CaptchaSecurityContext) SecurityContextHolder.getContext();
|
context = (CaptchaSecurityContext) SecurityContextHolder.getContext();
|
||||||
|
|
||||||
Iterator iter = config.getConfigAttributes().iterator();
|
Iterator iter = config.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
||||||
|
@ -181,8 +181,7 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commence(ServletRequest request, ServletResponse response)
|
public void commence(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||||
throws IOException, ServletException {
|
|
||||||
StringBuffer redirectUrl = new StringBuffer();
|
StringBuffer redirectUrl = new StringBuffer();
|
||||||
HttpServletRequest req = (HttpServletRequest) request;
|
HttpServletRequest req = (HttpServletRequest) request;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package org.springframework.security.captcha;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.springframework.security.ConfigAttributeDefinition;
|
import org.springframework.security.ConfigAttribute;
|
||||||
import org.springframework.security.SecurityConfig;
|
import org.springframework.security.SecurityConfig;
|
||||||
|
|
||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
@ -28,6 +28,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
|||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
@ -44,7 +45,7 @@ import javax.servlet.ServletResponse;
|
|||||||
public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
private MockHttpServletResponse decideWithNewResponse(ConfigAttributeDefinition cad,
|
private MockHttpServletResponse decideWithNewResponse(List<ConfigAttribute> cad,
|
||||||
CaptchaChannelProcessorTemplate processor, MockHttpServletRequest request)
|
CaptchaChannelProcessorTemplate processor, MockHttpServletRequest request)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
MockHttpServletResponse response;
|
MockHttpServletResponse response;
|
||||||
@ -70,7 +71,7 @@ public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
|||||||
CaptchaChannelProcessorTemplate processor = new TestHumanityCaptchaChannelProcessor();
|
CaptchaChannelProcessorTemplate processor = new TestHumanityCaptchaChannelProcessor();
|
||||||
processor.setKeyword("X");
|
processor.setKeyword("X");
|
||||||
|
|
||||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition("Y");
|
List<ConfigAttribute> cad = SecurityConfig.createList("Y");
|
||||||
|
|
||||||
CaptchaSecurityContext context = new CaptchaSecurityContextImpl();
|
CaptchaSecurityContext context = new CaptchaSecurityContextImpl();
|
||||||
SecurityContextHolder.setContext(context);
|
SecurityContextHolder.setContext(context);
|
||||||
@ -136,7 +137,7 @@ public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
|||||||
CaptchaChannelProcessorTemplate processor = new TestHumanityCaptchaChannelProcessor();
|
CaptchaChannelProcessorTemplate processor = new TestHumanityCaptchaChannelProcessor();
|
||||||
processor.setKeyword("X");
|
processor.setKeyword("X");
|
||||||
|
|
||||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition("X");
|
List<ConfigAttribute> cad = SecurityConfig.createList("X");
|
||||||
CaptchaSecurityContext context = new CaptchaSecurityContextImpl();
|
CaptchaSecurityContext context = new CaptchaSecurityContextImpl();
|
||||||
SecurityContextHolder.setContext(context);
|
SecurityContextHolder.setContext(context);
|
||||||
|
|
||||||
@ -224,5 +225,5 @@ public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
|||||||
public void doFilter(ServletRequest arg0, ServletResponse arg1) throws IOException, ServletException {
|
public void doFilter(ServletRequest arg0, ServletResponse arg1) throws IOException, ServletException {
|
||||||
throw new UnsupportedOperationException("mock method not implemented");
|
throw new UnsupportedOperationException("mock method not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.springframework.security.context.SecurityContextHolder;
|
import org.springframework.security.context.SecurityContextHolder;
|
||||||
|
|
||||||
|
import org.springframework.security.util.MockFilter;
|
||||||
import org.springframework.security.util.MockFilterChain;
|
import org.springframework.security.util.MockFilterChain;
|
||||||
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
@ -17,19 +17,26 @@
|
|||||||
<artifactId>spring-security-core</artifactId>
|
<artifactId>spring-security-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>org.springframework.test</artifactId>
|
<artifactId>org.springframework.test</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>org.springframework.jdbc</artifactId>
|
||||||
</dependency>
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ldap</groupId>
|
<groupId>org.springframework.ldap</groupId>
|
||||||
<artifactId>spring-ldap</artifactId>
|
<artifactId>spring-ldap-core</artifactId>
|
||||||
<version>1.2.1</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -45,27 +52,26 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>org.aspectj</groupId>
|
||||||
<artifactId>aspectjrt</artifactId>
|
<artifactId>com.springsource.org.aspectj.runtime</artifactId>
|
||||||
<version>1.5.4</version>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>org.aspectj</groupId>
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>com.springsource.org.aspectj.weaver</artifactId>
|
||||||
<version>1.5.4</version>
|
</dependency>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ldapsdk</groupId>
|
<groupId>ldapsdk</groupId>
|
||||||
<artifactId>ldapsdk</artifactId>
|
<artifactId>ldapsdk</artifactId>
|
||||||
<version>4.1</version>
|
<version>4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.samba.jcifs</groupId>
|
<groupId>org.samba.jcifs</groupId>
|
||||||
<artifactId>jcifs</artifactId>
|
<artifactId>jcifs</artifactId>
|
||||||
<version>1.2.6</version>
|
<version>1.2.6</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>hsqldb</groupId>
|
<groupId>hsqldb</groupId>
|
||||||
<artifactId>hsqldb</artifactId>
|
<artifactId>hsqldb</artifactId>
|
||||||
|
@ -28,8 +28,8 @@ import netscape.ldap.ber.stream.BERSequence;
|
|||||||
import netscape.ldap.ber.stream.BERTag;
|
import netscape.ldap.ber.stream.BERTag;
|
||||||
import netscape.ldap.ber.stream.BERTagDecoder;
|
import netscape.ldap.ber.stream.BERTagDecoder;
|
||||||
|
|
||||||
import org.springframework.security.ldap.LdapDataAccessException;
|
|
||||||
import org.springframework.security.ldap.ppolicy.PasswordPolicyControl;
|
import org.springframework.security.ldap.ppolicy.PasswordPolicyControl;
|
||||||
|
import org.springframework.dao.DataRetrievalFailureException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -98,7 +98,7 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
|
|||||||
try {
|
try {
|
||||||
decoder.decode();
|
decoder.decode();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new LdapDataAccessException("Failed to parse control value", e);
|
throw new DataRetrievalFailureException("Failed to parse control value", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +107,6 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
|
|||||||
/**
|
/**
|
||||||
* Returns the unchanged value of the response control. Returns the unchanged value of the response
|
* Returns the unchanged value of the response control. Returns the unchanged value of the response
|
||||||
* control as byte array.
|
* control as byte array.
|
||||||
*
|
|
||||||
* @return DOCUMENT ME!
|
|
||||||
*/
|
*/
|
||||||
public byte[] getEncodedValue() {
|
public byte[] getEncodedValue() {
|
||||||
return encodedValue;
|
return encodedValue;
|
||||||
@ -287,7 +285,7 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new LdapDataAccessException("Unexpected tag " + tag);
|
throw new DataRetrievalFailureException("Unexpected tag " + tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInChoice(boolean inChoice) {
|
private void setInChoice(boolean inChoice) {
|
||||||
|
@ -22,6 +22,8 @@ import org.springframework.security.GrantedAuthority;
|
|||||||
import org.springframework.security.userdetails.UserDetails;
|
import org.springframework.security.userdetails.UserDetails;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps user (loaded from the primary user accounts repository, e.g. LDAP) to username in secondary
|
* Maps user (loaded from the primary user accounts repository, e.g. LDAP) to username in secondary
|
||||||
* user accounts repository. Tries to find user's authority with name starting with
|
* user accounts repository. Tries to find user's authority with name starting with
|
||||||
@ -53,9 +55,9 @@ public class AuthorityByPrefixAccountMapper implements AccountMapper, Initializi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// search authorities for authority prefix
|
// search authorities for authority prefix
|
||||||
GrantedAuthority[] authorities = user.getAuthorities();
|
List<GrantedAuthority> authorities = user.getAuthorities();
|
||||||
for (int i = 0; i < authorities.length; i++) {
|
for (int i = 0; i < authorities.size(); i++) {
|
||||||
String authority = authorities[i].getAuthority();
|
String authority = authorities.get(i).getAuthority();
|
||||||
if (authority.startsWith(this.getAuthorityPrefix())) {
|
if (authority.startsWith(this.getAuthorityPrefix())) {
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger.debug("Authority found=[" + authority + "]");
|
this.logger.debug("Authority found=[" + authority + "]");
|
||||||
|
@ -26,6 +26,7 @@ import org.springframework.security.userdetails.UserDetails;
|
|||||||
import org.springframework.security.userdetails.UserDetailsService;
|
import org.springframework.security.userdetails.UserDetailsService;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
/**
|
/**
|
||||||
* The context mapper used by the LDAP authentication provider to create an LDAP user object.
|
* The context mapper used by the LDAP authentication provider to create an LDAP user object.
|
||||||
* Creates the final <tt>UserDetails</tt> object that will be returned by the provider once the
|
* Creates the final <tt>UserDetails</tt> object that will be returned by the provider once the
|
||||||
@ -95,7 +96,7 @@ public class ReplacingUserDetailsMapper extends LdapUserDetailsMapper implements
|
|||||||
* the user has been authenticated, replacing the original <tt>UserDetails</tt> object.
|
* the user has been authenticated, replacing the original <tt>UserDetails</tt> object.
|
||||||
*/
|
*/
|
||||||
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
|
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
|
||||||
GrantedAuthority[] authorities) {
|
List<GrantedAuthority> authorities) {
|
||||||
UserDetails userOriginal = super.mapUserFromContext(ctx, username, authorities);
|
UserDetails userOriginal = super.mapUserFromContext(ctx, username, authorities);
|
||||||
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.springframework.security.userdetails.ldap;
|
package org.springframework.security.userdetails.ldap;
|
||||||
|
|
||||||
@ -10,16 +10,18 @@ import org.springframework.security.GrantedAuthorityImpl;
|
|||||||
import org.springframework.security.userdetails.User;
|
import org.springframework.security.userdetails.User;
|
||||||
import org.springframework.security.userdetails.UserDetails;
|
import org.springframework.security.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AuthorityByPrefixAccountMapperTest extends TestCase {
|
public class AuthorityByPrefixAccountMapperTest extends TestCase {
|
||||||
AuthorityByPrefixAccountMapper mapper;
|
AuthorityByPrefixAccountMapper mapper;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -28,7 +30,7 @@ public class AuthorityByPrefixAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
@ -43,7 +45,7 @@ public class AuthorityByPrefixAccountMapperTest extends TestCase {
|
|||||||
String expectedAuthority = "prefix1_role1";
|
String expectedAuthority = "prefix1_role1";
|
||||||
GrantedAuthority[] authorities = { new GrantedAuthorityImpl(expectedAuthority),
|
GrantedAuthority[] authorities = { new GrantedAuthorityImpl(expectedAuthority),
|
||||||
new GrantedAuthorityImpl("prefix1_role2") };
|
new GrantedAuthorityImpl("prefix1_role2") };
|
||||||
UserDetails user = new User("username1", "password1", false, authorities);
|
UserDetails user = new User("username1", "password1", false, false, false, false, Arrays.asList(authorities));
|
||||||
mapper.setAuthorityPrefix("prefix1_");
|
mapper.setAuthorityPrefix("prefix1_");
|
||||||
String authority = mapper.map(user);
|
String authority = mapper.map(user);
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ public class AuthorityByPrefixAccountMapperTest extends TestCase {
|
|||||||
public final void testAuthorityNotFoundThrowsException() {
|
public final void testAuthorityNotFoundThrowsException() {
|
||||||
String expectedAuthority = "prefix1_role1";
|
String expectedAuthority = "prefix1_role1";
|
||||||
GrantedAuthority[] authorities = { new GrantedAuthorityImpl(expectedAuthority) };
|
GrantedAuthority[] authorities = { new GrantedAuthorityImpl(expectedAuthority) };
|
||||||
UserDetails user = new User("username1", "password1", false, authorities);
|
UserDetails user = new User("username1", "password1", false, false, false, false, Arrays.asList(authorities));
|
||||||
mapper.setAuthorityPrefix("NoMatchPrefix");
|
mapper.setAuthorityPrefix("NoMatchPrefix");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -23,10 +23,11 @@ import org.springframework.security.userdetails.UsernameNotFoundException;
|
|||||||
import org.springframework.security.userdetails.memory.InMemoryDaoImpl;
|
import org.springframework.security.userdetails.memory.InMemoryDaoImpl;
|
||||||
import org.springframework.security.userdetails.memory.UserMap;
|
import org.springframework.security.userdetails.memory.UserMap;
|
||||||
import org.springframework.security.userdetails.memory.UserMapEditor;
|
import org.springframework.security.userdetails.memory.UserMapEditor;
|
||||||
|
import org.springframework.security.util.AuthorityUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReplacingUserDetailsMapperTest extends TestCase {
|
public class ReplacingUserDetailsMapperTest extends TestCase {
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ public class ReplacingUserDetailsMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -43,7 +44,7 @@ public class ReplacingUserDetailsMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
@ -118,9 +119,9 @@ public class ReplacingUserDetailsMapperTest extends TestCase {
|
|||||||
ctx.setAttributeValues("userRole", new String[] { "X", "Y", "Z" });
|
ctx.setAttributeValues("userRole", new String[] { "X", "Y", "Z" });
|
||||||
ctx.setAttributeValue("uid", "ani");
|
ctx.setAttributeValue("uid", "ani");
|
||||||
|
|
||||||
UserDetails userDetails = mapper.mapUserFromContext(ctx, "ani", new GrantedAuthority[0]);
|
UserDetails userDetails = mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES);
|
||||||
// verify that userDetails came from the secondary repository
|
// verify that userDetails came from the secondary repository
|
||||||
assertEquals("ROLE_ONE", userDetails.getAuthorities()[0].getAuthority());
|
assertEquals("ROLE_ONE", userDetails.getAuthorities().get(0).getAuthority());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +142,7 @@ public class ReplacingUserDetailsMapperTest extends TestCase {
|
|||||||
|
|
||||||
UserDetails userDetails = mapper.retrieveUser(username);
|
UserDetails userDetails = mapper.retrieveUser(username);
|
||||||
|
|
||||||
assertEquals("ROLE_ONE", userDetails.getAuthorities()[0].getAuthority());
|
assertEquals("ROLE_ONE", userDetails.getAuthorities().get(0).getAuthority());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapper.retrieveUser("noMatchUsername");
|
mapper.retrieveUser("noMatchUsername");
|
||||||
|
@ -22,7 +22,7 @@ import org.springframework.security.userdetails.UserDetails;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -39,7 +39,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
@ -52,7 +52,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public final void testNormalOperation() {
|
public final void testNormalOperation() {
|
||||||
String usernameExpected = "username1";
|
String usernameExpected = "username1";
|
||||||
UserDetails user = new User(usernameExpected, "password1", false, new GrantedAuthority[0]);
|
UserDetails user = new User(usernameExpected, "password1", false, false, false, false, new GrantedAuthority[0]);
|
||||||
mapper.setUsername(usernameExpected);
|
mapper.setUsername(usernameExpected);
|
||||||
String username = mapper.map(user);
|
String username = mapper.map(user);
|
||||||
|
|
||||||
|
@ -25,26 +25,16 @@ import org.springframework.security.userdetails.memory.UserMapEditor;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UserDetailsMappingServiceWrapperTest extends TestCase {
|
public class UserDetailsMappingServiceWrapperTest extends TestCase {
|
||||||
|
|
||||||
UserDetailsMappingServiceWrapper service;
|
UserDetailsMappingServiceWrapper service;
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see junit.framework.TestCase#setUp()
|
|
||||||
*/
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
service = new UserDetailsMappingServiceWrapper();
|
service = new UserDetailsMappingServiceWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see junit.framework.TestCase#tearDown()
|
|
||||||
*/
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
service = null;
|
service = null;
|
||||||
}
|
}
|
||||||
@ -84,11 +74,11 @@ public class UserDetailsMappingServiceWrapperTest extends TestCase {
|
|||||||
service.setUserDetailsService(dao);
|
service.setUserDetailsService(dao);
|
||||||
}
|
}
|
||||||
|
|
||||||
Authentication authentication = new TestingAuthenticationToken("any", "any", null);
|
Authentication authentication = new TestingAuthenticationToken("any", "any");
|
||||||
UserDetails user = service.loadUserDetails(authentication);
|
UserDetails user = service.loadUserDetails(authentication);
|
||||||
|
|
||||||
// verify that userDetails came from the secondary repository
|
// verify that userDetails came from the secondary repository
|
||||||
assertEquals("ROLE_ONE", user.getAuthorities()[0].getAuthority());
|
assertEquals("ROLE_ONE", user.getAuthorities().get(0).getAuthority());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,7 @@ import org.springframework.security.providers.TestingAuthenticationToken;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -38,7 +38,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
@ -51,7 +51,7 @@ public class UsernameFromPropertyAccountMapperTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public final void testNormalOperation() {
|
public final void testNormalOperation() {
|
||||||
String usernameExpected = "username1";
|
String usernameExpected = "username1";
|
||||||
Authentication authenticationRequest = new TestingAuthenticationToken("any", "any", null);
|
Authentication authenticationRequest = new TestingAuthenticationToken("any", "any");
|
||||||
mapper.setUsername(usernameExpected);
|
mapper.setUsername(usernameExpected);
|
||||||
|
|
||||||
String username = mapper.map(authenticationRequest);
|
String username = mapper.map(authenticationRequest);
|
||||||
|
@ -21,7 +21,7 @@ import org.springframework.security.providers.TestingAuthenticationToken;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Valery Tydykov
|
* @author Valery Tydykov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UsernameFromRequestAccountMapperTest extends TestCase {
|
public class UsernameFromRequestAccountMapperTest extends TestCase {
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public class UsernameFromRequestAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -38,7 +38,7 @@ public class UsernameFromRequestAccountMapperTest extends TestCase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
@ -51,8 +51,7 @@ public class UsernameFromRequestAccountMapperTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public final void testNormalOperation() {
|
public final void testNormalOperation() {
|
||||||
String usernameExpected = "username1";
|
String usernameExpected = "username1";
|
||||||
Authentication authenticationRequest = new TestingAuthenticationToken(usernameExpected,
|
Authentication authenticationRequest = new TestingAuthenticationToken(usernameExpected, "password1");
|
||||||
"password1", null);
|
|
||||||
String username = mapper.map(authenticationRequest);
|
String username = mapper.map(authenticationRequest);
|
||||||
|
|
||||||
assertEquals(usernameExpected, username);
|
assertEquals(usernameExpected, username);
|
||||||
|
@ -15,37 +15,37 @@
|
|||||||
|
|
||||||
package org.springframework.security.vote;
|
package org.springframework.security.vote;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.*;
|
||||||
|
|
||||||
import org.springframework.security.AccessDeniedException;
|
import org.springframework.security.AccessDeniedException;
|
||||||
import org.springframework.security.Authentication;
|
import org.springframework.security.Authentication;
|
||||||
import org.springframework.security.ConfigAttributeDefinition;
|
import org.springframework.security.ConfigAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccessDecisionManager which bases its result on the first non-abstention from
|
* AccessDecisionManager which bases its result on the first non-abstention from
|
||||||
* its list of voters.
|
* its list of voters.
|
||||||
*
|
*
|
||||||
* @author Janning Vygen
|
* @author Janning Vygen
|
||||||
*/
|
*/
|
||||||
public class FirstDecisionBased extends AbstractAccessDecisionManager {
|
public class FirstDecisionBased extends AbstractAccessDecisionManager {
|
||||||
|
|
||||||
public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config ) throws AccessDeniedException {
|
public void decide(Authentication authentication, Object object, List<ConfigAttribute> config ) throws AccessDeniedException {
|
||||||
Iterator voters = this.getDecisionVoters().iterator();
|
Iterator voters = this.getDecisionVoters().iterator();
|
||||||
|
|
||||||
while (voters.hasNext()) {
|
while (voters.hasNext()) {
|
||||||
AccessDecisionVoter voter = (AccessDecisionVoter) voters.next();
|
AccessDecisionVoter voter = (AccessDecisionVoter) voters.next();
|
||||||
int result = voter.vote(authentication, object, config);
|
int result = voter.vote(authentication, object, config);
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case AccessDecisionVoter.ACCESS_GRANTED:
|
case AccessDecisionVoter.ACCESS_GRANTED:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case AccessDecisionVoter.ACCESS_DENIED:
|
case AccessDecisionVoter.ACCESS_DENIED:
|
||||||
throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied", "Access is denied"));
|
throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied", "Access is denied"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To get this far, every AccessDecisionVoter abstained
|
// To get this far, every AccessDecisionVoter abstained
|
||||||
checkAllowIfAllAbstainDecisions();
|
checkAllowIfAllAbstainDecisions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user