1 19 20 package org.efs.openreports.interceptors; 21 22 import com.opensymphony.xwork.*; 23 import com.opensymphony.xwork.interceptor.Interceptor; 24 import com.opensymphony.xwork.interceptor.component.ComponentManager; 25 26 import org.efs.openreports.ORStatics; 27 import org.efs.openreports.objects.ReportUser; 28 import org.efs.openreports.util.LocalStrings; 29 30 public class SecurityInterceptor implements Interceptor 31 { 32 private boolean loggedIn; 33 private ReportUser user; 34 35 public String intercept(ActionInvocation actionInvocation) throws Exception 36 { 37 ComponentManager container = 38 (ComponentManager) ActionContext.getContext().get( 39 "com.opensymphony.xwork.interceptor.component.ComponentManager"); 40 41 if (container != null) 42 { 43 container.initializeObject(this); 44 } 45 46 user = (ReportUser) actionInvocation.getInvocationContext().getSession().get( 47 "user"); 48 49 if (!isAuthenticated(user)) 50 { 51 ActionSupport action = (ActionSupport) actionInvocation.getAction(); 52 action.addActionError(LocalStrings.getString(LocalStrings.ERROR_NOTLOGGEDIN)); 53 54 return Action.LOGIN; 55 } 56 57 if (!isAuthorized(user)) 58 { 59 ActionSupport action = (ActionSupport) actionInvocation.getAction(); 60 action.addActionError(LocalStrings.getString(LocalStrings.ERROR_NOTAUTHORIZED)); 61 62 return ORStatics.NOT_AUTHORIZED; 63 } 64 65 ActionContext.getContext().getValueStack().push(this); 66 67 return actionInvocation.invoke(); 68 } 69 70 protected boolean isAuthenticated(ReportUser user) 71 { 72 if (user == null) 73 { 74 loggedIn = false; 75 return false; 76 } 77 78 loggedIn = true; 79 return true; 80 } 81 82 protected boolean isAuthorized(ReportUser user) 83 { 84 return true; 85 } 86 87 public void destroy() 88 { 89 } 90 91 public void init() 92 { 93 } 94 95 public boolean isLoggedIn() 96 { 97 return loggedIn; 98 } 99 100 public ReportUser getUser() 101 { 102 return user; 103 } 104 } 105 | Popular Tags |