Package org.apache.catalina.connector

Examples of org.apache.catalina.connector.Request$AsyncContextImpl


   }

   public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
         Subject serviceSubject) throws AuthException
   {
      Request request = (Request) messageInfo.getRequestMessage();
      Response response = (Response) messageInfo.getResponseMessage();
    
      Principal principal;
      context = request.getContext();
      LoginConfig config = context.getLoginConfig();
     
      // Validate any credentials already included with this request
      String username = null;
      String password = null;

      MessageBytes authorization =
          request.getCoyoteRequest().getMimeHeaders()
          .getValue("authorization");
     
      if (authorization != null) {
          authorization.toBytes();
          ByteChunk authorizationBC = authorization.getByteChunk();
          if (authorizationBC.startsWithIgnoreCase("basic ", 0)) {
              authorizationBC.setOffset(authorizationBC.getOffset() + 6);
              // FIXME: Add trimming
              // authorizationBC.trim();
             
              CharChunk authorizationCC = authorization.getCharChunk();
              Base64.decode(authorizationBC, authorizationCC);
             
              // Get username and password
              int colon = authorizationCC.indexOf(':');
              if (colon < 0) {
                  username = authorizationCC.toString();
              } else {
                  char[] buf = authorizationCC.getBuffer();
                  username = new String(buf, 0, colon);
                  password = new String(buf, colon + 1,
                          authorizationCC.getEnd() - colon - 1);
              }
             
              authorizationBC.setOffset(authorizationBC.getOffset() - 6);
          }

          principal = context.getRealm().authenticate(username, password);
          if (principal != null) {
             registerWithCallbackHandler(principal, username, password);
            
              /*register(request, response, principal, Constants.BASIC_METHOD,
                       username, password);*/
             return AuthStatus.SUCCESS;
          }
      }

      // Send an "unauthorized" response and an appropriate challenge
      MessageBytes authenticate =
          response.getCoyoteResponse().getMimeHeaders()
          .addValue(AUTHENTICATE_BYTES, 0, AUTHENTICATE_BYTES.length);
      CharChunk authenticateCC = authenticate.getCharChunk();
      try
      {
         authenticateCC.append("Basic realm=\"");
         if (config.getRealmName() == null) {
            authenticateCC.append(request.getServerName());
            authenticateCC.append(':');
            authenticateCC.append(Integer.toString(request.getServerPort()));
         } else {
            authenticateCC.append(config.getRealmName());
         }
         authenticateCC.append('\"');       
         authenticate.toChars();
View Full Code Here


      this.options = options;
   }

   public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException
   {
      Request request = (Request) messageInfo.getRequestMessage();
      Principal principal = request.getUserPrincipal();
      if(subject != null)
         subject.getPrincipals().remove(principal);
   }
View Full Code Here

   }

   public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
         Subject serviceSubject) throws AuthException
   {
      Request request = (Request) messageInfo.getRequestMessage();
      Response response = (Response) messageInfo.getResponseMessage();
    
      Principal principal;
      context = request.getContext();
      LoginConfig config = context.getLoginConfig();
      
      // References to objects we will need later
      Session session = null;

      //Lets find out if the cache is enabled or not
      cache = (Boolean) messageInfo.getMap().get("CACHE");
     
      // Have we authenticated this user before but have caching disabled?
      if (!cache) {
          session = request.getSessionInternal(true);
          log.debug("Checking for reauthenticate in session " + session);
          String username =
              (String) session.getNote(Constants.SESS_USERNAME_NOTE);
          String password =
              (String) session.getNote(Constants.SESS_PASSWORD_NOTE);
          if ((username != null) && (password != null)) {
              log.debug("Reauthenticating username '" + username + "'");
              principal =
                  context.getRealm().authenticate(username, password);
              if (principal != null) {
                  session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
                  if (!matchRequest(request)) {
                     registerWithCallbackHandler(principal, username, password);
                    
                      /*register(request, response, principal,
                               Constants.FORM_METHOD,
                               username, password);*/
                      return AuthStatus.SUCCESS;
                  }
              }
              log.trace("Reauthentication failed, proceed normally");
          }
      }

      // Is this the re-submit of the original request URI after successful
      // authentication?  If so, forward the *original* request instead.
      if (matchRequest(request)) {
          session = request.getSessionInternal(true);
          log.trace("Restore request from session '"
                        + session.getIdInternal()
                        + "'");
          principal = (Principal)
              session.getNote(Constants.FORM_PRINCIPAL_NOTE);
         
          registerWithCallbackHandler(principal,
                (String) session.getNote(Constants.SESS_USERNAME_NOTE),
                (String) session.getNote(Constants.SESS_PASSWORD_NOTE));
         
          /*register(request, response, principal, Constants.FORM_METHOD,
                   (String) session.getNote(Constants.SESS_USERNAME_NOTE),
                   (String) session.getNote(Constants.SESS_PASSWORD_NOTE));*/
          // If we're caching principals we no longer need the username
          // and password in the session, so remove them
          if (cache) {
              session.removeNote(Constants.SESS_USERNAME_NOTE);
              session.removeNote(Constants.SESS_PASSWORD_NOTE);
          }
          if (restoreRequest(request, session)) {
              log.trace("Proceed to restored request");
              return (AuthStatus.SUCCESS);
          } else {
              log.trace("Restore of original request failed");
           
            try
            {
               response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            }
            catch (IOException e)
            {
               log.error(e.getLocalizedMessage(),e);
            }
              return AuthStatus.FAILURE;
          }
      }

      // Acquire references to objects we will need to evaluate
      MessageBytes uriMB = MessageBytes.newInstance();
      CharChunk uriCC = uriMB.getCharChunk();
      uriCC.setLimit(-1);
      String contextPath = request.getContextPath();
      String requestURI = request.getDecodedRequestURI();
      response.setContext(request.getContext());

      // Is this the action request from the login page?
      boolean loginAction =
          requestURI.startsWith(contextPath) &&
          requestURI.endsWith(Constants.FORM_ACTION);

      // No -- Save this request and redirect to the form login page
      if (!loginAction) {
          session = request.getSessionInternal(true);
          log.trace("Save request in session '" + session.getIdInternal() + "'");
          try {
              saveRequest(request, session);
          } catch (IOException ioe) {
              log.trace("Request body too big to save during authentication");
              try
            {
               response.sendError(HttpServletResponse.SC_FORBIDDEN,
                         sm.getString("authenticator.requestBodyTooBig"));
            }
            catch (IOException e)
            {
               log.error("Exception in Form authentication:",e);
               throw new AuthException(e.getLocalizedMessage());
            }
              return (AuthStatus.FAILURE);
          }
          forwardToLoginPage(request, response, config);
          return (AuthStatus.SEND_CONTINUE);
      }

      // Yes -- Validate the specified credentials and redirect
      // to the error page if they are not correct
      Realm realm = context.getRealm();
      String characterEncoding = request.getCharacterEncoding();
      if (characterEncoding != null) {
          try
         {
            request.setCharacterEncoding(characterEncoding);
         }
         catch (UnsupportedEncodingException e)
         {
            log.error(e.getLocalizedMessage(), e);
         }
      }
      String username = request.getParameter(Constants.FORM_USERNAME);
      String password = request.getParameter(Constants.FORM_PASSWORD);
      log.trace("Authenticating username '" + username + "'");
      principal = realm.authenticate(username, password);
      if (principal == null) {
          forwardToErrorPage(request, response, config);
          return (AuthStatus.FAILURE);
      }

      log.trace("Authentication of '" + username + "' was successful");

      if (session == null)
          session = request.getSessionInternal(false);
      if (session == null) {
          log.trace
                  ("User took so long to log on the session expired");
          try
         {
View Full Code Here

   @Override
   public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
   throws AuthException
   {
      Request request = (Request) messageInfo.getRequestMessage();
      Response response = (Response) messageInfo.getResponseMessage();

      Principal principal;
      context = request.getContext();

      X509Certificate certs[] = (X509Certificate[])
      request.getAttribute(CERTIFICATES_ATTR);
      if ((certs == null) || (certs.length < 1)) {
         request.getCoyoteRequest().action
         (ActionCode.ACTION_REQ_SSL_CERTIFICATE, null);
         certs = (X509Certificate[])
         request.getAttribute(CERTIFICATES_ATTR);
      }
      if ((certs == null) || (certs.length < 1)) {
         log.debug("  No certificates included with this request");
         try
         {
View Full Code Here

        if ((principal == null) || (role == null) || !(principal instanceof JAASTomcatPrincipal)) {
            return false;
        }

        Request request = (Request) currentRequest.get();
        if (currentRequest == null) {
            log.error("No currentRequest found.");
            return false;
        }
View Full Code Here

    public void lifecycleEvent(LifecycleEvent event) {
        if (event.getType() == Lifecycle.BEFORE_STOP_EVENT) {
            // The container is getting stopped, close all current connections
            Iterator<Request> iterator = cometRequests.iterator();
            while (iterator.hasNext()) {
                Request request = iterator.next();
                // Remove the session tracking attribute as it isn't
                // serializable or required.
                HttpSession session = request.getSession(false);
                if (session != null) {
                    session.removeAttribute(cometRequestsAttribute);
                }
                // Close the comet connection
                try {
                    CometEventImpl cometEvent = request.getEvent();
                    cometEvent.setEventType(CometEvent.EventType.END);
                    cometEvent.setEventSubType(
                            CometEvent.EventSubType.WEBAPP_RELOAD);
                    getNext().event(request, request.getResponse(), cometEvent);
                    cometEvent.close();
                } catch (Exception e) {
                    container.getLogger().warn(
                            sm.getString("cometConnectionManagerValve.event"),
                            e);
View Full Code Here

        // Close all Comet connections associated with this session
        Request[] reqs = (Request[])
            se.getSession().getAttribute(cometRequestsAttribute);
        if (reqs != null) {
            for (int i = 0; i < reqs.length; i++) {
                Request req = reqs[i];
                try {
                    CometEventImpl event = req.getEvent();
                    event.setEventType(CometEvent.EventType.END);
                    event.setEventSubType(CometEvent.EventSubType.SESSION_END);
                    ((CometProcessor)
                            req.getWrapper().getServlet()).event(event);
                    event.close();
                } catch (Exception e) {
                    req.getWrapper().getParent().getLogger().warn(sm.getString(
                            "cometConnectionManagerValve.listenerEvent"), e);
                }
            }
        }
    }
View Full Code Here

        boolean comet = false;
       
        // Create and initialize a filter chain object
        ApplicationFilterChain filterChain = null;
        if (request instanceof Request) {
            Request req = (Request) request;
            comet = req.isComet();
            if (Globals.IS_SECURITY_ENABLED) {
                // Security: Do not recycle
                filterChain = new ApplicationFilterChain();
                if (comet) {
                    req.setFilterChain(filterChain);
                }
            } else {
                filterChain = (ApplicationFilterChain) req.getFilterChain();
                if (filterChain == null) {
                    filterChain = new ApplicationFilterChain();
                    req.setFilterChain(filterChain);
                }
            }
        } else {
            // Request dispatcher in use
            filterChain = new ApplicationFilterChain();
View Full Code Here

    public boolean hasRole(Principal principal, String role) {
        boolean authzDecision = true;
        boolean baseDecision = super.hasRole(principal, role);
        // if the RealmBase check has passed, then we can go to authz framework
        if (baseDecision && useJBossAuthorization) {
            Request request = SecurityContextAssociationValve.getActiveRequest();
            String servletName = null;
            Wrapper servlet = request.getWrapper();
            if (servlet != null) {
                servletName = getServletName(servlet);
            }
            if (servletName == null)
                throw new IllegalStateException("servletName is null");
View Full Code Here

        remoteIpValve.setRemoteIpHeader("x-forwarded-for");
        remoteIpValve.setProxiesHeader("x-forwarded-by");
        RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
        remoteIpValve.setNext(remoteAddrAndHostTrackerValve);
       
        Request request = new Request();
        request.setCoyoteRequest(new org.apache.coyote.Request());
        request.setRemoteAddr("192.168.0.10");
        request.setRemoteHost("remote-host-original-value");
       
        // TEST
        remoteIpValve.invoke(request, null);
       
        // VERIFY
        String actualXForwardedFor = request.getHeader("x-forwarded-for");
        assertNull("x-forwarded-for must be null", actualXForwardedFor);
       
        String actualXForwardedBy = request.getHeader("x-forwarded-by");
        assertNull("x-forwarded-by must be null", actualXForwardedBy);
       
        String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
        assertEquals("remoteAddr", "192.168.0.10", actualRemoteAddr);
       
        String actualRemoteHost = remoteAddrAndHostTrackerValve.getRemoteHost();
        assertEquals("remoteHost", "remote-host-original-value", actualRemoteHost);
       
        String actualPostInvokeRemoteAddr = request.getRemoteAddr();
        assertEquals("postInvoke remoteAddr", "192.168.0.10", actualPostInvokeRemoteAddr);
       
        String actualPostInvokeRemoteHost = request.getRemoteHost();
        assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
       
    }
View Full Code Here

TOP

Related Classes of org.apache.catalina.connector.Request$AsyncContextImpl

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.