diff --git a/core/src/main/java/org/springframework/security/ui/AuthenticationDetails.java b/core/src/main/java/org/springframework/security/ui/AuthenticationDetails.java new file mode 100755 index 0000000000..831f4a077b --- /dev/null +++ b/core/src/main/java/org/springframework/security/ui/AuthenticationDetails.java @@ -0,0 +1,81 @@ +package org.springframework.security.ui; + +import java.io.Serializable; + +/** +* A holder of the context as a string. +* +* @author Ruud Senden +* @since 2.0 +*/ +public class AuthenticationDetails implements Serializable { + //~ Instance fields ================================================================================================ + + private String context; + + //~ Constructors =================================================================================================== + + /** + * Constructor. + * + * @param context that the authentication request is initiated from + */ + public AuthenticationDetails(Object context) { + this.context = context==null?"":context.toString(); + doPopulateAdditionalInformation(context); + } + + protected AuthenticationDetails() { + throw new IllegalArgumentException("Cannot use default constructor"); + } + + //~ Methods ======================================================================================================== + + /** + * Provided so that subclasses can populate additional information. + * + * @param request that the authentication request was received from + */ + protected void doPopulateAdditionalInformation(Object context) {} + + public boolean equals(Object obj) { + if (obj instanceof AuthenticationDetails) { + AuthenticationDetails rhs = (AuthenticationDetails) obj; + + if ((context == null) && (rhs.getContext() != null)) { + return false; + } + + if ((context != null) && (rhs.getContext() == null)) { + return false; + } + + if (context != null) { + if (!context.equals(rhs.getContext())) { + return false; + } + } + + return true; + } + + return false; + } + + /** + * Indicates the context. + * + * @return the address + */ + public String getContext() { + return context; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(super.toString() + ": "); + sb.append("Context: " + this.getContext()); + + return sb.toString(); + } +} diff --git a/core/src/main/java/org/springframework/security/ui/AuthenticationDetailsSourceImpl.java b/core/src/main/java/org/springframework/security/ui/AuthenticationDetailsSourceImpl.java new file mode 100755 index 0000000000..2508cd6abb --- /dev/null +++ b/core/src/main/java/org/springframework/security/ui/AuthenticationDetailsSourceImpl.java @@ -0,0 +1,81 @@ +package org.springframework.security.ui; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import org.springframework.security.ui.AuthenticationDetailsSource; +import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; + +/** + * Base implementation of {@link AuthenticationDetailsSource}. + *
+ * By default will create an instance of AuthenticationDetails.
+ * Any object that accepts an Object as its sole constructor can
+ * be used instead of this default.
+ *