Пример #1
0
  private User authenticateRecursive(Host h, String name, String password) {
    User u = h.doAuthenticate(name, password);
    if (u != null) {
      if (log.isTraceEnabled()) {
        LogUtils.trace(
            log,
            "authenticateRecursive: authenticated ok on host: ",
            h.getName(),
            "user",
            name,
            password,
            "->",
            u.getPath());
      }
      return u;
    }

    Host hParent = h.getParentHost();
    if (hParent == null) {
      LogUtils.trace(log, "authenticateRecursive: reached null host for user name: ", name);
      return null;
    } else {
      LogUtils.trace(log, "authenticateRecursive: not found here, delegate to parent host");
      return authenticateRecursive(hParent, name, password);
    }
  }
Пример #2
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);
   }
 }