2 Replies - 376 Views - Last Post: 10 October 2012 - 03:37 AM Rate Topic: -----

#1 gingerbread  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-October 12

An error in logging 2 different users.

Posted 10 October 2012 - 02:22 AM

Hi Everyone! im a beginner here, and really want to solve this. I have an issue about logging 2 different users, everytime i log in 2 different users with diff browsers, it come up with the same results. it should be differ since it logg in a different users. i searched about this kind of error, and i think its in struts or in the session manager or in interceptor. im really confuse.

here'e the session manager....
package com.lms.actions;

import com.opensymphony.xwork2.ActionContext;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;

   public class SessionMgr implements SessionAware{
   private Map<String , object> session = (Map<String , object>) inv.getInvocationContext();

    Object user = session.get("user");
    
   
    public void setSession(Map map) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
 





and in loginAction

package com.lms.actions;

import com.lms.dataAccess.OraDataAccess;
import com.lms.dataAccess.SqlDataAccess;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
//import com.sun.xml.internal.bind.v2.runtime.Name;

public class LoginAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	OraDataAccess db = new OraDataAccess();
	SqlDataAccess sqldb = new SqlDataAccess();
	PreparedStatement psmt = null;
	Connection con = null;
	static String username;
	public String password;
	public ArrayList<String> array;
	private Map session;
	static String sub_org;

	public String execute() {
		//if(username.equals("admin") && password.equals("admin")){

		if (isUser(username, password)== true) {
			session.put("user",username);
                        session.put("subOrg",sub_org);
			return SUCCESS;
		}else if(isRegUser(username, password) == true){
			session.put("user",username);
                        session.put("subOrg",sub_org);
			return NONE;
		}else{
			addActionerror(getText("error.login"));
			return ERROR;
		}
	}

	public ArrayList<String> getArray() {
		return array;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setSession(Map session) {
		this.session = session;
	}


	
	public Boolean isUser(String username, String password){
		boolean find = false;
		sub_org = null;
		try {
			con = db.getDBConnection();

			String sql="SELECT LMS_SUB_ORG FROM HR.WEB_USER_PANEL WHERE USER_NAME = ? AND USR_PWORD = ?";
			psmt = con.prepareStatement(sql);
			psmt.setString(1, username.toUpperCase());
			psmt.setString(2, password);
			ResultSet rs = psmt.executeQuery();
			String admin = "ADMIN";
			String pm = "PM";
			


            while (rs.next())
                sub_org = rs.getString(1).trim();
        
            if(sub_org .equals(admin) || sub_org.equals(pm))
                find = true;
            else
            	find = false;
            
            System.out.println(sub_org);
            System.out.println(find);
            
			rs.close();
			psmt.close();
			con.close();
		} catch (Exception e) {
			// TODO: handle exception
			find = false;
			System.out.println(e);
		}
		return find;
	}
	
	public boolean isRegUser(String username, String password) {
		boolean find = false;
		try{
			con = sqldb.getDBConnection();
			String sql = "SELECT * FROM USERS WHERE username = ? and password = ? and approval = '1'";
			psmt = con.prepareStatement(sql);
			psmt.setString(1, username);
			psmt.setString(2, password);
			ResultSet rs = psmt.executeQuery();
			if(rs.next()){
				find = true;
			}else{
				find = false;
			}
			rs.close();
			psmt.close();
			con.close();
		}catch(Exception e){
			System.out.println("error isRegUser:\n");
		}
		return find;
	}
}



Thank you in Advance guys! :)

Is This A Good Question/Topic? 0
  • +

Replies To: An error in logging 2 different users.

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1401
  • View blog
  • Posts: 3,109
  • Joined: 05-April 11

Re: An error in logging 2 different users.

Posted 10 October 2012 - 03:34 AM

Static username and public password, and where do you set these variables?

I am expecting horror
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: An error in logging 2 different users.

Posted 10 October 2012 - 03:37 AM

Make a constructor for your SessionManager so you can debug. This is an horror

   private Map<String , object> session = (Map<String , object>) inv.getInvocationContext();  

   Object user = session.get("user");     


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1