4 Replies Latest reply on Feb 21, 2007 12:13 PM by monkeyden

    @LoggedIn at the method level

    monkeyden

      @LoggedIn in the docs is at the TYPE level. Has anyone gotten it to work at the method level? It doesnt seem to be intercepting the method call. I'd like to allow the "list function" of a screen but not the edit function if the user is not logged in.

      @Target(METHOD)
      @Retention(RUNTIME)
      @Interceptors(LoggedInInterceptor.class)
      public @interface LoggedIn {}


      @Stateful
      @Name("safe")
      @Scope(SESSION)
      public class SafeAction implements Safe {
       @Logger
       private Log log;
      
       @LoggedIn
       public String pingMe(){
       log.debug("Pinging me");
       return "success";
       }
      
       public String pingMeToo(){
       log.debug("Pinging me too");
       return "home";
       }
      
       @Destroy @Remove
       public void destroy(){
      
       }
      }


      public class LoggedInInterceptor {
      
       @Logger
       private Log log;
      
       @AroundInvoke
       public Object checkLoggedIn(InvocationContext invocation) throws Exception {
       boolean isLoggedIn = Contexts.getSessionContext().get("user")!=null;
       try {
       if (isLoggedIn) {
       return invocation.proceed();
       } else {
       throw new SecurityException();
       }
       } catch (SecurityException se) {
       log.debug("Login required");
       return "login";
       }
       }
      }