NIHVIVO-2694 Devise a way to determine what Identifiers would be created if a particular user were to log in.
This commit is contained in:
parent
cb4f07af47
commit
12fe9f9da3
10 changed files with 126 additions and 53 deletions
|
@ -8,7 +8,8 @@ import java.util.List;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep a list of the active IdentifierBundleFactories in the context.
|
* Keep a list of the active IdentifierBundleFactories in the context.
|
||||||
|
@ -50,14 +51,15 @@ public class ActiveIdentifierBundleFactories {
|
||||||
|
|
||||||
getActiveFactories(ctx).addFactory(factory);
|
getActiveFactories(ctx).addFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just for diagnostics. Don't expose the factories themselves, only their names.
|
* Just for diagnostics. Don't expose the factories themselves, only their
|
||||||
|
* names.
|
||||||
*/
|
*/
|
||||||
public static List<String> getFactoryNames(ServletContext ctx) {
|
public static List<String> getFactoryNames(ServletContext ctx) {
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
ActiveIdentifierBundleFactories actFact = getActiveFactories(ctx);
|
ActiveIdentifierBundleFactories actFact = getActiveFactories(ctx);
|
||||||
for (IdentifierBundleFactory factory: actFact.factories) {
|
for (IdentifierBundleFactory factory : actFact.factories) {
|
||||||
names.add(factory.toString());
|
names.add(factory.toString());
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
@ -72,10 +74,28 @@ public class ActiveIdentifierBundleFactories {
|
||||||
* request.
|
* request.
|
||||||
*/
|
*/
|
||||||
static IdentifierBundle getIdentifierBundle(HttpServletRequest request) {
|
static IdentifierBundle getIdentifierBundle(HttpServletRequest request) {
|
||||||
HttpSession session = request.getSession();
|
return getActiveFactories(request).getBundleForRequest(request);
|
||||||
ServletContext ctx = session.getServletContext();
|
}
|
||||||
return getActiveFactories(ctx).getIdentifierBundle(request, session,
|
|
||||||
ctx);
|
/**
|
||||||
|
* Get the Identifiers that would be created if this user were to log in.
|
||||||
|
*/
|
||||||
|
public static IdentifierBundle getUserIdentifierBundle(
|
||||||
|
HttpServletRequest request, UserAccount userAccount) {
|
||||||
|
return getActiveFactories(request).getBundleForUser(userAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the singleton instance from the servlet context. If there isn't one,
|
||||||
|
* create one. This never returns null.
|
||||||
|
*/
|
||||||
|
private static ActiveIdentifierBundleFactories getActiveFactories(
|
||||||
|
HttpServletRequest req) {
|
||||||
|
if (req == null) {
|
||||||
|
throw new NullPointerException("req may not be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getActiveFactories(req.getSession().getServletContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,15 +138,26 @@ public class ActiveIdentifierBundleFactories {
|
||||||
* Run through the active factories and get all Identifiers for this
|
* Run through the active factories and get all Identifiers for this
|
||||||
* request.
|
* request.
|
||||||
*/
|
*/
|
||||||
private IdentifierBundle getIdentifierBundle(HttpServletRequest request,
|
private IdentifierBundle getBundleForRequest(HttpServletRequest request) {
|
||||||
HttpSession session, ServletContext ctx) {
|
|
||||||
IdentifierBundle ib = new ArrayIdentifierBundle();
|
IdentifierBundle ib = new ArrayIdentifierBundle();
|
||||||
for (IdentifierBundleFactory ibf : factories) {
|
for (IdentifierBundleFactory ibf : factories) {
|
||||||
IdentifierBundle obj = ibf.getIdentifierBundle(request);
|
ib.addAll(ibf.getIdentifierBundle(request));
|
||||||
if (obj != null) {
|
}
|
||||||
ib.addAll(obj);
|
return ib;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Identifiers that would be created if this User logged in.
|
||||||
|
*/
|
||||||
|
private IdentifierBundle getBundleForUser(UserAccount userAccount) {
|
||||||
|
IdentifierBundle ib = new ArrayIdentifierBundle();
|
||||||
|
for (IdentifierBundleFactory ibf : factories) {
|
||||||
|
if (ibf instanceof UserBasedIdentifierBundleFactory) {
|
||||||
|
UserBasedIdentifierBundleFactory ubibf = (UserBasedIdentifierBundleFactory) ibf;
|
||||||
|
ib.addAll(ubibf.getIdentifierBundleForUser(userAccount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ib;
|
return ib;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an IdentifierBundle based only on the characteristics of the current
|
||||||
|
* user, without considering other aspects of the current request.
|
||||||
|
*/
|
||||||
|
public interface UserBasedIdentifierBundleFactory extends
|
||||||
|
IdentifierBundleFactory {
|
||||||
|
/**
|
||||||
|
* Get the IdentifierBundle for this user. If user is null, return an empty
|
||||||
|
* bundle. Never returns null.
|
||||||
|
*/
|
||||||
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserBasedIdentifierBundleFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some fields and methods that are helpful to IdentifierBundleFactory classes.
|
||||||
|
*/
|
||||||
|
public abstract class BaseUserBasedIdentifierBundleFactory extends
|
||||||
|
BaseIdentifierBundleFactory implements UserBasedIdentifierBundleFactory {
|
||||||
|
|
||||||
|
public BaseUserBasedIdentifierBundleFactory(ServletContext ctx) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IdentifierBundle getIdentifierBundle(HttpServletRequest request) {
|
||||||
|
return getIdentifierBundleForUser(LoginStatusBean
|
||||||
|
.getCurrentUser(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract IdentifierBundle getIdentifierBundleForUser(UserAccount user);
|
||||||
|
|
||||||
|
}
|
|
@ -9,12 +9,10 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasPermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasPermission;
|
||||||
|
@ -26,7 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
/**
|
/**
|
||||||
* Figure out what Permissions the user is entitled to have.
|
* Figure out what Permissions the user is entitled to have.
|
||||||
*/
|
*/
|
||||||
public class HasPermissionFactory extends BaseIdentifierBundleFactory {
|
public class HasPermissionFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(HasPermissionFactory.class);
|
.getLog(HasPermissionFactory.class);
|
||||||
|
|
||||||
|
@ -35,8 +33,7 @@ public class HasPermissionFactory extends BaseIdentifierBundleFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return createPublicPermissions();
|
return createPublicPermissions();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasPermissionSet;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasPermissionSet;
|
||||||
|
@ -18,7 +16,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
/**
|
/**
|
||||||
* Figure out what PermissionSets the user is entitled to have.
|
* Figure out what PermissionSets the user is entitled to have.
|
||||||
*/
|
*/
|
||||||
public class HasPermissionSetFactory extends BaseIdentifierBundleFactory {
|
public class HasPermissionSetFactory extends
|
||||||
|
BaseUserBasedIdentifierBundleFactory {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(HasPermissionFactory.class);
|
.getLog(HasPermissionFactory.class);
|
||||||
|
|
||||||
|
@ -27,12 +26,10 @@ public class HasPermissionSetFactory extends BaseIdentifierBundleFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
IdentifierBundle ids = new ArrayIdentifierBundle();
|
IdentifierBundle ids = new ArrayIdentifierBundle();
|
||||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
for (String psUri : user.getPermissionSetUris()) {
|
||||||
for (String psUri: user.getPermissionSetUris()) {
|
|
||||||
PermissionSet ps = uaDao.getPermissionSetByUri(psUri);
|
PermissionSet ps = uaDao.getPermissionSetByUri(psUri);
|
||||||
if (ps != null) {
|
if (ps != null) {
|
||||||
ids.add(new HasPermissionSet(ps));
|
ids.add(new HasPermissionSet(ps));
|
||||||
|
|
|
@ -6,12 +6,10 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
|
@ -26,7 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
* create either an IsBlacklisted or HasAssociatedIndividual for each one.
|
* create either an IsBlacklisted or HasAssociatedIndividual for each one.
|
||||||
*/
|
*/
|
||||||
public class HasProfileOrIsBlacklistedFactory extends
|
public class HasProfileOrIsBlacklistedFactory extends
|
||||||
BaseIdentifierBundleFactory {
|
BaseUserBasedIdentifierBundleFactory {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(HasProfileOrIsBlacklistedFactory.class);
|
.getLog(HasProfileOrIsBlacklistedFactory.class);
|
||||||
|
|
||||||
|
@ -35,10 +33,10 @@ public class HasProfileOrIsBlacklistedFactory extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
||||||
|
|
||||||
for (Individual ind : getAssociatedIndividuals(req)) {
|
for (Individual ind : getAssociatedIndividuals(user)) {
|
||||||
// If they are blacklisted, this factory will return an identifier
|
// If they are blacklisted, this factory will return an identifier
|
||||||
Identifier id = IsBlacklisted.getInstance(ind, ctx);
|
Identifier id = IsBlacklisted.getInstance(ind, ctx);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
@ -54,17 +52,15 @@ public class HasProfileOrIsBlacklistedFactory extends
|
||||||
/**
|
/**
|
||||||
* Get all Individuals associated with the current user as SELF.
|
* Get all Individuals associated with the current user as SELF.
|
||||||
*/
|
*/
|
||||||
private Collection<Individual> getAssociatedIndividuals(
|
private Collection<Individual> getAssociatedIndividuals(UserAccount user) {
|
||||||
HttpServletRequest req) {
|
|
||||||
Collection<Individual> individuals = new ArrayList<Individual>();
|
Collection<Individual> individuals = new ArrayList<Individual>();
|
||||||
|
|
||||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
log.debug("No Associated Individuals: not logged in.");
|
log.debug("No Associated Individuals: not logged in.");
|
||||||
return individuals;
|
return individuals;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(req);
|
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(ctx);
|
||||||
individuals.addAll(sec.getAssociatedIndividuals(indDao, user));
|
individuals.addAll(sec.getAssociatedIndividuals(indDao, user));
|
||||||
|
|
||||||
return individuals;
|
return individuals;
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProxyEditingRights;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProxyEditingRights;
|
||||||
|
@ -14,17 +12,17 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
/**
|
/**
|
||||||
* Find out what Profiles the User can edit through proxy.
|
* Find out what Profiles the User can edit through proxy.
|
||||||
*/
|
*/
|
||||||
public class HasProxyEditingRightsFactory extends BaseIdentifierBundleFactory {
|
public class HasProxyEditingRightsFactory extends
|
||||||
|
BaseUserBasedIdentifierBundleFactory {
|
||||||
|
|
||||||
public HasProxyEditingRightsFactory(ServletContext ctx) {
|
public HasProxyEditingRightsFactory(ServletContext ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
||||||
|
|
||||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
for (String proxiedUri : user.getProxiedIndividualUris()) {
|
for (String proxiedUri : user.getProxiedIndividualUris()) {
|
||||||
ids.add(new HasProxyEditingRights(proxiedUri));
|
ids.add(new HasProxyEditingRights(proxiedUri));
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser;
|
||||||
|
@ -14,15 +12,14 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
/**
|
/**
|
||||||
* If the user is logged in as a Root User, create an identifier.
|
* If the user is logged in as a Root User, create an identifier.
|
||||||
*/
|
*/
|
||||||
public class IsRootUserFactory extends BaseIdentifierBundleFactory {
|
public class IsRootUserFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||||
|
|
||||||
public IsRootUserFactory(ServletContext ctx) {
|
public IsRootUserFactory(ServletContext ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
|
||||||
if ((user != null) && user.isRootUser()) {
|
if ((user != null) && user.isRootUser()) {
|
||||||
return new ArrayIdentifierBundle(IsRootUser.INSTANCE);
|
return new ArrayIdentifierBundle(IsRootUser.INSTANCE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,4 +28,3 @@ public class IsRootUserFactory extends BaseIdentifierBundleFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,29 +3,27 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the user is logged in, create an Identifier.
|
* If the user is logged in, create an Identifier.
|
||||||
*/
|
*/
|
||||||
public class IsUserFactory extends BaseIdentifierBundleFactory {
|
public class IsUserFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||||
|
|
||||||
public IsUserFactory(ServletContext ctx) {
|
public IsUserFactory(ServletContext ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||||
LoginStatusBean bean = LoginStatusBean.getBean(req);
|
if (user == null) {
|
||||||
if (bean.isLoggedIn()) {
|
|
||||||
return new ArrayIdentifierBundle(new IsUser(bean.getUserURI()));
|
|
||||||
} else {
|
|
||||||
return new ArrayIdentifierBundle();
|
return new ArrayIdentifierBundle();
|
||||||
|
} else {
|
||||||
|
return new ArrayIdentifierBundle(new IsUser(user.getUri()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||||
import stubs.javax.servlet.ServletContextStub;
|
import stubs.javax.servlet.ServletContextStub;
|
||||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||||
|
@ -17,6 +18,7 @@ import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The simplest of the IdentifierBundleFactory classes.
|
* The simplest of the IdentifierBundleFactory classes.
|
||||||
|
@ -25,6 +27,7 @@ public class IsUserFactoryTest extends AbstractTestClass {
|
||||||
private static final String USER_URI = "http://userUri";
|
private static final String USER_URI = "http://userUri";
|
||||||
|
|
||||||
private WebappDaoFactoryStub wdf;
|
private WebappDaoFactoryStub wdf;
|
||||||
|
private UserAccountsDaoStub uaDao;
|
||||||
|
|
||||||
private ServletContextStub ctx;
|
private ServletContextStub ctx;
|
||||||
private HttpSessionStub session;
|
private HttpSessionStub session;
|
||||||
|
@ -37,7 +40,10 @@ public class IsUserFactoryTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
uaDao = new UserAccountsDaoStub();
|
||||||
|
|
||||||
wdf = new WebappDaoFactoryStub();
|
wdf = new WebappDaoFactoryStub();
|
||||||
|
wdf.setUserAccountsDao(uaDao);
|
||||||
|
|
||||||
ctx = new ServletContextStub();
|
ctx = new ServletContextStub();
|
||||||
ctx.setAttribute("webappDaoFactory", wdf);
|
ctx.setAttribute("webappDaoFactory", wdf);
|
||||||
|
@ -63,6 +69,10 @@ public class IsUserFactoryTest extends AbstractTestClass {
|
||||||
LoginStatusBean lsb = new LoginStatusBean(USER_URI,
|
LoginStatusBean lsb = new LoginStatusBean(USER_URI,
|
||||||
AuthenticationSource.EXTERNAL);
|
AuthenticationSource.EXTERNAL);
|
||||||
LoginStatusBean.setBean(session, lsb);
|
LoginStatusBean.setBean(session, lsb);
|
||||||
|
|
||||||
|
UserAccount user = new UserAccount();
|
||||||
|
user.setUri(USER_URI);
|
||||||
|
uaDao.addUser(user);
|
||||||
|
|
||||||
expectedIds = new ArrayIdentifierBundle(new IsUser(USER_URI));
|
expectedIds = new ArrayIdentifierBundle(new IsUser(USER_URI));
|
||||||
actualIds = factory.getIdentifierBundle(req);
|
actualIds = factory.getIdentifierBundle(req);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue