use of org.polymap.core.security.SecurityContext in project polymap4-core by Polymap4.
the class ServiceContext2 method execute.
public <E extends Exception> void execute(Task<E> task) throws E {
// XXX no GeoServerClassLoader; just one instance per JVM
// assert context.cl != null;
// ClassLoader orig = Thread.currentThread().getContextClassLoader();
// Thread.currentThread().setContextClassLoader( context.cl );
// assert Thread.currentThread().getContextClassLoader() == context.cl;
SessionContext current = SessionContext.current();
assert current == null : "Thread already mapped to a SessionContext: " + current.getSessionKey();
try {
boolean mapped = contextProvider.mapContext(sessionKey, true);
log.debug("SessionContext: " + SessionContext.current());
assert mapped : "Thread already mapped to a SessionContext: " + SessionContext.current().getSessionKey();
SecurityContext securityContext = SecurityContext.instance();
if (!securityContext.isLoggedIn()) {
// XXX this user is used to authenticate upstream mapzone services
securityContext.loginTrusted("admin");
}
task.call();
} finally {
// Thread.currentThread().setContextClassLoader( orig );
contextProvider.unmapContext();
}
}
use of org.polymap.core.security.SecurityContext 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