mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 13:53:14 +00:00
SEC-1481: Updated constructors of Authentication types to use a generic wildcard for authorities collection.
This commit is contained in:
parent
c95cf6ec7d
commit
0e57ce2dc3
@ -59,7 +59,7 @@ public class CasAuthenticationToken extends AbstractAuthenticationToken implemen
|
|||||||
* @throws IllegalArgumentException if a <code>null</code> was passed
|
* @throws IllegalArgumentException if a <code>null</code> was passed
|
||||||
*/
|
*/
|
||||||
public CasAuthenticationToken(final String key, final Object principal, final Object credentials,
|
public CasAuthenticationToken(final String key, final Object principal, final Object credentials,
|
||||||
final Collection<GrantedAuthority> authorities, final UserDetails userDetails, final Assertion assertion) {
|
final Collection<? extends GrantedAuthority> authorities, final UserDetails userDetails, final Assertion assertion) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
|
|
||||||
if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal) || (credentials == null)
|
if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal) || (credentials == null)
|
||||||
|
@ -49,7 +49,7 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||||||
* @param authorities the collection of <tt>GrantedAuthority</tt>s for the
|
* @param authorities the collection of <tt>GrantedAuthority</tt>s for the
|
||||||
* principal represented by this authentication object.
|
* principal represented by this authentication object.
|
||||||
*/
|
*/
|
||||||
public AbstractAuthenticationToken(Collection<GrantedAuthority> authorities) {
|
public AbstractAuthenticationToken(Collection<? extends GrantedAuthority> authorities) {
|
||||||
if (authorities == null) {
|
if (authorities == null) {
|
||||||
this.authorities = AuthorityUtils.NO_AUTHORITIES;
|
this.authorities = AuthorityUtils.NO_AUTHORITIES;
|
||||||
return;
|
return;
|
||||||
@ -67,6 +67,39 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
public Collection<GrantedAuthority> getAuthorities() {
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
if (this.getPrincipal() instanceof UserDetails) {
|
||||||
|
return ((UserDetails) this.getPrincipal()).getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getPrincipal() instanceof Principal) {
|
||||||
|
return ((Principal)getPrincipal()).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.getPrincipal() == null) ? "" : this.getPrincipal().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthenticated() {
|
||||||
|
return authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthenticated(boolean authenticated) {
|
||||||
|
this.authenticated = authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDetails(Object details) {
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof AbstractAuthenticationToken)) {
|
if (!(obj instanceof AbstractAuthenticationToken)) {
|
||||||
return false;
|
return false;
|
||||||
@ -109,26 +142,7 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||||||
return this.isAuthenticated() == test.isAuthenticated();
|
return this.isAuthenticated() == test.isAuthenticated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<GrantedAuthority> getAuthorities() {
|
@Override
|
||||||
return authorities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getDetails() {
|
|
||||||
return details;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
if (this.getPrincipal() instanceof UserDetails) {
|
|
||||||
return ((UserDetails) this.getPrincipal()).getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getPrincipal() instanceof Principal) {
|
|
||||||
return ((Principal)getPrincipal()).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (this.getPrincipal() == null) ? "" : this.getPrincipal().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int code = 31;
|
int code = 31;
|
||||||
|
|
||||||
@ -155,18 +169,7 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthenticated() {
|
@Override
|
||||||
return authenticated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthenticated(boolean authenticated) {
|
|
||||||
this.authenticated = authenticated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDetails(Object details) {
|
|
||||||
this.details = details;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(super.toString()).append(": ");
|
sb.append(super.toString()).append(": ");
|
||||||
|
@ -46,7 +46,7 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken i
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if a <code>null</code> was passed
|
* @throws IllegalArgumentException if a <code>null</code> was passed
|
||||||
*/
|
*/
|
||||||
public RememberMeAuthenticationToken(String key, Object principal, Collection<GrantedAuthority> authorities) {
|
public RememberMeAuthenticationToken(String key, Object principal, Collection<? extends GrantedAuthority> authorities) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
|
|
||||||
if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal)) {
|
if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal)) {
|
||||||
@ -60,6 +60,23 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken i
|
|||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Always returns an empty <code>String</code>
|
||||||
|
*
|
||||||
|
* @return an empty String
|
||||||
|
*/
|
||||||
|
public Object getCredentials() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKeyHash() {
|
||||||
|
return this.keyHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getPrincipal() {
|
||||||
|
return this.principal;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!super.equals(obj)) {
|
if (!super.equals(obj)) {
|
||||||
return false;
|
return false;
|
||||||
@ -78,20 +95,4 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken i
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Always returns an empty <code>String</code>
|
|
||||||
*
|
|
||||||
* @return an empty String
|
|
||||||
*/
|
|
||||||
public Object getCredentials() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getKeyHash() {
|
|
||||||
return this.keyHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getPrincipal() {
|
|
||||||
return this.principal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationT
|
|||||||
* @param credentials
|
* @param credentials
|
||||||
* @param authorities
|
* @param authorities
|
||||||
*/
|
*/
|
||||||
public UsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<GrantedAuthority> authorities) {
|
public UsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
|
@ -55,7 +55,7 @@ public class OpenIDAuthenticationToken extends AbstractAuthenticationToken {
|
|||||||
* used by the <tt>OpenIDAuthenticationProvider</tt>.
|
* used by the <tt>OpenIDAuthenticationProvider</tt>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public OpenIDAuthenticationToken(Object principal, Collection<GrantedAuthority> authorities,
|
public OpenIDAuthenticationToken(Object principal, Collection<? extends GrantedAuthority> authorities,
|
||||||
String identityUrl, List<OpenIDAttribute> attributes) {
|
String identityUrl, List<OpenIDAttribute> attributes) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
|
@ -44,7 +44,7 @@ public class PreAuthenticatedAuthenticationToken extends AbstractAuthenticationT
|
|||||||
* @param anAuthorities
|
* @param anAuthorities
|
||||||
* The granted authorities
|
* The granted authorities
|
||||||
*/
|
*/
|
||||||
public PreAuthenticatedAuthenticationToken(Object aPrincipal, Object aCredentials, Collection<GrantedAuthority> anAuthorities) {
|
public PreAuthenticatedAuthenticationToken(Object aPrincipal, Object aCredentials, Collection<? extends GrantedAuthority> anAuthorities) {
|
||||||
super(anAuthorities);
|
super(anAuthorities);
|
||||||
this.principal = aPrincipal;
|
this.principal = aPrincipal;
|
||||||
this.credentials = aCredentials;
|
this.credentials = aCredentials;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user