Home > FAQs > Can we use Acegi Security with the framework

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

Step 1 - Declaring Authz Interface

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

Step 2 - Implementing Authz Interceptor

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

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

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

Step 5 - Declaring action

<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

Actualy you are logged as $authz.principal

Contributed by Luca Marrocco.