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,214 +2,241 @@
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jc55
|
* @author jc55
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
private String userURI;
|
public static final int NON_EDITOR = 1;
|
||||||
private String sessionId;
|
|
||||||
private String loginBrowser;
|
|
||||||
private String loginRemoteAddr;
|
|
||||||
private String loginName;
|
|
||||||
private String loginPassword;
|
|
||||||
private String loginStatus;
|
|
||||||
private int loginUserId;
|
|
||||||
private String loginRole;
|
|
||||||
private String duplicatePassword;
|
|
||||||
private String emailAddress;
|
|
||||||
private Hashtable errors;
|
|
||||||
|
|
||||||
public boolean validateLoginForm() {
|
public int getNonEditor() {
|
||||||
boolean allOk=true;
|
return NON_EDITOR;
|
||||||
|
}
|
||||||
|
|
||||||
if ( loginName.equals("")) {
|
public static final int EDITOR = 4;
|
||||||
errors.put( "loginName","Please enter your Vivo user name" );
|
|
||||||
loginName = "";
|
|
||||||
allOk = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( loginPassword.equals("")) {
|
public int getEditor() {
|
||||||
errors.put( "loginPassword","Please enter your Vivo password" );
|
return EDITOR;
|
||||||
loginPassword="";
|
}
|
||||||
allOk=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return allOk;
|
public static final int CURATOR = 5;
|
||||||
}
|
|
||||||
|
|
||||||
public LoginFormBean() {
|
public int getCurator() {
|
||||||
sessionId = "";
|
return CURATOR;
|
||||||
loginBrowser = "";
|
}
|
||||||
loginRemoteAddr = "";
|
|
||||||
loginName = "";
|
|
||||||
loginPassword = "";
|
|
||||||
loginStatus = "none";
|
|
||||||
loginUserId = 0;
|
|
||||||
loginRole = "1";
|
|
||||||
duplicatePassword = "";
|
|
||||||
emailAddress = "";
|
|
||||||
|
|
||||||
errors = new Hashtable();
|
public static final int DBA = 50;
|
||||||
}
|
|
||||||
|
|
||||||
public String toString(){
|
public int getDba() {
|
||||||
String name = "-not-logged-in-";
|
return DBA;
|
||||||
if( getLoginName() != null && !"".equals(getLoginName()) )
|
}
|
||||||
name = getLoginName();
|
|
||||||
|
|
||||||
return this.getClass().getName()
|
public boolean getBla() {
|
||||||
+" loginName: " + name
|
return true;
|
||||||
+" loginStatus: "+ getLoginStatus()
|
}
|
||||||
+" loginRole: "+ getLoginRole();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
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() ) ) {
|
|
||||||
try{
|
|
||||||
returnRole = Integer.parseInt( getLoginRole() );
|
|
||||||
}catch(Throwable thr){ }
|
|
||||||
}
|
|
||||||
return returnRole;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean loggedIn(HttpServletRequest request, int minLevel) {
|
private String userURI;
|
||||||
if( request == null ) return false;
|
private String sessionId;
|
||||||
HttpSession sess = request.getSession(false);
|
private String loginBrowser;
|
||||||
if( sess == null ) return false;
|
private String loginRemoteAddr;
|
||||||
Object obj = sess.getAttribute("loginHandler");
|
private String loginName;
|
||||||
if( obj == null || ! (obj instanceof LoginFormBean))
|
private String loginPassword;
|
||||||
return false;
|
private String loginStatus;
|
||||||
|
private int loginUserId;
|
||||||
|
private String loginRole;
|
||||||
|
private String duplicatePassword;
|
||||||
|
private String emailAddress;
|
||||||
|
private Hashtable<String, String> errors;
|
||||||
|
|
||||||
LoginFormBean lfb = (LoginFormBean)obj;
|
public boolean validateLoginForm() {
|
||||||
return ( "authenticated".equals(lfb.loginStatus ) &&
|
boolean allOk = true;
|
||||||
Integer.parseInt(lfb.loginRole ) >= minLevel) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************** GET METHODS *********************/
|
if (loginName.equals("")) {
|
||||||
|
errors.put("loginName", "Please enter your Vivo user name");
|
||||||
|
loginName = "";
|
||||||
|
allOk = false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserURI() {
|
if (loginPassword.equals("")) {
|
||||||
return userURI;
|
errors.put("loginPassword", "Please enter your Vivo password");
|
||||||
}
|
loginPassword = "";
|
||||||
|
allOk = false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSessionId() {
|
return allOk;
|
||||||
return sessionId;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginBrowser() {
|
public LoginFormBean() {
|
||||||
return loginBrowser;
|
sessionId = "";
|
||||||
}
|
loginBrowser = "";
|
||||||
|
loginRemoteAddr = "";
|
||||||
|
loginName = "";
|
||||||
|
loginPassword = "";
|
||||||
|
loginStatus = "none";
|
||||||
|
loginUserId = 0;
|
||||||
|
loginRole = "1";
|
||||||
|
duplicatePassword = "";
|
||||||
|
emailAddress = "";
|
||||||
|
|
||||||
public String getLoginRemoteAddr() {
|
errors = new Hashtable<String, String>();
|
||||||
return loginRemoteAddr;
|
}
|
||||||
}
|
|
||||||
public String getLoginName() {
|
|
||||||
return loginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginPassword() {
|
public String toString() {
|
||||||
return loginPassword;
|
String name = "-not-logged-in-";
|
||||||
}
|
if (getLoginName() != null && !"".equals(getLoginName()))
|
||||||
|
name = getLoginName();
|
||||||
|
|
||||||
public String getLoginStatus() {
|
return this.getClass().getName() + " loginName: " + name
|
||||||
return loginStatus;
|
+ " loginStatus: " + getLoginStatus() + " loginRole: "
|
||||||
}
|
+ getLoginRole();
|
||||||
|
}
|
||||||
|
|
||||||
public int getLoginUserId() {
|
/**
|
||||||
return loginUserId;
|
* 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())) {
|
||||||
|
try {
|
||||||
|
returnRole = Integer.parseInt(getLoginRole());
|
||||||
|
} catch (Throwable thr) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnRole;
|
||||||
|
}
|
||||||
|
|
||||||
public String getLoginRole() {
|
public static boolean loggedIn(HttpServletRequest request, int minLevel) {
|
||||||
return loginRole;
|
if (request == null)
|
||||||
}
|
return false;
|
||||||
|
HttpSession sess = request.getSession(false);
|
||||||
|
if (sess == null)
|
||||||
|
return false;
|
||||||
|
Object obj = sess.getAttribute("loginHandler");
|
||||||
|
if (obj == null || !(obj instanceof LoginFormBean))
|
||||||
|
return false;
|
||||||
|
|
||||||
public String getDuplicatePassword() {
|
LoginFormBean lfb = (LoginFormBean) obj;
|
||||||
return duplicatePassword;
|
return ("authenticated".equals(lfb.loginStatus) && Integer
|
||||||
}
|
.parseInt(lfb.loginRole) >= minLevel);
|
||||||
|
}
|
||||||
|
|
||||||
public String getEmailAddress() {
|
/********************** GET METHODS *********************/
|
||||||
return emailAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorMsg( String s ) {
|
public String getUserURI() {
|
||||||
String errorMsg =(String) errors.get( s.trim() );
|
return userURI;
|
||||||
return ( errorMsg == null ) ? "" : errorMsg;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/********************** SET METHODS *********************/
|
public String getSessionId() {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
public void setUserURI( String uri ) {
|
public String getLoginBrowser() {
|
||||||
this.userURI = uri;
|
return loginBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessionId( String id ) {
|
public String getLoginRemoteAddr() {
|
||||||
sessionId = id;
|
return loginRemoteAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginBrowser( String b ) {
|
public String getLoginName() {
|
||||||
loginBrowser = b;
|
return loginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginRemoteAddr( String ra ) {
|
public String getLoginPassword() {
|
||||||
loginRemoteAddr = ra;
|
return loginPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginName( String ln ) {
|
public String getLoginStatus() {
|
||||||
loginName = ln;
|
return loginStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginPassword( String lp ) {
|
public int getLoginUserId() {
|
||||||
loginPassword = lp;
|
return loginUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginStatus( String ls ) {
|
public String getLoginRole() {
|
||||||
loginStatus = ls;
|
return loginRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginUserId(int int_val) {
|
public String getDuplicatePassword() {
|
||||||
loginUserId=int_val;
|
return duplicatePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginRole( String lr ) {
|
public String getEmailAddress() {
|
||||||
loginRole = lr;
|
return emailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDuplicatePassword( String dp ) {
|
public String getErrorMsg(String s) {
|
||||||
duplicatePassword = dp;
|
String errorMsg = (String) errors.get(s.trim());
|
||||||
}
|
return (errorMsg == null) ? "" : errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
public void setEmailAddress( String ea ) {
|
/********************** SET METHODS *********************/
|
||||||
emailAddress = ea;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMsg( String key, String msg ) {
|
public void setUserURI(String uri) {
|
||||||
errors.put( key,msg );
|
this.userURI = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSessionId(String id) {
|
||||||
|
sessionId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginBrowser(String b) {
|
||||||
|
loginBrowser = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginRemoteAddr(String ra) {
|
||||||
|
loginRemoteAddr = ra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginName(String ln) {
|
||||||
|
loginName = ln;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginPassword(String lp) {
|
||||||
|
loginPassword = lp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginStatus(String ls) {
|
||||||
|
loginStatus = ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginUserId(int int_val) {
|
||||||
|
loginUserId = int_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginRole(String lr) {
|
||||||
|
loginRole = lr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuplicatePassword(String dp) {
|
||||||
|
duplicatePassword = dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailAddress(String ea) {
|
||||||
|
emailAddress = ea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMsg(String key, String msg) {
|
||||||
|
errors.put(key, msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue