1 | package edu.iu.uis.sit.portal.web.common; |
2 | |
3 | import javax.servlet.http.HttpServletRequest; |
4 | import javax.servlet.http.HttpServletResponse; |
5 | |
6 | import org.springframework.web.servlet.HandlerInterceptor; |
7 | import org.springframework.web.servlet.ModelAndView; |
8 | |
9 | public class OneStartInterceptor implements HandlerInterceptor { |
10 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OneStartInterceptor.class); |
11 | |
12 | // private ClassifiedsService classifiedsService; |
13 | // private UserService userService; |
14 | |
15 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) throws Exception { |
16 | |
17 | } |
18 | |
19 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
20 | |
21 | } |
22 | |
23 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
24 | // UserSession userSession = (UserSession) request.getSession(true).getAttribute(UserSession.USER_SESSION_KEY); |
25 | // if (!isUserSessionEstablished(request)) { |
26 | // // try { |
27 | // userSession = login(request); |
28 | // request.getSession().setAttribute(UserSession.USER_SESSION_KEY, userSession); |
29 | // // } catch (LoginException le) { |
30 | // // LOG.error("Login Exception.", le); |
31 | // // MyClassifiedsErrors myClassifiedsErrors = new |
32 | // // MyClassifiedsErrors(); |
33 | // // myClassifiedsErrors.setError(getClassifiedsService().getApplicationConstant("Error.Login.GdsUserHasNoAttributes").getConstantValue()); |
34 | // // request.setAttribute("MyClassifiedsErrors", myClassifiedsErrors); |
35 | // // // try { |
36 | // // // super.processForwardConfig(request, response, |
37 | // // moduleConfig.findForwardConfig("ClassifiedsErrorPage")); |
38 | // // // } catch (Exception e) { |
39 | // // // LOG.error("error", e); |
40 | // // // } |
41 | // // return false; |
42 | // // } |
43 | // } |
44 | // if (isAccessDenied(request) || isBannedUser(userSession)) { |
45 | // LOG.info("responding with access denied for request: " + |
46 | // request.getRequestURI() + " with remote user: " + |
47 | // userSession.getUsername() + " from remote addr: " + |
48 | // request.getHeader("X-CLUSTER-CLIENT-IP")); |
49 | // MyClassifiedsErrors myClassifiedsErrors = new MyClassifiedsErrors(); |
50 | // myClassifiedsErrors.setError("<li>You are not currently authorized to |
51 | // use this service."); |
52 | // myClassifiedsErrors.setError("<li>Please contact your administrator |
53 | // or, "); |
54 | // myClassifiedsErrors.setError("<li>Contact: <a |
55 | // href='mailto:onestart.indiana.edu'>OneStart Project Team</a>"); |
56 | // request.setAttribute("MyClassifiedsErrors", myClassifiedsErrors); |
57 | // // try { |
58 | // // super.processForwardConfig(request, response, |
59 | // moduleConfig.findForwardConfig("ClassifiedsErrorPage")); |
60 | // // } catch (Exception e) { |
61 | // // LOG.error("error", e); |
62 | // // } |
63 | // return false; |
64 | // } |
65 | // LOG.info("forwarding request to action servlet for processing: " + |
66 | // request.getRequestURI() + " with remote user: " + |
67 | // userSession.getUsername() + " from remote addr: " + |
68 | // request.getHeader("X-CLUSTER-CLIENT-IP")); |
69 | // addP3pHeaders(request, response); |
70 | return true; |
71 | } |
72 | |
73 | // /** |
74 | // * Checks if the user who made the request has a UserSession established |
75 | // * |
76 | // * @param request |
77 | // * the HTTPServletRequest object passed in |
78 | // * @return true if the user session has been established, false otherwise |
79 | // */ |
80 | // private boolean isUserSessionEstablished(HttpServletRequest request) { |
81 | // return (request.getSession(false) != null && request.getSession(false).getAttribute(UserSession.USER_SESSION_KEY) != null); |
82 | // } |
83 | |
84 | // /** |
85 | // * Adds P3P to response header. |
86 | // * |
87 | // * @param request - |
88 | // * Http Servlet Request. |
89 | // * @param response - |
90 | // * Http Servlet Response. |
91 | // */ |
92 | // private void addP3pHeaders(HttpServletRequest request, |
93 | // HttpServletResponse response) { |
94 | // response.addHeader("P3P", "policyref=\"" + request.getServerName() + ":" |
95 | // + request.getServerPort() + "" + request.getContextPath() + |
96 | // "/w3c/p3p.xml\",CP=\"NON DSP COR CUR ADM OUR NOR UNI STA\""); |
97 | // } |
98 | // |
99 | // |
100 | // /** |
101 | // * Checks if the user who made the request is an administrator |
102 | // * |
103 | // * @param request |
104 | // * the HTTPServletRequest object passed in |
105 | // * @return true if the user session has been established and the user is |
106 | // an admin, false otherwise |
107 | // */ |
108 | // private boolean isAdmin(HttpServletRequest request) { |
109 | // return (isUserSessionEstablished(request) && (((UserSession) |
110 | // request.getSession(false).getAttribute("edu.iu.uis.ccm.ccf.application.UserSession")).getIsAdmin().booleanValue())); |
111 | // } |
112 | // |
113 | // /** |
114 | // * Checks if the request should be allowed |
115 | // * |
116 | // * @param request |
117 | // * HttpServlet Request |
118 | // * @return false if admin true other wise |
119 | // */ |
120 | // private boolean isAccessDenied(HttpServletRequest request) { |
121 | // if (request.getServletPath().startsWith("/Maint")) { |
122 | // if (isAdmin(request)) { |
123 | // return false; |
124 | // } |
125 | // return true; |
126 | // } |
127 | // return false; |
128 | // } |
129 | // |
130 | // /** |
131 | // * create a UserSession object for the user |
132 | // */ |
133 | // private UserSession login(HttpServletRequest request) { |
134 | // // String kerberosUserName = FilterCAS.getRemoteUser(request); |
135 | // // LOG.info("performing Kerberos login: " + kerberosUserName); |
136 | // // String firstName = null; |
137 | // // String lastName = null; |
138 | // // String emailAddress = null; |
139 | // // String campusCode = null; |
140 | // // String personSequenceNumber = null; |
141 | // // List groups = new ArrayList(); |
142 | // // |
143 | // // try { |
144 | // // LOG.info("starting gds lookup: "); |
145 | // // ClassifiedsPerson person = |
146 | // // getUserService().findUserByUsername(kerberosUserName); |
147 | // // |
148 | // // firstName = person.getFirstName(); |
149 | // // lastName = person.getLastName(); |
150 | // // campusCode = person.getCampus(); |
151 | // // personSequenceNumber = person.getPersonId(); |
152 | // // emailAddress = person.getEmailAddress(); |
153 | // // groups = person.getGroups(); |
154 | // // |
155 | // // LOG.info("ending gds lookup: "); |
156 | // // } catch (Exception e) { |
157 | // // LOG.error("Error in gds Kerberos login", e); |
158 | // // } |
159 | // // |
160 | // // /** |
161 | // // * now before we move on, we need to make sure that we have |
162 | // // personSequenceNumber and if we dont then we need to throw a login |
163 | // // error |
164 | // // */ |
165 | // // if (personSequenceNumber == null || |
166 | // // personSequenceNumber.trim().length() < 1) { |
167 | // // LOG.error("Error in kerberos login: no person empl id retrieved"); |
168 | // // throw new LoginException("Error Performing Login, unable to locate |
169 | // // account definition in directory"); |
170 | // // } |
171 | // return new UserSession(); |
172 | // } |
173 | // |
174 | // public ClassifiedsService getClassifiedsService() { |
175 | // return classifiedsService; |
176 | // } |
177 | // |
178 | // public void setClassifiedsService(ClassifiedsService classifiedsService) |
179 | // { |
180 | // this.classifiedsService = classifiedsService; |
181 | // } |
182 | // |
183 | // public UserService getUserService() { |
184 | // return userService; |
185 | // } |
186 | // |
187 | // public void setUserService(UserService userService) { |
188 | // this.userService = userService; |
189 | // } |
190 | } |