NIHVIVO-736 transitioning from LoginFormBean to LoginStatusBean.

This commit is contained in:
jeb228 2010-10-13 18:34:41 +00:00
parent 275ef7d471
commit b4ea726109
5 changed files with 74 additions and 84 deletions

View file

@ -23,13 +23,11 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vedit.beans.EditProcessObject; import edu.cornell.mannlib.vedit.beans.EditProcessObject;
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.util.FormUtils; import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
public class BaseEditController extends VitroHttpServlet { public class BaseEditController extends VitroHttpServlet {

View file

@ -6,7 +6,7 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole;
@ -17,15 +17,12 @@ public class CuratorEditingIdentifierFactory implements IdentifierBundleFactory{
IdentifierBundle ib = new ArrayIdentifierBundle(); IdentifierBundle ib = new ArrayIdentifierBundle();
ib.add( RoleBasedPolicy.AuthRole.ANYBODY); ib.add( RoleBasedPolicy.AuthRole.ANYBODY);
if( session != null ){ LoginStatusBean loginBean = LoginStatusBean.getBean(session);
LoginFormBean f = (LoginFormBean) session.getAttribute( "loginHandler" ); if (loginBean.isLoggedInAtLeast(LoginStatusBean.CURATOR)) {
try{ String loginRole = String.valueOf(loginBean.getSecurityLevel());
if( f != null && Integer.parseInt( f.getLoginRole() ) >= LoginFormBean.CURATOR){ ib.add(new CuratorEditingId(loginRole, loginBean.getUserURI()));
ib.add(new CuratorEditingId(f.getLoginRole(),f.getUserURI())); ib.add(AuthRole.CURATOR);
ib.add(AuthRole.CURATOR); }
}
}catch(NumberFormatException th){}
}
return ib; return ib;
} }

View file

@ -6,7 +6,7 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole;
@ -17,15 +17,12 @@ public class DbAdminEditingIdentifierFactory implements IdentifierBundleFactory{
IdentifierBundle ib = new ArrayIdentifierBundle(); IdentifierBundle ib = new ArrayIdentifierBundle();
ib.add( RoleBasedPolicy.AuthRole.ANYBODY); ib.add( RoleBasedPolicy.AuthRole.ANYBODY);
if( session != null ){ LoginStatusBean loginBean = LoginStatusBean.getBean(session);
LoginFormBean f = (LoginFormBean) session.getAttribute( "loginHandler" ); if (loginBean.isLoggedInAtLeast(LoginStatusBean.DBA)) {
try{ String loginRole = String.valueOf(loginBean.getSecurityLevel());
if( f != null && Integer.parseInt( f.getLoginRole() ) >= LoginFormBean.DBA){ ib.add(new DbAdminEditingId(loginRole, loginBean.getUserURI()));
ib.add(new DbAdminEditingId(f.getLoginRole(),f.getUserURI())); ib.add(AuthRole.DBA);
ib.add(AuthRole.DBA); }
}
}catch(NumberFormatException th){}
}
return ib; return ib;
} }

View file

@ -6,7 +6,7 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy;
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole; import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy.AuthRole;
@ -16,15 +16,14 @@ public class EditorEditingIdentifierFactory implements IdentifierBundleFactory{
HttpSession session, ServletContext context) { HttpSession session, ServletContext context) {
IdentifierBundle ib = new ArrayIdentifierBundle(); IdentifierBundle ib = new ArrayIdentifierBundle();
ib.add( RoleBasedPolicy.AuthRole.ANYBODY); ib.add( RoleBasedPolicy.AuthRole.ANYBODY);
if( session != null ){
LoginFormBean f = (LoginFormBean) session.getAttribute( "loginHandler" ); LoginStatusBean loginBean = LoginStatusBean.getBean(session);
try{ if (loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR)) {
if( f != null && Integer.parseInt( f.getLoginRole() ) >= LoginFormBean.EDITOR){ String loginRole = String.valueOf(loginBean.getSecurityLevel());
ib.add(new EditorEditingId(f.getLoginRole(), f.getUserURI())); ib.add(new EditorEditingId(loginRole, loginBean.getUserURI()));
ib.add(AuthRole.EDITOR); ib.add(AuthRole.EDITOR);
} }
}catch(NumberFormatException th){ }
}
return ib; return ib;
} }

View file

@ -10,7 +10,7 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -27,42 +27,41 @@ public class UserToIndIdentifierFactory implements IdentifierBundleFactory {
ServletRequest request, ServletRequest request,
HttpSession session, HttpSession session,
ServletContext context) { ServletContext context) {
if( session != null ){ // is the request logged in as a User?
// is the request logged in as a User? LoginStatusBean loginBean = LoginStatusBean.getBean(session);
LoginFormBean loginBean = (LoginFormBean) session.getAttribute("loginHandler"); if (loginBean.isLoggedIn()) {
if( loginBean != null && "authenticated".equals(loginBean.getLoginStatus() )){ String userURI = loginBean.getUserURI();
String userURI = loginBean.getUserURI();
WebappDaoFactory wdf = (WebappDaoFactory)context.getAttribute("webappDaoFactory"); WebappDaoFactory wdf = (WebappDaoFactory)context.getAttribute("webappDaoFactory");
// get Individuals that the User mayEditAs // get Individuals that the User mayEditAs
List<String> mayEditAsUris = List<String> mayEditAsUris =
wdf.getUserDao().getIndividualsUserMayEditAs(userURI); wdf.getUserDao().getIndividualsUserMayEditAs(userURI);
// make self editing Identifiers for those Individuals // make self editing Identifiers for those Individuals
IdentifierBundle idb = new ArrayIdentifierBundle(); IdentifierBundle idb = new ArrayIdentifierBundle();
idb.add( new UserIdentifier(userURI,mayEditAsUris) ); idb.add( new UserIdentifier(userURI,mayEditAsUris) );
//Also make a self-editing identifier. //Also make a self-editing identifier.
//There is not need for SelfEditingIdentifierFactory because SelfEditing //There is not need for SelfEditingIdentifierFactory because SelfEditing
//identifiers are created here. //identifiers are created here.
for( String personUri : mayEditAsUris){ for( String personUri : mayEditAsUris){
if( personUri != null ){ if( personUri != null ){
Individual person = wdf.getIndividualDao().getIndividualByURI(personUri); Individual person = wdf.getIndividualDao().getIndividualByURI(personUri);
if( person != null ){ if( person != null ){
idb.add( new SelfEditingIdentifierFactory.SelfEditing(person,null) ); idb.add( new SelfEditingIdentifierFactory.SelfEditing(person,null) );
}
} }
} }
return idb;
} }
return idb;
} }
return null; return null;
} }
public static List<String> getIndividualsForUser(IdentifierBundle ids) { public static List<String> getIndividualsForUser(IdentifierBundle ids) {
if( ids == null ) if( ids == null )
return Collections.EMPTY_LIST; return Collections.emptyList();
//find the user id //find the user id
List<String> uris = new ArrayList<String>(); List<String> uris = new ArrayList<String>();