Can we use Acegi Security with the framework

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

The following details a possible integration of Acegi Security with WebWork:-

Step 1 - Declaring Authz Interface

Code Block
import org.acegisecurity.taglibs.velocity.Authz;
public interface AuthzAware {
        void setAuthz(Authz authz);
}

Step 2 - Implementing Authz Interceptor

Code Block
import org.acegisecurity.taglibs.velocity.Authz;
import org.acegisecurity.taglibs.velocity.AuthzImpl;
import package.api.AuthzAware;
 
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
 
public class AuthzInterceptor implements Interceptor {
        public void destroy()
        {}
 
        public void init()
        {}
 
        public String intercept(ActionInvocation invocation)
                throws Exception
        {
                if (invocation.getAction() instanceof AuthzAware) {
                        Authz authz = new AuthzImpl();
 
                        AuthzAware authzAware = (AuthzAware)invocation.getAction();
                        authzAware.setAuthz(authz);
                }
 
                return invocation.invoke();
        }
}

Step 3 - Making AuthzAware action

Code Block
import org.acegisecurity.taglibs.velocity.Authz;
import package.api.AuthzAware;
import com.opensymphony.xwork.ActionSupport;
 
 
public class DashboardAction extends ActionSupport implements AuthzAware
{
        private Authz authz;
 
        public Authz getAuthz(){
                return authz;
        }
 
        public void setAuthz(Authz authz)
        {
                this.authz = authz;
        }
 
        public String execute() throws Exception
        {
                return SUCCESS;
        }
}

Step 4 - Declaring interceptor

Code Block
<interceptor name="authz" class="package.interceptor.AuthzInterceptor"/>

Step 5 - Declaring action

Code Block
<action name="dashboard" class="package.action.DashboardAction">
        <interceptor-ref name="authz" />
        <result type="velocity" name="success">dashboard.vm</result>
</action>

Step 6 - mplementing dashboard.vm

Code Block
Actualy you are logged as $authz.principal

...