Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain)
- throws IOException, ServletException {
- if (debug) {
- log("NPNSessionFilter:doFilter()");
- }
- // Create wrappers for the request and response objects.
- // Using these, you can extend the capabilities of the
- // request and response, for example, allow setting parameters
- // on the request before sending the request to the rest of the filter chain,
- // or keep track of the cookies that are set on the response.
- //
- // Caveat: some servers do not handle wrappers very well for forward or
- // include requests.
- RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest) request);
- ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse) response);
- doBeforeProcessing(wrappedRequest, wrappedResponse);
- Throwable problem = null;
- AbstractSiteAccess access = null;
- Connection dbconn = null;
- try {
- //NPN - Check access to protected content
- dbconn =
- DBConn.getConnection(ServiceLocator.getInstance().
- getDataSource(DBConn.USANPN_DS_NAME));
- access =
- new SiteAccessDrupal();
- access.verifyAccess(wrappedRequest, wrappedResponse, dbconn);
- chain.doFilter(wrappedRequest, wrappedResponse);
- } catch (Throwable t) {
- // If an exception is thrown somewhere down the filter chain,
- // we still want to execute our after processing, and then
- // rethrow the problem after that.
- problem = t;
- Logger.getLogger(NPNSessionFilter.class.getName()).log(
- Level.INFO,
- t.getLocalizedMessage());
- for(StackTraceElement e : t.getStackTrace()){
- StringBuffer sb = new StringBuffer();
- sb.append(e.getClassName());
- sb.append(":");
- sb.append(e.getFileName());
- sb.append(":");
- sb.append(e.getMethodName());
- sb.append(":");
- sb.append(e.getLineNumber());
- System.out.println(sb.toString());
- }
- }finally{
- DBConn.closeConnection(dbconn);
- }
- doAfterProcessing(wrappedRequest, wrappedResponse);
- // If there was a problem, we want to rethrow it if it is
- // a known type, otherwise log it.
- if (problem != null) {
- if (problem instanceof ServletException) {
- throw (ServletException) problem;
- }
- if (problem instanceof IOException) {
- throw (IOException) problem;
- }
- //NPN - Handle the problem
- if (problem instanceof AccessControlException) {
- try {
- access.handleAccessProblem(wrappedRequest, wrappedResponse, problem);
- } catch (Exception ex) {
- Logger.getLogger(NPNSessionFilter.class.getName()).log(Level.SEVERE, null, ex);
- }
- return;
- }
- sendProcessingError(problem, response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement