1
0
mirror of synced 2026-08-01 07:47:03 +00:00

SEC-1183: Modified Attributes2GrantedAuthoritiesMapper to return Collection<? extends GrantedAuthority>.

This commit is contained in:
Luke Taylor
2010-11-02 14:02:55 +00:00
parent 84efffb937
commit 43ec2beec0
14 changed files with 63 additions and 96 deletions
@@ -1,7 +1,6 @@
package org.springframework.security.web.authentication.preauth;
import java.util.Collections;
import java.util.List;
import java.util.*;
import org.springframework.security.authentication.AuthenticationDetails;
import org.springframework.security.core.GrantedAuthority;
@@ -37,10 +36,12 @@ public class PreAuthenticatedGrantedAuthoritiesAuthenticationDetails extends Aut
}
/**
* @see MutableGrantedAuthoritiesContainer#setGrantedAuthorities(List)
* @see MutableGrantedAuthoritiesContainer#setGrantedAuthorities(Collection)
*/
public void setGrantedAuthorities(List<GrantedAuthority> aJ2eeBasedGrantedAuthorities) {
this.preAuthenticatedGrantedAuthorities = Collections.unmodifiableList(aJ2eeBasedGrantedAuthorities);
public void setGrantedAuthorities(Collection<? extends GrantedAuthority> aJ2eeBasedGrantedAuthorities) {
List<GrantedAuthority> temp = new ArrayList<GrantedAuthority>(aJ2eeBasedGrantedAuthorities.size());
temp.addAll(aJ2eeBasedGrantedAuthorities);
this.preAuthenticatedGrantedAuthorities = Collections.unmodifiableList(temp);
}
/**
@@ -48,8 +49,8 @@ public class PreAuthenticatedGrantedAuthoritiesAuthenticationDetails extends Aut
*/
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString() + "; ");
sb.append("preAuthenticatedGrantedAuthorities: " + preAuthenticatedGrantedAuthorities);
sb.append(super.toString()).append("; ");
sb.append("preAuthenticatedGrantedAuthorities: ").append(preAuthenticatedGrantedAuthorities);
return sb.toString();
}
}
@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth;
import java.util.List;
import java.util.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
@@ -41,7 +41,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsService
public final UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
Assert.notNull(token.getDetails());
Assert.isInstanceOf(GrantedAuthoritiesContainer.class, token.getDetails());
List<GrantedAuthority> authorities = ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
Collection<? extends GrantedAuthority> authorities = ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
return createuserDetails(token, authorities);
}
@@ -51,7 +51,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsService
* @param token the authentication request token
* @param authorities the pre-authenticated authorities.
*/
protected UserDetails createuserDetails(Authentication token, List<GrantedAuthority> authorities) {
protected UserDetails createuserDetails(Authentication token, Collection<? extends GrantedAuthority> authorities) {
return new User(token.getName(), "N/A", true, true, true, true, authorities);
}
}
@@ -5,9 +5,7 @@ import org.springframework.security.core.authority.GrantedAuthoritiesContainer;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
/**
* This WebAuthenticationDetails implementation allows for storing a list of
@@ -23,7 +21,7 @@ public class PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails extends
private final List<GrantedAuthority> authorities;
public PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(HttpServletRequest request,
List<GrantedAuthority> authorities) {
Collection<? extends GrantedAuthority> authorities) {
super(request);
List<GrantedAuthority> temp = new ArrayList<GrantedAuthority>(authorities.size());
@@ -68,7 +68,7 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource
public PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails buildDetails(HttpServletRequest context) {
Collection<String> j2eeUserRoles = getUserRoles(context);
List<GrantedAuthority> userGas = j2eeUserRoles2GrantedAuthoritiesMapper.getGrantedAuthorities(j2eeUserRoles);
Collection<? extends GrantedAuthority> userGas = j2eeUserRoles2GrantedAuthoritiesMapper.getGrantedAuthorities(j2eeUserRoles);
if (logger.isDebugEnabled()) {
logger.debug("J2EE roles [" + j2eeUserRoles + "] mapped to Granted Authorities: [" + userGas + "]");
@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth.websphere;
import java.util.List;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -73,9 +73,9 @@ public class WebSpherePreAuthenticatedAuthenticationDetailsSource extends Authen
*
* @return authorities mapped from the user's WebSphere groups.
*/
private List<GrantedAuthority> getWebSphereGroupsBasedGrantedAuthorities() {
private Collection<? extends GrantedAuthority> getWebSphereGroupsBasedGrantedAuthorities() {
List<String> webSphereGroups = wasHelper.getGroupsForCurrentUser();
List<GrantedAuthority> userGas = webSphereGroups2GrantedAuthoritiesMapper.getGrantedAuthorities(webSphereGroups);
Collection<? extends GrantedAuthority> userGas = webSphereGroups2GrantedAuthoritiesMapper.getGrantedAuthorities(webSphereGroups);
if (logger.isDebugEnabled()) {
logger.debug("WebSphere groups: " + webSphereGroups + " mapped to Granted Authorities: " + userGas);
}
@@ -9,7 +9,7 @@ import org.springframework.security.core.authority.mapping.SimpleAttributes2Gran
import org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.*;
/**
* This AuthenticationDetailsSource implementation will set the pre-authenticated granted
@@ -43,9 +43,9 @@ public class WebSpherePreAuthenticatedWebAuthenticationDetailsSource implements
*
* @return authorities mapped from the user's WebSphere groups.
*/
private List<GrantedAuthority> getWebSphereGroupsBasedGrantedAuthorities() {
private Collection<? extends GrantedAuthority> getWebSphereGroupsBasedGrantedAuthorities() {
List<String> webSphereGroups = wasHelper.getGroupsForCurrentUser();
List<GrantedAuthority> userGas = webSphereGroups2GrantedAuthoritiesMapper.getGrantedAuthorities(webSphereGroups);
Collection<? extends GrantedAuthority> userGas = webSphereGroups2GrantedAuthoritiesMapper.getGrantedAuthorities(webSphereGroups);
if (logger.isDebugEnabled()) {
logger.debug("WebSphere groups: " + webSphereGroups + " mapped to Granted Authorities: " + userGas);
}
@@ -2,15 +2,13 @@ package org.springframework.security.web.authentication.preauth;
import static org.junit.Assert.*;
import java.util.List;
import java.util.*;
import org.junit.Test;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.authority.GrantedAuthoritiesContainer;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService;
/**
*
@@ -51,7 +49,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests {
PreAuthenticatedGrantedAuthoritiesUserDetailsService svc = new PreAuthenticatedGrantedAuthoritiesUserDetailsService();
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(userName, "dummy");
token.setDetails(new GrantedAuthoritiesContainer() {
public List<GrantedAuthority> getGrantedAuthorities() {
public Collection<? extends GrantedAuthority> getGrantedAuthorities() {
return gas;
}
});