use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.
the class UserPrincipalDecoderTest method testHttpBasicDecoding.
@Test
public void testHttpBasicDecoding() {
dummyRequest.setHeader("authorization", "Basic Zm9vOmJhcg==");
User result = decoder.fromRequest(dummyRequest);
assertNotNull(result);
assertEquals("foo", result.getUsername());
assertNull(result.getId());
assertFalse(result.isTimeouted());
}
use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.
the class UserPlugin method isAllowed.
@Override
public boolean isAllowed(HttpServletRequest request, Group group) {
User user;
if ((user = (User) request.getAttribute(REQUEST_ATTR)) == null) {
user = decoder.fromRequest(request);
request.setAttribute(REQUEST_ATTR, user);
}
return user != null;
}
use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.
the class UserPlugin method isAllowed.
@Override
public boolean isAllowed(HttpServletRequest request, Project project) {
User user;
if ((user = (User) request.getAttribute(REQUEST_ATTR)) == null) {
user = decoder.fromRequest(request);
request.setAttribute(REQUEST_ATTR, user);
}
return user != null;
}
use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.
the class UserPlugin method getUser.
private User getUser(HttpServletRequest request) {
User user;
if ((user = (User) request.getAttribute(REQUEST_ATTR)) == null) {
user = decoder.fromRequest(request);
request.setAttribute(REQUEST_ATTR, user);
}
return user;
}
use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.
the class OSSOHeaderDecoder method fromRequest.
@Override
public User fromRequest(HttpServletRequest request) {
String username, userguid, timeouted, timestamp;
Date cookieTimestamp = null;
// Avoid classification as a taint bug.
username = Laundromat.launderInput(request.getHeader(OSSO_USER_DN_HEADER));
timeouted = Laundromat.launderInput(request.getHeader(OSSO_TIMEOUT_EXCEEDED_HEADER));
timestamp = Laundromat.launderInput(request.getHeader(OSSO_COOKIE_TIMESTAMP_HEADER));
userguid = Laundromat.launderInput(request.getHeader(OSSO_USER_GUID_HEADER));
if (username == null || username.isEmpty()) {
LOGGER.log(Level.WARNING, "Can not construct an user: username could not be extracted from headers: {0}", String.join(",", Collections.list(request.getHeaderNames())));
return null;
}
if (userguid == null || userguid.isEmpty()) {
LOGGER.log(Level.WARNING, "Can not construct an user: userguid could not be extracted from headers: {0}", String.join(",", Collections.list(request.getHeaderNames())));
return null;
}
/**
* The timestamp cookie can be corrupted.
*/
try {
cookieTimestamp = Timestamp.decodeTimeCookie(timestamp);
} catch (NumberFormatException ex) {
LOGGER.log(Level.WARNING, String.format("Unparseable timestamp cookie \"%s\" for user \"%s\"", timestamp, username), ex);
}
/**
* Creating new user entity with provided information. The entity can be
* checked if the timeout expired via {@link User#isTimeouted()}.
*/
User user = new User(username, userguid, cookieTimestamp, "true".equalsIgnoreCase(timeouted));
user.setAttribute("subscriber-dn", request.getHeader(OSSO_SUBSCRIBER_DN_HEADER));
user.setAttribute("subscriber", request.getHeader(OSSO_SUBSCRIBER_HEADER));
if (user.isTimeouted()) {
LOGGER.log(Level.WARNING, "Can not construct an user \"{0}\": header is timeouted", username);
return null;
}
return user;
}
Aggregations