Cosmetic changes: reformat, organize imports, add generic type arguments.
This commit is contained in:
parent
6ed9e94366
commit
53ecff4f60
1 changed files with 194 additions and 167 deletions
|
@ -2,9 +2,10 @@
|
|||
|
||||
package edu.cornell.mannlib.vedit.beans;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -13,17 +14,38 @@ import java.util.*;
|
|||
*/
|
||||
public class LoginFormBean {
|
||||
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 sessionId;
|
||||
|
@ -36,7 +58,7 @@ public class LoginFormBean {
|
|||
private String loginRole;
|
||||
private String duplicatePassword;
|
||||
private String emailAddress;
|
||||
private Hashtable errors;
|
||||
private Hashtable<String, String> errors;
|
||||
|
||||
public boolean validateLoginForm() {
|
||||
boolean allOk = true;
|
||||
|
@ -68,7 +90,7 @@ public class LoginFormBean {
|
|||
duplicatePassword = "";
|
||||
emailAddress = "";
|
||||
|
||||
errors = new Hashtable();
|
||||
errors = new Hashtable<String, String>();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -76,40 +98,44 @@ public class LoginFormBean {
|
|||
if (getLoginName() != null && !"".equals(getLoginName()))
|
||||
name = getLoginName();
|
||||
|
||||
return this.getClass().getName()
|
||||
+" loginName: " + name
|
||||
+" loginStatus: "+ getLoginStatus()
|
||||
+" loginRole: "+ getLoginRole();
|
||||
return this.getClass().getName() + " loginName: " + name
|
||||
+ " loginStatus: " + getLoginStatus() + " loginRole: "
|
||||
+ getLoginRole();
|
||||
}
|
||||
|
||||
/**
|
||||
Tests a HttpSession to see if logged in and authenticated.
|
||||
@returns loginRole if seems to be authenticated, -1 otherwise
|
||||
* Tests a HttpSession to see if logged in and authenticated.
|
||||
*
|
||||
* @returns loginRole if seems to be authenticated, -1 otherwise
|
||||
*/
|
||||
public int testSessionLevel(HttpServletRequest request) {
|
||||
// TODO: security code added by bdc34, should be checked by jc55
|
||||
HttpSession currentSession = request.getSession();
|
||||
int returnRole = -1;
|
||||
if ( getLoginStatus().equals("authenticated") &&
|
||||
currentSession.getId().equals( getSessionId() ) &&
|
||||
request.getRemoteAddr().equals( getLoginRemoteAddr() ) ) {
|
||||
if (getLoginStatus().equals("authenticated")
|
||||
&& currentSession.getId().equals(getSessionId())
|
||||
&& request.getRemoteAddr().equals(getLoginRemoteAddr())) {
|
||||
try {
|
||||
returnRole = Integer.parseInt(getLoginRole());
|
||||
}catch(Throwable thr){ }
|
||||
} catch (Throwable thr) {
|
||||
}
|
||||
}
|
||||
return returnRole;
|
||||
}
|
||||
|
||||
public static boolean loggedIn(HttpServletRequest request, int minLevel) {
|
||||
if( request == null ) return false;
|
||||
if (request == null)
|
||||
return false;
|
||||
HttpSession sess = request.getSession(false);
|
||||
if( sess == null ) return false;
|
||||
if (sess == null)
|
||||
return false;
|
||||
Object obj = sess.getAttribute("loginHandler");
|
||||
if (obj == null || !(obj instanceof LoginFormBean))
|
||||
return false;
|
||||
|
||||
LoginFormBean lfb = (LoginFormBean) obj;
|
||||
return ( "authenticated".equals(lfb.loginStatus ) &&
|
||||
Integer.parseInt(lfb.loginRole ) >= minLevel) ;
|
||||
return ("authenticated".equals(lfb.loginStatus) && Integer
|
||||
.parseInt(lfb.loginRole) >= minLevel);
|
||||
}
|
||||
|
||||
/********************** GET METHODS *********************/
|
||||
|
@ -129,6 +155,7 @@ public class LoginFormBean {
|
|||
public String getLoginRemoteAddr() {
|
||||
return loginRemoteAddr;
|
||||
}
|
||||
|
||||
public String getLoginName() {
|
||||
return loginName;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue