throws TransportAuthenticationException {
String path = context.getAttribute("path", String.class);
String privilege = context.getAttribute("privilege", String.class);
if (path == null) {
throw new TransportAuthenticationException(
"the path to authenticate is missing from the context");
}
Session session = null;
try {
session = authenticable.loginService(serviceName, null);
if (session == null) {
throw new TransportAuthenticationException("failed to authenticate" + path);
}
if (!session.hasPermission(path, privilege)) {
session.logout();
throw new TransportAuthenticationException("failed to access path " + path + " with privilege " + privilege);
}
log.info("authenticated path {} with privilege {}", path, privilege);
return session;
} catch (RepositoryException re) {
if (session != null) {
session.logout();
}
throw new TransportAuthenticationException(re);
}
}