diff --git a/webapp/config/web.xml b/webapp/config/web.xml index a12a19079..d82026d64 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -157,12 +157,6 @@ --> - - - edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactorySetup - - - edu.cornell.mannlib.vitro.webapp.auth.policy.setup.EditorEditingPolicySetup diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditing2RoleIdentifierFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditing2RoleIdentifierFactory.java deleted file mode 100644 index c521821b8..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditing2RoleIdentifierFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.auth.identifier; - -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpSession; - -import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole; -import edu.cornell.mannlib.vitro.webapp.beans.User; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; - -/** - * Checks to see if the Individual associated with a SelfEditingIdentifier - * has Admin, Curator or Editor rights. This ignores black listing. - * - * This should be added to the IdentifierFactory list after the - * SelfEditingIdentiferFactory. - * - * SelfEditing2RoleIdentifierSetup can be used in web.xml to add this class - * to the IdentifierFactory list of a servlet context. - * - * @author bdc34 - * - */ -public class SelfEditing2RoleIdentifierFactory implements - IdentifierBundleFactory { - - @Override - public IdentifierBundle getIdentifierBundle(ServletRequest request, - HttpSession session, ServletContext context) { - IdentifierBundle whoToAuth = RequestIdentifiers.getIdBundleForRequest(request); - WebappDaoFactory wdf = (WebappDaoFactory)context.getAttribute("webappDaoFactory"); - if( wdf == null ) - return whoToAuth; - SelfEditingIdentifierFactory.SelfEditing selfEditing = - SelfEditingIdentifierFactory.getSelfEditingIdentifier(whoToAuth); - if( selfEditing != null ){ - User user = wdf.getUserDao().getUserByURI(selfEditing.getIndividual().getURI()); - if( user != null){ - String role = user.getRoleURI(); - if("role/:50".equals(role)){ - whoToAuth.add( AuthRole.DBA ); - } - if("role/:4".equals(role)){ - whoToAuth.add( AuthRole.CURATOR); - } - if("role/:3".equals(role)){ - whoToAuth.add( AuthRole.EDITOR); - } - if("role/:2".equals(role)){ - whoToAuth.add( AuthRole.USER ); - } - } - } - return whoToAuth; - } -} \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactory.java deleted file mode 100644 index 8aa3e84e0..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactory.java +++ /dev/null @@ -1,96 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.auth.identifier; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpSession; - -import edu.cornell.mannlib.vedit.beans.LoginStatusBean; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; - -/** - * Check to see if the User is logged in, find Individuals that the User mayEditAs, - * and and those Individuals as identifiers. - * - * @author bdc34 - * - */ -public class UserToIndIdentifierFactory implements IdentifierBundleFactory { - - public IdentifierBundle getIdentifierBundle( - ServletRequest request, - HttpSession session, - ServletContext context) { - // is the request logged in as a User? - LoginStatusBean loginBean = LoginStatusBean.getBean(session); - if (loginBean.isLoggedIn()) { - String userURI = loginBean.getUserURI(); - - WebappDaoFactory wdf = (WebappDaoFactory)context.getAttribute("webappDaoFactory"); - - // get Individuals that the User mayEditAs - List mayEditAsUris = - wdf.getUserDao().getIndividualsUserMayEditAs(userURI); - - // make self editing Identifiers for those Individuals - IdentifierBundle idb = new ArrayIdentifierBundle(); - idb.add( new UserIdentifier(userURI,mayEditAsUris) ); - - //Also make a self-editing identifier. - //There is not need for SelfEditingIdentifierFactory because SelfEditing - //identifiers are created here. - for( String personUri : mayEditAsUris){ - if( personUri != null ){ - Individual person = wdf.getIndividualDao().getIndividualByURI(personUri); - if( person != null ){ - idb.add( new SelfEditingIdentifierFactory.SelfEditing(person,null) ); - } - } - } - return idb; - } - - return null; - } - - public static List getIndividualsForUser(IdentifierBundle ids) { - if( ids == null ) - return Collections.emptyList(); - - //find the user id - List uris = new ArrayList(); - for( Identifier id : ids ){ - if( id instanceof UserIdentifier){ - uris.addAll( ((UserIdentifier)id).getMayEditAsURIs() ); - } - } - return uris; - } - - public class UserIdentifier implements Identifier { - private final String userURI; - private final List mayEditAsURIs; - public UserIdentifier(String userURI, List mayEditAsURIs) { - super(); - this.userURI = userURI; - this.mayEditAsURIs = Collections.unmodifiableList(mayEditAsURIs); - } - public String getUserURI() { - return userURI; - } - public List getMayEditAsURIs() { - return mayEditAsURIs; - } - @Override - public String toString() { - return "UserIdentifier: " + userURI; - } - - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactorySetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactorySetup.java deleted file mode 100644 index 7ee015260..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/UserToIndIdentifierFactorySetup.java +++ /dev/null @@ -1,40 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.auth.identifier; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; - -/** - * Setups context so that Identifiers for Individuals associated with Users are - * added to requests. - * - * This only adds identifiers. A self-editing policy is also needed. - * - * @author bdc34 - * - */ -public class UserToIndIdentifierFactorySetup implements ServletContextListener{ - private static final Log log = LogFactory.getLog(UserToIndIdentifierFactorySetup.class.getName()); - - @Override - public void contextInitialized(ServletContextEvent sce) { - - if (AbortStartup.isStartupAborted(sce.getServletContext())) { - return; - } - - ActiveIdentifierBundleFactories.addFactory(sce, new UserToIndIdentifierFactory()); - log.info("Set up Identifier Factory UserToIndIdentifierFactory."); - } - - @Override - public void contextDestroyed(ServletContextEvent arg0) { - // Nothing to do. - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditing2RoleIdentifierSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditing2RoleIdentifierSetup.java deleted file mode 100644 index 001aa5608..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditing2RoleIdentifierSetup.java +++ /dev/null @@ -1,49 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.auth.policy.setup; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.auth.identifier.ActiveIdentifierBundleFactories; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditing2RoleIdentifierFactory; - -/** - * Add the SelfEditing2RoleIdentifier factory to the IdentifierFactory list - * in the servlet context. - * - * This should be added to the IdentifierFactory list after the - * SelfEditingIdentiferFactory. - * - * This only sets up a IdentifierFactoy that maps SelfEditing identifiers to - * roles associated with the Individual that represents the self editor. This - * does not set up a policy or the SelfEditingIdentifierFactory. - * - * @author bdc34 - * - */ -public class SelfEditing2RoleIdentifierSetup implements ServletContextListener{ - - private static final Log log = LogFactory.getLog(SelfEditing2RoleIdentifierSetup.class.getName()); - - @Override - public void contextDestroyed(ServletContextEvent sce) { - //do nothing - } - - @Override - public void contextInitialized(ServletContextEvent sce) { - try{ - log.debug("Setting up SelfEditing2RoleIdentifier"); - ActiveIdentifierBundleFactories.addFactory(sce, new SelfEditing2RoleIdentifierFactory()); - log.debug( "SelfEditing2RoleIdentifier has been setup. " ); - }catch(Exception e){ - log.error("could not run SelfEditing2RoleIdentifier: " + e); - e.printStackTrace(); - } - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java index f2582028c..854126779 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java @@ -28,15 +28,13 @@ import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ResourceFactory; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.EditSubmissionPreprocessor; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.SparqlEvaluate; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; @@ -262,22 +260,9 @@ public class EditConfiguration { throw new Error("EditConfiguration.addSystemValues() needs a session"); /* ********** Get URI of a logged in user ************** */ - IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); - List userUris = - UserToIndIdentifierFactory.getIndividualsForUser(ids); - - if( userUris == null || userUris.size() == 0 ){ - log.debug("Cound not find user ur for edit request"); - log.error("Could not find a userUri for edit request, make " + - "sure that there is an IdentifierBundleFactory that " + - "produces userUri identifiers in the context."); - } else if( userUris.size() > 1 ){ - log.error("Found multiple userUris, using the first in list."); - log.debug("Found multiple user uris"); - }else { - log.debug("EditConfiguration.java - checking system value for User URI " + userUris.get(0)); - getUrisInScope().put("editingUser",userUris.get(0)); - } + String userUri = EditN3Utils.getEditorUri(request); + log.debug("EditConfiguration.java - checking system value for User URI " + userUri); + getUrisInScope().put("editingUser", userUri); } }