Cosmetic changes: reformat, organize imports, add generic type arguments.

This commit is contained in:
jeb228 2010-09-03 16:17:01 +00:00
parent 6ed9e94366
commit 53ecff4f60

View file

@ -2,9 +2,10 @@
package edu.cornell.mannlib.vedit.beans; package edu.cornell.mannlib.vedit.beans;
import javax.servlet.*; import java.util.Hashtable;
import javax.servlet.http.*;
import java.util.*; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/** /**
* *
@ -13,17 +14,38 @@ import java.util.*;
*/ */
public class LoginFormBean { public class LoginFormBean {
public static final int ANYBODY = 0; public static final int ANYBODY = 0;
public int getAnybody(){ return ANYBODY; }
public static final int NON_EDITOR = 1;
public int getNonEditor(){ return NON_EDITOR; }
public static final int EDITOR =4;
public int getEditor(){return EDITOR;}
public static final int CURATOR=5;
public int getCurator(){return CURATOR;}
public static final int DBA =50;
public int getDba(){return DBA;}
public boolean getBla(){ return true; } public int getAnybody() {
return ANYBODY;
}
public static final int NON_EDITOR = 1;
public int getNonEditor() {
return NON_EDITOR;
}
public static final int EDITOR = 4;
public int getEditor() {
return EDITOR;
}
public static final int CURATOR = 5;
public int getCurator() {
return CURATOR;
}
public static final int DBA = 50;
public int getDba() {
return DBA;
}
public boolean getBla() {
return true;
}
private String userURI; private String userURI;
private String sessionId; private String sessionId;
@ -36,7 +58,7 @@ public class LoginFormBean {
private String loginRole; private String loginRole;
private String duplicatePassword; private String duplicatePassword;
private String emailAddress; private String emailAddress;
private Hashtable errors; private Hashtable<String, String> errors;
public boolean validateLoginForm() { public boolean validateLoginForm() {
boolean allOk = true; boolean allOk = true;
@ -68,7 +90,7 @@ public class LoginFormBean {
duplicatePassword = ""; duplicatePassword = "";
emailAddress = ""; emailAddress = "";
errors = new Hashtable(); errors = new Hashtable<String, String>();
} }
public String toString() { public String toString() {
@ -76,40 +98,44 @@ public class LoginFormBean {
if (getLoginName() != null && !"".equals(getLoginName())) if (getLoginName() != null && !"".equals(getLoginName()))
name = getLoginName(); name = getLoginName();
return this.getClass().getName() return this.getClass().getName() + " loginName: " + name
+" loginName: " + name + " loginStatus: " + getLoginStatus() + " loginRole: "
+" loginStatus: "+ getLoginStatus() + getLoginRole();
+" loginRole: "+ getLoginRole();
} }
/** /**
Tests a HttpSession to see if logged in and authenticated. * Tests a HttpSession to see if logged in and authenticated.
@returns loginRole if seems to be authenticated, -1 otherwise *
* @returns loginRole if seems to be authenticated, -1 otherwise
*/ */
public int testSessionLevel(HttpServletRequest request) { public int testSessionLevel(HttpServletRequest request) {
// TODO: security code added by bdc34, should be checked by jc55 // TODO: security code added by bdc34, should be checked by jc55
HttpSession currentSession = request.getSession(); HttpSession currentSession = request.getSession();
int returnRole = -1; int returnRole = -1;
if ( getLoginStatus().equals("authenticated") && if (getLoginStatus().equals("authenticated")
currentSession.getId().equals( getSessionId() ) && && currentSession.getId().equals(getSessionId())
request.getRemoteAddr().equals( getLoginRemoteAddr() ) ) { && request.getRemoteAddr().equals(getLoginRemoteAddr())) {
try { try {
returnRole = Integer.parseInt(getLoginRole()); returnRole = Integer.parseInt(getLoginRole());
}catch(Throwable thr){ } } catch (Throwable thr) {
}
} }
return returnRole; return returnRole;
} }
public static boolean loggedIn(HttpServletRequest request, int minLevel) { public static boolean loggedIn(HttpServletRequest request, int minLevel) {
if( request == null ) return false; if (request == null)
return false;
HttpSession sess = request.getSession(false); HttpSession sess = request.getSession(false);
if( sess == null ) return false; if (sess == null)
return false;
Object obj = sess.getAttribute("loginHandler"); Object obj = sess.getAttribute("loginHandler");
if (obj == null || !(obj instanceof LoginFormBean)) if (obj == null || !(obj instanceof LoginFormBean))
return false; return false;
LoginFormBean lfb = (LoginFormBean) obj; LoginFormBean lfb = (LoginFormBean) obj;
return ( "authenticated".equals(lfb.loginStatus ) && return ("authenticated".equals(lfb.loginStatus) && Integer
Integer.parseInt(lfb.loginRole ) >= minLevel) ; .parseInt(lfb.loginRole) >= minLevel);
} }
/********************** GET METHODS *********************/ /********************** GET METHODS *********************/
@ -129,6 +155,7 @@ public class LoginFormBean {
public String getLoginRemoteAddr() { public String getLoginRemoteAddr() {
return loginRemoteAddr; return loginRemoteAddr;
} }
public String getLoginName() { public String getLoginName() {
return loginName; return loginName;
} }