?? auth.java
字號(hào):
package com.everstar.usermanage;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import com.everstar.database.*;
public class Auth
{
private Database dbConn;
public Auth(Database dbConn)
{
this.dbConn = dbConn;
}
public AuthInformation setAuth(String userName,String password)
{
//String adminName=PropertyManager.getProperty("AdminUserName");
String adminName="admin";
//String adminPassword=PropertyManager.getProperty("AdminPassword");
String adminPassword="admin";
int userid=0;
boolean isSubAdmin=false;
boolean isnomaluser=false;
Vector userPerm = new Vector();
int theSubSystem=0;
//if the user is administrator
if (userName.equalsIgnoreCase(adminName)&& password.equalsIgnoreCase(adminPassword))
{
AuthInformation AuthInfo = new AuthInformation();
AuthInfo.setUserID(0);
AuthInfo.setUsername(userName);
AuthInfo.setAnonymous(false);
AuthInfo.setNomaluser(false);
AuthInfo.setAdmin(true);
AuthInfo.setSubAdmin(false);
AuthInfo.setTheSubSystem(0);
AuthInfo.setUserPerm(new Vector());
return AuthInfo;
}
else
{
//Identify the user in JiveUser
int usercount = 0;
try
{
String FIND_USER = "select count(*) from JIVEUSER "
+" where rtrim(username)='"+userName+"' and passwordhash='"+StringUtils.hash(password)+"' and valid=1";
ResultSet rs =dbConn.select(FIND_USER);
rs.next();
usercount = rs.getInt(1);
rs.close();
dbConn.close();
}
catch( Exception e )
{
e.printStackTrace();
}
if (usercount == 0) //the user is not exist
{
return null;
}
else
{
// get userid
try
{
String GET_USER_ID = "select userid from JIVEUSER "
+" where rtrim(username)='"+userName+"' and passwordhash='"+StringUtils.hash(password)+"' and valid=1";
ResultSet rs =dbConn.select(GET_USER_ID);
if(rs.next())
userid = rs.getInt(1);
rs.close();
dbConn.close();
}
catch( Exception e )
{
e.printStackTrace();
}
// the user is the systemmanager;
try
{
String IS_SUB_SYS_MANAGER = "select count(*) from SUBSYSTEM where managerid="+userid;
ResultSet rs =dbConn.select(IS_SUB_SYS_MANAGER);
int temp=0;
if(rs.next())
temp = rs.getInt(1);
rs.close();
dbConn.close();
if (temp==0)
{
isSubAdmin = false;
isnomaluser =true;
}
else
{
isSubAdmin = true;
isnomaluser =false;
}
}
catch( Exception e )
{
e.printStackTrace();
}
// get the system managed by the user
if(isSubAdmin)
{
try {
String SYS_MANAGER = "select systemid from SUBSYSTEM where managerid="+userid;
ResultSet rs =dbConn.select(SYS_MANAGER);
if(rs.next())
theSubSystem = rs.getInt(1);
rs.close();
dbConn.close();
}
catch( Exception e ) { e.printStackTrace();}
}
// get the user perms
//if(isnomaluser)
//{
try {
String USER_PERM = "select operate from PERMS where userid="+userid;
ResultSet rs =dbConn.select(USER_PERM);
while(rs.next())
{
String oprateName= rs.getString(1);
userPerm.add(oprateName);
//System.out.println("key:="+sid+" "+"value:="+fid);
}
rs.close();
dbConn.close();
}
catch( Exception e ) { e.printStackTrace();}
//}
//put the user information and his perms into session
AuthInformation AuthInfo = new AuthInformation();
AuthInfo.setUserID(userid);
AuthInfo.setUsername(userName);
AuthInfo.setAnonymous(false);
AuthInfo.setNomaluser(isnomaluser);
AuthInfo.setAdmin(false);
AuthInfo.setSubAdmin(isSubAdmin);
AuthInfo.setTheSubSystem(theSubSystem);
AuthInfo.setUserPerm(userPerm);
return AuthInfo;
}
}
}//end
//get the login username
public static String getUserName(HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return null;
else
return AuthInfo.getUsername();
}
public static int getUserID(HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return 0;
else
return AuthInfo.getUserID();
}
// check if the session is empty;
public static boolean islogin(HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return false;
else
return true;
}
// if the user have perm
public static boolean havePerm(String operate, HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return false;
else
{
Vector myperm=AuthInfo.getUserPerm();
if (myperm==null || myperm.isEmpty())
return false;
else
return myperm.contains(operate);
}
}
//check if the user is normaluser
public static boolean checkNormalUser (HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return false;
else
{
return AuthInfo.isNomaluser();
}
}
//check if the user is administrator
public static boolean checkAdmin (HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return false;
else
{
return AuthInfo.isAdmin();
}
}
//check if the user is subsystem manager
public static boolean checkSubAdmin (HttpSession AuthInfoPool)
{
AuthInformation AuthInfo = (AuthInformation)AuthInfoPool.getValue("Webstar.userPerm");
if (AuthInfo==null)
return false;
else
{
boolean subAdmin=AuthInfo.isSubAdmin();
return subAdmin;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -