String fieldValue = request
.getHeaderValues(HeaderName.AUTHORIZATION)[0];
String encryptedPart = fieldValue
.substring(fieldValue.indexOf(' ') + 1);
authorization = new String(Base64.decode(encryptedPart));
Cookie cookie = new Cookie("auth", authorization);
cookie.setMaxAge(3 * 30 * 24 * 60 * 60);
cookie.setPath("/");
response.setHeader(HeaderName.SET_COOKIE, cookie);
} catch (ArrayIndexOutOfBoundsException ex) {
}
// TODO if login-status cookie indicates failed, consider anyway - or
// give priority to http-auth: problem is: wrong password entered, no
// fixing!
if (authorization == null) {
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookie.getName().equals("auth")) {
authorization = cookie.getValue();
}
}
}
/*
* if (authorization == null) { try { authorization = request