Examples of HttpPrincipal


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

Examples of com.sun.net.httpserver.HttpPrincipal

            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

Examples of com.sun.net.httpserver.HttpPrincipal

   
    // 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

Examples of com.sun.net.httpserver.HttpPrincipal

          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

Examples of com.sun.net.httpserver.HttpPrincipal

            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

Examples of com.sun.net.httpserver.HttpPrincipal

  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

Examples of org.apache.camel.component.netty.http.HttpPrincipal

                // assume any roles is valid if no security constraint has been configured
                roles = "*";
            }
            if (roles != null) {
                // basic auth subject
                HttpPrincipal principal = extractBasicAuthSubject(request);

                // authenticate principal and check if the user is in role
                Subject subject = null;
                boolean inRole = true;
                if (principal != null) {
                    subject = authenticate(security.getSecurityAuthenticator(), security.getLoginDeniedLoggingLevel(), principal);
                    if (subject != null) {
                        String userRoles = security.getSecurityAuthenticator().getUserRoles(subject);
                        inRole = matchesRoles(roles, userRoles);
                    }
                }

                if (principal == null || subject == null || !inRole) {
                    if (principal == null) {
                        LOG.debug("Http Basic Auth required for resource: {}", url);
                    } else if (subject == null) {
                        LOG.debug("Http Basic Auth not authorized for username: {}", principal.getUsername());
                    } else {
                        LOG.debug("Http Basic Auth not in role for username: {}", principal.getUsername());
                    }
                    // restricted resource, so send back 401 to require valid username/password
                    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, UNAUTHORIZED);
                    response.headers().set("WWW-Authenticate", "Basic realm=\"" + security.getRealm() + "\"");
                    response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
                    response.headers().set(Exchange.CONTENT_LENGTH, 0);
                    response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
                    messageEvent.getChannel().write(response);
                    return;
                } else {
                    LOG.debug("Http Basic Auth authorized for username: {}", principal.getUsername());
                }
            }
        }

        // let Camel process this message
View Full Code Here

Examples of org.apache.camel.component.netty.http.HttpPrincipal

                    ChannelBuffer buf = ChannelBuffers.copiedBuffer(decoded.getBytes());
                    ChannelBuffer out = Base64.decode(buf);
                    String userAndPw = out.toString(Charset.defaultCharset());
                    String username = ObjectHelper.before(userAndPw, ":");
                    String password = ObjectHelper.after(userAndPw, ":");
                    HttpPrincipal principal = new HttpPrincipal(username, password);

                    LOG.debug("Extracted Basic Auth principal from HTTP header: {}", principal);
                    return principal;
                }
            }
View Full Code Here

Examples of org.apache.camel.component.netty.http.HttpPrincipal

                // assume any roles is valid if no security constraint has been configured
                roles = "*";
            }
            if (roles != null) {
                // basic auth subject
                HttpPrincipal principal = extractBasicAuthSubject(request);

                // authenticate principal and check if the user is in role
                Subject subject = null;
                boolean inRole = true;
                if (principal != null) {
                    subject = authenticate(security.getSecurityAuthenticator(), security.getLoginDeniedLoggingLevel(), principal);
                    if (subject != null) {
                        String userRoles = security.getSecurityAuthenticator().getUserRoles(subject);
                        inRole = matchesRoles(roles, userRoles);
                    }
                }

                if (principal == null || subject == null || !inRole) {
                    if (principal == null) {
                        LOG.debug("Http Basic Auth required for resource: {}", url);
                    } else if (subject == null) {
                        LOG.debug("Http Basic Auth not authorized for username: {}", principal.getUsername());
                    } else {
                        LOG.debug("Http Basic Auth not in role for username: {}", principal.getUsername());
                    }
                    // restricted resource, so send back 401 to require valid username/password
                    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, UNAUTHORIZED);
                    response.setHeader("WWW-Authenticate", "Basic realm=\"" + security.getRealm() + "\"");
                    response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
                    response.setHeader(Exchange.CONTENT_LENGTH, 0);
                    response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
                    messageEvent.getChannel().write(response);
                    return;
                } else {
                    LOG.debug("Http Basic Auth authorized for username: {}", principal.getUsername());
                }
            }
        }

        // let Camel process this message
View Full Code Here

Examples of org.apache.camel.component.netty.http.HttpPrincipal

                    ChannelBuffer buf = ChannelBuffers.copiedBuffer(decoded.getBytes());
                    ChannelBuffer out = Base64.decode(buf);
                    String userAndPw = out.toString(Charset.defaultCharset());
                    String username = ObjectHelper.before(userAndPw, ":");
                    String password = ObjectHelper.after(userAndPw, ":");
                    HttpPrincipal principal = new HttpPrincipal(username, password);

                    LOG.debug("Extracted Basic Auth principal from HTTP header: {}", principal);
                    return principal;
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.