mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 14:22:47 +00:00
Store additional information about the authentication request.
This commit is contained in:
parent
b6e0c3076f
commit
42ccbfbad7
@ -71,6 +71,15 @@ public interface Authentication extends Principal {
|
|||||||
*/
|
*/
|
||||||
public Object getCredentials();
|
public Object getCredentials();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores additional details about the authentication request. These might
|
||||||
|
* be an IP address, certificate serial number etc.
|
||||||
|
*
|
||||||
|
* @return additional details about the authentication request, or
|
||||||
|
* <code>null</code> if not used
|
||||||
|
*/
|
||||||
|
public Object getDetails();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The identity of the principal being authenticated. This is usually a
|
* The identity of the principal being authenticated. This is usually a
|
||||||
* username. Callers are expected to populate the principal.
|
* username. Callers are expected to populate the principal.
|
||||||
|
@ -27,6 +27,16 @@ import net.sf.acegisecurity.Authentication;
|
|||||||
public abstract class AbstractAuthenticationToken implements Authentication {
|
public abstract class AbstractAuthenticationToken implements Authentication {
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclasses should override if they wish to provide additional details
|
||||||
|
* about the authentication event.
|
||||||
|
*
|
||||||
|
* @return always <code>null</code>
|
||||||
|
*/
|
||||||
|
public Object getDetails() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.getPrincipal().toString();
|
return this.getPrincipal().toString();
|
||||||
}
|
}
|
||||||
@ -68,6 +78,7 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||||||
sb.append("Username: " + this.getPrincipal() + "; ");
|
sb.append("Username: " + this.getPrincipal() + "; ");
|
||||||
sb.append("Password: [PROTECTED]; ");
|
sb.append("Password: [PROTECTED]; ");
|
||||||
sb.append("Authenticated: " + this.isAuthenticated() + "; ");
|
sb.append("Authenticated: " + this.isAuthenticated() + "; ");
|
||||||
|
sb.append("Details: " + this.getDetails() + "; ");
|
||||||
|
|
||||||
if (this.getAuthorities() != null) {
|
if (this.getAuthorities() != null) {
|
||||||
sb.append("Granted Authorities: ");
|
sb.append("Granted Authorities: ");
|
||||||
|
@ -40,6 +40,7 @@ public class UsernamePasswordAuthenticationToken
|
|||||||
private Object principal;
|
private Object principal;
|
||||||
private GrantedAuthority[] authorities;
|
private GrantedAuthority[] authorities;
|
||||||
private boolean authenticated = false;
|
private boolean authenticated = false;
|
||||||
|
private String details = null;
|
||||||
|
|
||||||
//~ Constructors ===========================================================
|
//~ Constructors ===========================================================
|
||||||
|
|
||||||
@ -85,4 +86,12 @@ public class UsernamePasswordAuthenticationToken
|
|||||||
public Object getPrincipal() {
|
public Object getPrincipal() {
|
||||||
return this.principal;
|
return this.principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDetails(String details) {
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ public class BasicProcessingFilter implements Filter, InitializingBean {
|
|||||||
|
|
||||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
||||||
password);
|
password);
|
||||||
|
authRequest.setDetails(httpRequest.getRemoteAddr());
|
||||||
|
|
||||||
Authentication authResult;
|
Authentication authResult;
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ public class CasProcessingFilter extends AbstractProcessingFilter {
|
|||||||
|
|
||||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
||||||
password);
|
password);
|
||||||
|
authRequest.setDetails(request.getRemoteAddr());
|
||||||
|
|
||||||
return this.getAuthenticationManager().authenticate(authRequest);
|
return this.getAuthenticationManager().authenticate(authRequest);
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ public class AuthenticationProcessingFilter extends AbstractProcessingFilter {
|
|||||||
|
|
||||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
||||||
password);
|
password);
|
||||||
|
authRequest.setDetails(request.getRemoteAddr());
|
||||||
|
|
||||||
return this.getAuthenticationManager().authenticate(authRequest);
|
return this.getAuthenticationManager().authenticate(authRequest);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user