1 package org.javabb.interceptor; 2 3 import org.javabb.infra.UserContext; 4 import org.javabb.transaction.UserTransaction; 5 import org.javabb.vo.User; 6 7 import com.opensymphony.xwork.Action; 8 import com.opensymphony.xwork.ActionContext; 9 import com.opensymphony.xwork.ActionInvocation; 10 import com.opensymphony.xwork.interceptor.AroundInterceptor; 11 12 27 28 35 public class LoginAdminInterceptor extends AroundInterceptor { 36 37 private UserTransaction userTransaction; 38 39 43 public void setUserTransaction(UserTransaction userTransaction) { 44 this.userTransaction = userTransaction; 45 } 46 47 52 protected void before(ActionInvocation invocation) throws Exception { 53 54 } 55 56 63 protected void after(ActionInvocation invocation, String result) 64 throws Exception { 65 } 66 67 73 public String intercept(ActionInvocation invocation) throws Exception { 74 boolean loggedIn = false; 75 User user = null; 76 ActionContext ctx = ActionContext.getContext(); 77 user = UserContext.getContext().getUser(); 78 if ((user != null) && (user.getUser() != null) 79 && (user.getAdmin() != null) 80 && (user.getAdmin().intValue() == 1)) { 81 user = userTransaction.getUser(user.getId()); 83 if ((user.getAdmin() != null) && (user.getAdmin().intValue() == 1)) { 84 loggedIn = true; 85 } else { 86 loggedIn = false; 87 } 88 } else { 89 loggedIn = false; 90 } 91 92 if (loggedIn == false) { 93 if (UserContext.getContext().isAuthenticated()) { 95 log.debug("Action name: " + ctx.getName()); 96 log.debug("Admin Denied: " 97 + UserContext.getContext().getUser().getUser()); 98 } 99 100 return Action.LOGIN; 102 } 103 104 String result = invocation.invoke(); 106 after(invocation, result); 107 108 return result; 109 } 110 } | Popular Tags |