Ejemplo n.º 1
0
 @Override
 public User authenticate(Resource r, DigestResponse digestRequest) {
   log.debug("authenticate(digest): " + digestRequest.getUser());
   if (r instanceof Templatable) {
     Templatable resource = (Templatable) r;
     NameAndAuthority na = NameAndAuthority.parse(digestRequest.getUser());
     User u = null;
     if (na.authority == null) {
       Host h = resource.getHost();
       u = authenticateRecursive(h, na.name, digestRequest);
     } else {
       Host host = findHost(resource, na.authority);
       if (host == null) {
         log.debug("authenticate: host not found: " + na.authority);
         return null;
       } else {
         u = host.doAuthenticate(na.name, digestRequest);
       }
     }
     if (u == null) {
       log.warn("Authentication failed: " + na.name);
     }
     return u;
   } else if (r instanceof DigestResource) {
     DigestResource dr = (DigestResource) r;
     return (User) dr.authenticate(digestRequest);
   } else {
     throw new RuntimeException(
         "Cant authenticate against resource of type: " + r.getClass().getCanonicalName());
   }
 }
Ejemplo n.º 2
0
 public Host findHost(Templatable resource, String authority) {
   Host h = resource.getHost();
   while (h != null && !h.getName().equals(authority)) {
     h = h.getParentHost();
   }
   return h;
 }
Ejemplo n.º 3
0
 @Override
 public User authenticate(Resource r, String user, String password) {
   // log.debug("authenticate: " + user);
   if (r instanceof Templatable) {
     Templatable resource = (Templatable) r;
     NameAndAuthority na = NameAndAuthority.parse(user);
     User u = null;
     if (na.authority == null) {
       Host h = resource.getHost();
       LogUtils.trace(log, "authenticate: no authority given, so use current host", h.getName());
       u = authenticateRecursive(h, na.name, password);
     } else {
       Host host = findHost(resource, na.authority);
       if (host == null) {
         log.warn("authenticate: host not found: " + na.authority);
         return null;
       } else {
         u = host.doAuthenticate(na.name, password);
         LogUtils.trace(
             log, "authenticate: authenticating on specified host", host.getName(), "result:", u);
       }
     }
     if (u == null) {
       log.warn("Authentication failed: " + na.name);
     }
     return u;
   } else {
     return (User) r.authenticate(user, password);
   }
 }