this.authService = authService;
setVerifier(new Verifier() {
public int verify(Request request, Response response) {
request.getAttributes().put(App.AUTH_SERVICE_ATTR,UserGuard.this.authService);
ChallengeResponse cr = request.getChallengeResponse();
Cookie cookie = request.getCookies().getFirst("I");
// We must have one of these to check
if (cr==null && cookie==null) {
return Verifier.RESULT_MISSING;
}
// If we have new credentials, check them first
if (cr!=null) {
String identifier = request.getChallengeResponse()
.getIdentifier();
char[] secret = request.getChallengeResponse().getSecret();
// Check the credentials
if ((identifier != null) && (secret != null)) {
if (getLogger().isLoggable(Level.FINE)) {
getLogger().fine("Authenticating " + identifier);
}
try {
User user = UserGuard.this.authService.authenticate(identifier, new String(secret));
if (user != null) {
if (getLogger().isLoggable(Level.FINE)) {
getLogger().fine("Authenticated: " + user.getAlias() + ", checking groups");
}
}
user = checkUser(request, user);
if (user!=null) {
return Verifier.RESULT_VALID;
}
} catch (AuthException ex) {
getContext().getLogger().log(Level.SEVERE, "Cannot check authentication.", ex);
}
}
}
// Check the identity cookie
if (cookie != null) {
try {
User user = UserGuard.this.authService.verifySession(cookie.getValue());
if (user != null) {
if (getLogger().isLoggable(Level.FINE)) {
getLogger().fine("Valid session for: " + user.getAlias() + ", checking groups");
}
}