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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -12,18 +13,39 @@ 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 static final int ANYBODY = 0;
|
||||
|
||||
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,21 +58,21 @@ 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;
|
||||
boolean allOk = true;
|
||||
|
||||
if ( loginName.equals("")) {
|
||||
errors.put( "loginName","Please enter your Vivo user name" );
|
||||
if (loginName.equals("")) {
|
||||
errors.put("loginName", "Please enter your Vivo user name");
|
||||
loginName = "";
|
||||
allOk = false;
|
||||
}
|
||||
|
||||
if ( loginPassword.equals("")) {
|
||||
errors.put( "loginPassword","Please enter your Vivo password" );
|
||||
loginPassword="";
|
||||
allOk=false;
|
||||
if (loginPassword.equals("")) {
|
||||
errors.put("loginPassword", "Please enter your Vivo password");
|
||||
loginPassword = "";
|
||||
allOk = false;
|
||||
}
|
||||
|
||||
return allOk;
|
||||
|
@ -68,48 +90,52 @@ public class LoginFormBean {
|
|||
duplicatePassword = "";
|
||||
emailAddress = "";
|
||||
|
||||
errors = new Hashtable();
|
||||
errors = new Hashtable<String, String>();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
String name = "-not-logged-in-";
|
||||
if( getLoginName() != null && !"".equals(getLoginName()) )
|
||||
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
|
||||
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() ) ) {
|
||||
try{
|
||||
returnRole = Integer.parseInt( getLoginRole() );
|
||||
}catch(Throwable thr){ }
|
||||
if (getLoginStatus().equals("authenticated")
|
||||
&& currentSession.getId().equals(getSessionId())
|
||||
&& request.getRemoteAddr().equals(getLoginRemoteAddr())) {
|
||||
try {
|
||||
returnRole = Integer.parseInt(getLoginRole());
|
||||
} 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))
|
||||
if (obj == null || !(obj instanceof LoginFormBean))
|
||||
return false;
|
||||
|
||||
LoginFormBean lfb = (LoginFormBean)obj;
|
||||
return ( "authenticated".equals(lfb.loginStatus ) &&
|
||||
Integer.parseInt(lfb.loginRole ) >= minLevel) ;
|
||||
LoginFormBean lfb = (LoginFormBean) obj;
|
||||
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;
|
||||
}
|
||||
|
@ -157,59 +184,59 @@ public class LoginFormBean {
|
|||
return emailAddress;
|
||||
}
|
||||
|
||||
public String getErrorMsg( String s ) {
|
||||
String errorMsg =(String) errors.get( s.trim() );
|
||||
return ( errorMsg == null ) ? "" : errorMsg;
|
||||
public String getErrorMsg(String s) {
|
||||
String errorMsg = (String) errors.get(s.trim());
|
||||
return (errorMsg == null) ? "" : errorMsg;
|
||||
}
|
||||
|
||||
/********************** SET METHODS *********************/
|
||||
|
||||
public void setUserURI( String uri ) {
|
||||
public void setUserURI(String uri) {
|
||||
this.userURI = uri;
|
||||
}
|
||||
|
||||
public void setSessionId( String id ) {
|
||||
public void setSessionId(String id) {
|
||||
sessionId = id;
|
||||
}
|
||||
|
||||
public void setLoginBrowser( String b ) {
|
||||
public void setLoginBrowser(String b) {
|
||||
loginBrowser = b;
|
||||
}
|
||||
|
||||
public void setLoginRemoteAddr( String ra ) {
|
||||
public void setLoginRemoteAddr(String ra) {
|
||||
loginRemoteAddr = ra;
|
||||
}
|
||||
|
||||
public void setLoginName( String ln ) {
|
||||
public void setLoginName(String ln) {
|
||||
loginName = ln;
|
||||
}
|
||||
|
||||
public void setLoginPassword( String lp ) {
|
||||
public void setLoginPassword(String lp) {
|
||||
loginPassword = lp;
|
||||
}
|
||||
|
||||
public void setLoginStatus( String ls ) {
|
||||
public void setLoginStatus(String ls) {
|
||||
loginStatus = ls;
|
||||
}
|
||||
|
||||
public void setLoginUserId(int int_val) {
|
||||
loginUserId=int_val;
|
||||
loginUserId = int_val;
|
||||
}
|
||||
|
||||
public void setLoginRole( String lr ) {
|
||||
public void setLoginRole(String lr) {
|
||||
loginRole = lr;
|
||||
}
|
||||
|
||||
public void setDuplicatePassword( String dp ) {
|
||||
public void setDuplicatePassword(String dp) {
|
||||
duplicatePassword = dp;
|
||||
}
|
||||
|
||||
public void setEmailAddress( String ea ) {
|
||||
public void setEmailAddress(String ea) {
|
||||
emailAddress = ea;
|
||||
}
|
||||
|
||||
public void setErrorMsg( String key, String msg ) {
|
||||
errors.put( key,msg );
|
||||
public void setErrorMsg(String key, String msg) {
|
||||
errors.put(key, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue