1 40 package org.dspace.app.webui.filter; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 45 import javax.servlet.Filter ; 46 import javax.servlet.FilterChain ; 47 import javax.servlet.FilterConfig ; 48 import javax.servlet.ServletException ; 49 import javax.servlet.ServletRequest ; 50 import javax.servlet.ServletResponse ; 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 54 import org.apache.log4j.Logger; 55 import org.dspace.app.webui.util.Authenticate; 56 import org.dspace.app.webui.util.JSPManager; 57 import org.dspace.app.webui.util.UIUtil; 58 import org.dspace.authorize.AuthorizeManager; 59 import org.dspace.core.Context; 60 import org.dspace.core.LogManager; 61 62 70 public class AdminOnlyFilter implements Filter 71 { 72 73 private static Logger log = Logger.getLogger(RegisteredOnlyFilter.class); 74 75 public void init(FilterConfig config) 76 { 77 } 79 80 public void doFilter(ServletRequest request, ServletResponse response, 81 FilterChain chain) throws ServletException , IOException 82 { 83 Context context = null; 84 85 HttpServletRequest hrequest = (HttpServletRequest ) request; 87 HttpServletResponse hresponse = (HttpServletResponse ) response; 88 89 try 90 { 91 context = UIUtil.obtainContext(hrequest); 93 94 if (context.getCurrentUser() != null || 97 Authenticate.startAuthentication(context, hrequest, hresponse)) 98 { 99 if (AuthorizeManager.isAdmin(context)) 101 { 102 chain.doFilter(hrequest, hresponse); 104 } 105 else 106 { 107 log.info(LogManager.getHeader(context, "admin_only", "")); 109 JSPManager.showAuthorizeError(hrequest, hresponse, null); 110 } 111 } 112 } 113 catch (SQLException se) 114 { 115 log.warn(LogManager.getHeader(context, "database_error", se 116 .toString()), se); 117 JSPManager.showInternalError(hrequest, hresponse); 118 } 119 120 if ((context != null) && context.isValid()) 122 { 123 context.abort(); 124 } 125 } 126 127 public void destroy() 128 { 129 } 131 } 132 | Popular Tags |