Apache Struts 2 Documentation > Home > FAQs > Can we use Acegi Security with the framework |
The following details a possible integration of Acegi Security with WebWork:-
import org.acegisecurity.taglibs.velocity.Authz; public interface AuthzAware { void setAuthz(Authz authz); }
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(); } }
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; } }
<interceptor name="authz" class="package.interceptor.AuthzInterceptor"/>
<action name="dashboard" class="package.action.DashboardAction"> <interceptor-ref name="authz" /> <result type="velocity" name="success">dashboard.vm</result> </action>
Actualy you are logged as $authz.principal
Contributed by Luca Marrocco.