Skip to content

Instantly share code, notes, and snippets.

@beatty
Created June 3, 2010 22:35
Show Gist options
  • Save beatty/424618 to your computer and use it in GitHub Desktop.
Save beatty/424618 to your computer and use it in GitHub Desktop.
@Singleton
public class AuthFilter<R extends Request> extends BaseFilter<R> {
private final String loginUrl;
@Inject
public AuthFilter(@Named("loginUrl") String loginUrl) {
this.loginUrl = loginUrl;
}
@Override
public Response before(R request, Class<? extends Handler<R>> handlerClass) {
if (handlerClass.getAnnotation(RequiresLogin.class) != null && !request.isLoggedIn()) {
return new RedirectResponse(loginUrl + "?target=" + request.getReconstructedUrl());
} else {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment