// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java
// public class Session {
// 	private String id;
// 	private Integer user_id;
// 	private Date create_timestamp;
// 	private HashMap<String, Object> sessionMap;
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 	public Integer getUser_id() {
// 		return user_id;
// 	}
// 	public void setUser_id(Integer user_id) {
// 		this.user_id = user_id;
// 	}
// 	public Date getCreate_timestamp() {
// 		return create_timestamp;
// 	}
// 	public void setCreate_timestamp(Date create_timestamp) {
// 		this.create_timestamp = create_timestamp;
// 	}
// 
// 	public HashMap<String, Object> getSessionMap()
// 	{
// 		if (sessionMap == null)
// 		{
// 			sessionMap = new HashMap<String, Object>();
// 		}
// 		return sessionMap;
// 	}
// 	public void setSessionMap(HashMap<String, Object> sessionMap)
// 	{
// 		this.sessionMap = sessionMap;
// 	}
// 	
// }


import com.webpagebytes.wpbsample.data.Session;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.webpagebytes.cms.WPBForward;
import com.webpagebytes.cms.WPBModel;
import com.webpagebytes.cms.exception.WPBException;

	protected boolean handleAuthentication(HttpServletRequest request,
			HttpServletResponse response, WPBModel model, WPBForward forward, Session session) {
		Map<String, Object> sessionMap = session.getSessionMap();
		Integer userId = (Integer) sessionMap.get(SESSION_LOGIN_USERID); 
		String userName = (String) sessionMap.get(SESSION_LOGIN_USERNAME);
		if (userId == null)
		{
			// user is not logged in, redirect to Login page
			String regPageUri = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get(GLOBALS_LOGIN_PAGE_URI_KEY);
			response.addHeader("Location", regPageUri);
			response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
			return false;
		} else
		{
			model.getCmsApplicationModel().put(SESSION_LOGIN_USERID, userId);	
			model.getCmsApplicationModel().put(SESSION_LOGIN_USERNAME, userName);
		}
		return true;	
	}

    protected boolean handleAuthenticationWithoutRedirect(HttpServletRequest request,
            HttpServletResponse response, WPBModel model, WPBForward forward, Session session) {
        Map<String, Object> sessionMap = session.getSessionMap();
        Integer userId = (Integer) sessionMap.get(SESSION_LOGIN_USERID); 
        String userName = (String) sessionMap.get(SESSION_LOGIN_USERNAME);
        if (userId == null)
        {
            return false;
        } else
        {

// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java
// public class Session {
// 	private String id;
// 	private Integer user_id;
// 	private Date create_timestamp;
// 	private HashMap<String, Object> sessionMap;
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 	public Integer getUser_id() {
// 		return user_id;
// 	}
// 	public void setUser_id(Integer user_id) {
// 		this.user_id = user_id;
// 	}
// 	public Date getCreate_timestamp() {
// 		return create_timestamp;
// 	}
// 	public void setCreate_timestamp(Date create_timestamp) {
// 		this.create_timestamp = create_timestamp;
// 	}
// 
// 	public HashMap<String, Object> getSessionMap()
// 	{
// 		if (sessionMap == null)
// 		{
// 			sessionMap = new HashMap<String, Object>();
// 		}
// 		return sessionMap;
// 	}
// 	public void setSessionMap(HashMap<String, Object> sessionMap)
// 	{
// 		this.sessionMap = sessionMap;
// 	}
// 	
// }


// Path: src/main/java/com/webpagebytes/wpbsample/controllers/GenericController.java
import com.webpagebytes.wpbsample.data.Session;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.webpagebytes.cms.WPBForward;
import com.webpagebytes.cms.WPBModel;
import com.webpagebytes.cms.exception.WPBException;

	protected boolean handleAuthentication(HttpServletRequest request,
			HttpServletResponse response, WPBModel model, WPBForward forward, Session session) {
		Map<String, Object> sessionMap = session.getSessionMap();
		Integer userId = (Integer) sessionMap.get(SESSION_LOGIN_USERID); 
		String userName = (String) sessionMap.get(SESSION_LOGIN_USERNAME);
		if (userId == null)
		{
			// user is not logged in, redirect to Login page
			String regPageUri = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get(GLOBALS_LOGIN_PAGE_URI_KEY);
			response.addHeader("Location", regPageUri);
			response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
			return false;
		} else
		{
			model.getCmsApplicationModel().put(SESSION_LOGIN_USERID, userId);	
			model.getCmsApplicationModel().put(SESSION_LOGIN_USERNAME, userName);
		}
		return true;	
	}

    protected boolean handleAuthenticationWithoutRedirect(HttpServletRequest request,
            HttpServletResponse response, WPBModel model, WPBForward forward, Session session) {
        Map<String, Object> sessionMap = session.getSessionMap();
        Integer userId = (Integer) sessionMap.get(SESSION_LOGIN_USERID); 
        String userName = (String) sessionMap.get(SESSION_LOGIN_USERNAME);
        if (userId == null)
        {
            return false;
        } else
        {

            model.getCmsApplicationModel().put(SESSION_LOGIN_USERID, userId);   
