NIHVIVO-2694 Make it easier to change the AuthenticatorFactory
This commit is contained in:
parent
2c2151a0f2
commit
b0649849ce
2 changed files with 24 additions and 2 deletions
|
@ -14,6 +14,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ActiveIdentifierBundleFactories;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
|
||||
/**
|
||||
|
@ -57,14 +59,19 @@ public abstract class Authenticator {
|
|||
ServletContext ctx = request.getSession().getServletContext();
|
||||
Object attribute = ctx.getAttribute(FACTORY_ATTRIBUTE_NAME);
|
||||
if (!(attribute instanceof AuthenticatorFactory)) {
|
||||
attribute = new BasicAuthenticator.Factory();
|
||||
ctx.setAttribute(FACTORY_ATTRIBUTE_NAME, attribute);
|
||||
setAuthenticatorFactory(new BasicAuthenticator.Factory(), ctx);
|
||||
attribute = ctx.getAttribute(FACTORY_ATTRIBUTE_NAME);
|
||||
}
|
||||
AuthenticatorFactory factory = (AuthenticatorFactory) attribute;
|
||||
|
||||
return factory.getInstance(request);
|
||||
}
|
||||
|
||||
public static void setAuthenticatorFactory(AuthenticatorFactory factory,
|
||||
ServletContext ctx) {
|
||||
ctx.setAttribute(FACTORY_ATTRIBUTE_NAME, factory);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The interface.
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -200,6 +207,16 @@ public abstract class Authenticator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IDs that would be created for this userAccount, if this user were
|
||||
* to log in.
|
||||
*/
|
||||
public static IdentifierBundle getIdsForUserAccount(HttpServletRequest req,
|
||||
UserAccount userAccount) {
|
||||
return ActiveIdentifierBundleFactories.getUserIdentifierBundle(req,
|
||||
userAccount);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Exceptions
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -312,4 +312,9 @@ public class BasicAuthenticator extends Authenticator {
|
|||
return wadf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BasicAuthenticator[" + request + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue