use of org.polymap.core.security.UserPrincipal in project polymap4-core by Polymap4.
the class SecurityManagerAdapter method authenticate.
public Object authenticate(String user, String passwd) {
HttpServletRequest req = io.milton.servlet.ServletRequest.getRequest();
final HttpSession session = req.getSession();
UserPrincipal sessionUser = (UserPrincipal) session.getAttribute("sessionUser");
if (sessionUser == null) {
log.info("WebDAV login: " + user);
SecurityContext sc = SecurityContext.instance();
if (sc.isLoggedIn()) {
log.info("Already logged in as: " + sc.getUser().getName());
sessionUser = (UserPrincipal) sc.getUser();
session.setAttribute("sessionUser", sessionUser);
return WebDavServer.createNewSession(sessionUser);
} else if (sc.login(user, passwd)) {
sessionUser = (UserPrincipal) sc.getUser();
session.setAttribute("sessionUser", sessionUser);
return WebDavServer.createNewSession(sessionUser);
} else {
log.warn("Login failed.");
return null;
}
}
return sessionUser != null && sessionUser.getName().equals(user) ? sessionUser : null;
}
Aggregations