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();
|
||||
|
||||
/**
|
||||
* 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
|
||||
* username. Callers are expected to populate the principal.
|
||||
|
|
|
@ -27,6 +27,16 @@ import net.sf.acegisecurity.Authentication;
|
|||
public abstract class AbstractAuthenticationToken implements Authentication {
|
||||
//~ 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() {
|
||||
return this.getPrincipal().toString();
|
||||
}
|
||||
|
@ -68,6 +78,7 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
|||
sb.append("Username: " + this.getPrincipal() + "; ");
|
||||
sb.append("Password: [PROTECTED]; ");
|
||||
sb.append("Authenticated: " + this.isAuthenticated() + "; ");
|
||||
sb.append("Details: " + this.getDetails() + "; ");
|
||||
|
||||
if (this.getAuthorities() != null) {
|
||||
sb.append("Granted Authorities: ");
|
||||
|
|
|
@ -40,6 +40,7 @@ public class UsernamePasswordAuthenticationToken
|
|||
private Object principal;
|
||||
private GrantedAuthority[] authorities;
|
||||
private boolean authenticated = false;
|
||||
private String details = null;
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
|
||||
|
@ -85,4 +86,12 @@ public class UsernamePasswordAuthenticationToken
|
|||
public Object getPrincipal() {
|
||||
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,
|
||||
password);
|
||||
authRequest.setDetails(httpRequest.getRemoteAddr());
|
||||
|
||||
Authentication authResult;
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public class CasProcessingFilter extends AbstractProcessingFilter {
|
|||
|
||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
||||
password);
|
||||
authRequest.setDetails(request.getRemoteAddr());
|
||||
|
||||
return this.getAuthenticationManager().authenticate(authRequest);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ public class AuthenticationProcessingFilter extends AbstractProcessingFilter {
|
|||
|
||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
|
||||
password);
|
||||
authRequest.setDetails(request.getRemoteAddr());
|
||||
|
||||
return this.getAuthenticationManager().authenticate(authRequest);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue