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.ServletContextEvent;
|
||||
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.
|
||||
|
@ -50,14 +51,15 @@ public class ActiveIdentifierBundleFactories {
|
|||
|
||||
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) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
ActiveIdentifierBundleFactories actFact = getActiveFactories(ctx);
|
||||
for (IdentifierBundleFactory factory: actFact.factories) {
|
||||
for (IdentifierBundleFactory factory : actFact.factories) {
|
||||
names.add(factory.toString());
|
||||
}
|
||||
return names;
|
||||
|
@ -72,10 +74,28 @@ public class ActiveIdentifierBundleFactories {
|
|||
* request.
|
||||
*/
|
||||
static IdentifierBundle getIdentifierBundle(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
ServletContext ctx = session.getServletContext();
|
||||
return getActiveFactories(ctx).getIdentifierBundle(request, session,
|
||||
ctx);
|
||||
return getActiveFactories(request).getBundleForRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* request.
|
||||
*/
|
||||
private IdentifierBundle getIdentifierBundle(HttpServletRequest request,
|
||||
HttpSession session, ServletContext ctx) {
|
||||
private IdentifierBundle getBundleForRequest(HttpServletRequest request) {
|
||||
IdentifierBundle ib = new ArrayIdentifierBundle();
|
||||
for (IdentifierBundleFactory ibf : factories) {
|
||||
IdentifierBundle obj = ibf.getIdentifierBundle(request);
|
||||
if (obj != null) {
|
||||
ib.addAll(obj);
|
||||
ib.addAll(ibf.getIdentifierBundle(request));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.IdentifierBundle;
|
||||
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.
|
||||
*/
|
||||
public class HasPermissionFactory extends BaseIdentifierBundleFactory {
|
||||
public class HasPermissionFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(HasPermissionFactory.class);
|
||||
|
||||
|
@ -35,8 +33,7 @@ public class HasPermissionFactory extends BaseIdentifierBundleFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
if (user == null) {
|
||||
return createPublicPermissions();
|
||||
} else {
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.factory;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.IdentifierBundle;
|
||||
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.
|
||||
*/
|
||||
public class HasPermissionSetFactory extends BaseIdentifierBundleFactory {
|
||||
public class HasPermissionSetFactory extends
|
||||
BaseUserBasedIdentifierBundleFactory {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(HasPermissionFactory.class);
|
||||
|
||||
|
@ -27,12 +26,10 @@ public class HasPermissionSetFactory extends BaseIdentifierBundleFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
IdentifierBundle ids = new ArrayIdentifierBundle();
|
||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||
if (user != null) {
|
||||
|
||||
for (String psUri: user.getPermissionSetUris()) {
|
||||
for (String psUri : user.getPermissionSetUris()) {
|
||||
PermissionSet ps = uaDao.getPermissionSetByUri(psUri);
|
||||
if (ps != null) {
|
||||
ids.add(new HasPermissionSet(ps));
|
||||
|
|
|
@ -6,12 +6,10 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.Identifier;
|
||||
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.
|
||||
*/
|
||||
public class HasProfileOrIsBlacklistedFactory extends
|
||||
BaseIdentifierBundleFactory {
|
||||
BaseUserBasedIdentifierBundleFactory {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(HasProfileOrIsBlacklistedFactory.class);
|
||||
|
||||
|
@ -35,10 +33,10 @@ public class HasProfileOrIsBlacklistedFactory extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
||||
|
||||
for (Individual ind : getAssociatedIndividuals(req)) {
|
||||
for (Individual ind : getAssociatedIndividuals(user)) {
|
||||
// If they are blacklisted, this factory will return an identifier
|
||||
Identifier id = IsBlacklisted.getInstance(ind, ctx);
|
||||
if (id != null) {
|
||||
|
@ -54,17 +52,15 @@ public class HasProfileOrIsBlacklistedFactory extends
|
|||
/**
|
||||
* Get all Individuals associated with the current user as SELF.
|
||||
*/
|
||||
private Collection<Individual> getAssociatedIndividuals(
|
||||
HttpServletRequest req) {
|
||||
private Collection<Individual> getAssociatedIndividuals(UserAccount user) {
|
||||
Collection<Individual> individuals = new ArrayList<Individual>();
|
||||
|
||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||
if (user == null) {
|
||||
log.debug("No Associated Individuals: not logged in.");
|
||||
return individuals;
|
||||
}
|
||||
|
||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(req);
|
||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(ctx);
|
||||
individuals.addAll(sec.getAssociatedIndividuals(indDao, user));
|
||||
|
||||
return individuals;
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
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.ArrayIdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
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.
|
||||
*/
|
||||
public class HasProxyEditingRightsFactory extends BaseIdentifierBundleFactory {
|
||||
public class HasProxyEditingRightsFactory extends
|
||||
BaseUserBasedIdentifierBundleFactory {
|
||||
|
||||
public HasProxyEditingRightsFactory(ServletContext ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
ArrayIdentifierBundle ids = new ArrayIdentifierBundle();
|
||||
|
||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||
if (user != null) {
|
||||
for (String proxiedUri : user.getProxiedIndividualUris()) {
|
||||
ids.add(new HasProxyEditingRights(proxiedUri));
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
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.ArrayIdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
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.
|
||||
*/
|
||||
public class IsRootUserFactory extends BaseIdentifierBundleFactory {
|
||||
public class IsRootUserFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||
|
||||
public IsRootUserFactory(ServletContext ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
if ((user != null) && user.isRootUser()) {
|
||||
return new ArrayIdentifierBundle(IsRootUser.INSTANCE);
|
||||
} else {
|
||||
|
@ -31,4 +28,3 @@ public class IsRootUserFactory extends BaseIdentifierBundleFactory {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,27 @@
|
|||
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.ArrayIdentifierBundle;
|
||||
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.beans.UserAccount;
|
||||
|
||||
/**
|
||||
* If the user is logged in, create an Identifier.
|
||||
*/
|
||||
public class IsUserFactory extends BaseIdentifierBundleFactory {
|
||||
public class IsUserFactory extends BaseUserBasedIdentifierBundleFactory {
|
||||
|
||||
public IsUserFactory(ServletContext ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierBundle getIdentifierBundle(HttpServletRequest req) {
|
||||
LoginStatusBean bean = LoginStatusBean.getBean(req);
|
||||
if (bean.isLoggedIn()) {
|
||||
return new ArrayIdentifierBundle(new IsUser(bean.getUserURI()));
|
||||
} else {
|
||||
public IdentifierBundle getIdentifierBundleForUser(UserAccount user) {
|
||||
if (user == null) {
|
||||
return new ArrayIdentifierBundle();
|
||||
} else {
|
||||
return new ArrayIdentifierBundle(new IsUser(user.getUri()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue