01: package com.technoetic.xplanner.tags;
02:
03: import com.technoetic.xplanner.db.hibernate.ThreadSession;
04: import com.technoetic.xplanner.security.AuthenticationException;
05: import com.technoetic.xplanner.security.SecurityHelper;
06: import com.technoetic.xplanner.security.auth.Authorizer;
07: import com.technoetic.xplanner.security.auth.SystemAuthorizer;
08: import net.sf.hibernate.Session;
09:
10: import javax.servlet.jsp.JspException;
11: import javax.servlet.jsp.PageContext;
12:
13: public class ContextInitiator {
14: public static final String COLLECTION_KEY = "optionCollection";
15: private PageContext pageContext;
16: private Session session;
17: private Authorizer authorizer;
18: private int loggedInUserId;
19:
20: public ContextInitiator(PageContext pageContext) {
21: this .pageContext = pageContext;
22: }
23:
24: public void initStaticContext() {
25: setSession(ThreadSession.get());
26: setAuthorizer(SystemAuthorizer.get());
27: try {
28: setLoggedInUserId(getRemoteUserId());
29: } catch (JspException e) {
30: e.printStackTrace();
31: }
32: }
33:
34: private int getRemoteUserId() throws JspException {
35: try {
36: return SecurityHelper.getRemoteUserId(pageContext);
37: } catch (AuthenticationException e) {
38: throw new JspException(e);
39: }
40: }
41:
42: public Session getSession() {
43: return session;
44: }
45:
46: public Authorizer getAuthorizer() {
47: return authorizer;
48: }
49:
50: public int getLoggedInUserId() {
51: return loggedInUserId;
52: }
53:
54: public void setSession(Session session) {
55: this .session = session;
56: }
57:
58: public void setAuthorizer(Authorizer authorizer) {
59: this .authorizer = authorizer;
60: }
61:
62: public void setLoggedInUserId(int loggedInUserId) {
63: this.loggedInUserId = loggedInUserId;
64: }
65: }
|