Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpPrincipal


     * the method returns null.
     * @return a String containing the name of the user making this request; null if the user has not been authenticated.
     */
    public String getPrincipal()
    {
        HttpPrincipal principal = _exchange.getPrincipal();
        return principal == null ? null : principal.getUsername();
    }
View Full Code Here


            if (auth != null)
            {
                Authenticator.Result authResult = auth.authenticate(jettyHttpExchange);
                if (authResult instanceof Authenticator.Success)
                {
                    HttpPrincipal p = ((Authenticator.Success)authResult).getPrincipal();
                    jettyHttpExchange.setPrincipal(p);
                    invokeHandler(jettyHttpExchange);
                }
                else  if (authResult instanceof Authenticator.Failure)
                {
View Full Code Here

   
    // FIXME: #security: If the request is to log in then we should check the username and password no matter what!
    // Currently we don't if we happen to be at a page that doesn't require authentication.
   
    if (allowedFileRequest(exchange.getRequestURI().getPath())) {
      return new Authenticator.Success(new HttpPrincipal("", _realm));
    }
   
    Headers rmap = exchange.getRequestHeaders();
   
    boolean isProtectedRequest = this.isProtectedRequest(exchange);
   
    String auth = rmap.getFirst("Authorization");
    if (auth == null) {
      if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
          || ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
          || (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
        Headers map = exchange.getResponseHeaders();
        map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm + "\"");
        return new Authenticator.Retry(401);
      } else {
        return new Authenticator.Success(new HttpPrincipal(User.UnknownUserName, _realm));
      }
    } else {
      int sp = auth.indexOf(' ');
      if (sp == -1 || !auth.substring(0, sp).equals("Basic")) {
        return new Authenticator.Failure(401);
      }
      byte[] b = new Base64().base64ToByteArray(auth.substring(sp + 1));
      String userpass = new String(b);
      int colon = userpass.indexOf(':');
      String uname = userpass.substring(0, colon);
      String pass = userpass.substring(colon + 1);
      if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
          || ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
          || (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
        if (checkCredentials(uname, pass)) {
          return new Authenticator.Success(new HttpPrincipal(uname, _realm));
        } else {
          Headers map = exchange.getResponseHeaders();
          map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm  + "\"");
          return new Authenticator.Failure(401);
        }
      } else {
        return new Authenticator.Success(new HttpPrincipal(uname, _realm));
      }
    }
  }
View Full Code Here

          int rc = ((Authenticator.Retry)result).getResponseCode();
          resp.sendError(rc);
        }
        else if (result instanceof Authenticator.Success)
        {
          HttpPrincipal p = ((Authenticator.Success)result).getPrincipal();
          jettyHttpExchange.setPrincipal(p);
        _handler.handle(jettyHttpExchange);
        }
  }
View Full Code Here

            resp.setStatus(rc);
            resp.flushBuffer();
        }
        else if (result instanceof Authenticator.Success)
        {
            HttpPrincipal principal = ((Authenticator.Success)result).getPrincipal();
            ((JettyExchange)httpExchange).setPrincipal(principal);
            _httpHandler.handle(httpExchange);
        }
    }
View Full Code Here

  public static boolean directmime(String mime) {
    return (mime.equals(MIME_MP4) || mime.equals(MIME_WEBM) || mime.equals(MIME_OGG));
  }

  public static String userName(HttpExchange t) {
    HttpPrincipal p = t.getPrincipal();
    if (p == null) {
      return "";
    }
    return p.getUsername();
  }
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpPrincipal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.