Skip to content

Instantly share code, notes, and snippets.

@nthx
Created December 17, 2011 03:42
Show Gist options
  • Save nthx/1489062 to your computer and use it in GitHub Desktop.
Save nthx/1489062 to your computer and use it in GitHub Desktop.
<bind pointcut="execution(* $instanceof{Action}->execute(*))"
cflow="(notInLoginAction AND notInLogoutAction)">
<advice aspect="AuthorizingAspect" name="checkUserLoggedIn"/>
</bind>
public class AuthorizingAspect
{
public Object checkUserLoggedIn(Invocation invocation)
throws Throwable
{
MethodInvocation mi = (MethodInvocation) invocation;
ActionMapping mapping = (ActionMapping) mi.getArguments()[0];
HttpServletRequest request = (HttpServletRequest) mi.getArguments()[2];
User sessionUser = getUserFromSession(request);
String servletPath = request.getServletPath();
if (servletPath.startsWith("/anonymous/"))
{
return letThrough_becauseAnonymousCall(invocation);
}
if (null == sessionUser)
{
storeUserRequestInSession(request, mapping);
return redirectToLoginPage(mapping);
}
else
{
if (userIsAuthorizedToAction(servletPath, sessionUser))
return letThrough_becauseIsAuthorized(invocation, sessionUser);
else
return redirectToHomePage(mapping, sessionUser);
}
}
private ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment