Package org.apache.catalina.connector

Examples of org.apache.catalina.connector.Response


        Session session = mgr.createSession(NO_JVMROUTE_ID);
        MockRequest req = new MockRequest(mgr);
        req.setSession(session);
        req.setRequestedSessionId(session.getId());

        Response res = new Response();

        jvmRouteValve.invoke(req, res);

        assertSame(req, mockValve.getInvokedRequest());
        assertSame(res, mockValve.getInvokedResponse());
View Full Code Here


        MockRequest req = new MockRequest(mgr);
        req.setSession(session);
        req.setRequestedSessionId(session.getId());
        req.setRequestedSessionIdFromURL(true);

        Response res = new Response();

        jvmRouteValve.invoke(req, res);

        assertSame(req, mockValve.getInvokedRequest());
        assertSame(res, mockValve.getInvokedResponse());
View Full Code Here

        Session session = mgr.createSession(NON_FAILOVER_ID);
        MockRequest req = new MockRequest(mgr);
        req.setSession(session);
        req.setRequestedSessionId(NO_JVMROUTE_ID);

        Response res = new Response();

        jvmRouteValve.invoke(req, res);

        assertSame(req, mockValve.getInvokedRequest());
        assertSame(res, mockValve.getInvokedResponse());
View Full Code Here

        Session session = mgr.createSession(NON_FAILOVER_ID);
        req.setSession(session);
        req.setRequestedSessionId(NO_JVMROUTE_ID);
        req.setRequestedSessionIdFromURL(true);

        Response res = new Response();

        jvmRouteValve.invoke(req, res);

        assertSame(req, mockValve.getInvokedRequest());
        assertSame(res, mockValve.getInvokedResponse());
View Full Code Here

        MockRequest req = new MockRequest(mgr);
        Session session = mgr.createSession(DOMAIN_FAILOVER_ID);
        req.setSession(session);
        req.setRequestedSessionId(session.getId());

        Response res = new Response();

        jvmRouteValve.invoke(req, res);

        assertSame(req, mockValve.getInvokedRequest());
        assertSame(res, mockValve.getInvokedResponse());
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)) {
            WebLogger.WEB_SECURITY_LOGGER.debugf("No certificates included with this request");
            try {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates"));
            } catch (IOException e) {
             // Ignore IOException here (client disconnect)
            }
            return (AuthStatus.FAILURE);
        }

        // Authenticate the specified certificate chain
        principal = context.getRealm().authenticate(certs);
        if (principal == null) {
            WebLogger.WEB_SECURITY_LOGGER.debugf("Realm.authenticate() returned false");
            try {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.unauthorized"));
            } catch (IOException e) {
             // Ignore IOException here (client disconnect)
            }
            return (AuthStatus.FAILURE);
        }
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();
        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.valueOf((String) messageInfo.getMap().get("CACHE"));

        // have we authenticated this user before but have caching disabled?
        if (!cache) {
            session = request.getSessionInternal(true);
            WebLogger.WEB_SECURITY_LOGGER.debugf("Checking for reauthenticate in session %s", session.getIdInternal());
            String username = (String) session.getNote(Constants.SESS_USERNAME_NOTE);
            String password = (String) session.getNote(Constants.SESS_PASSWORD_NOTE);
            if ((username != null) && (password != null)) {
                WebLogger.WEB_SECURITY_LOGGER.debugf("Reauthenticating username '%s'", username);
                principal = context.getRealm().authenticate(username, password);
                if (principal != null) {
                    session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
                    if (!matchRequest(request)) {
                        registerWithCallbackHandler(principal, username, password);
                        return AuthStatus.SUCCESS;
                    }
                }
                WebLogger.WEB_SECURITY_LOGGER.tracef("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);
            WebLogger.WEB_SECURITY_LOGGER.tracef("Restore request from session '%s'", 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));

            // 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)) {
                WebLogger.WEB_SECURITY_LOGGER.tracef("Proceed to restored request");
                return (AuthStatus.SUCCESS);
            } else {
                WebLogger.WEB_SECURITY_LOGGER.tracef("Restore of original request failed");

                try {
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                } catch (IOException e) {
                 // Ignore IOException here (client disconnect)
                }
                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();

        // 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);
            WebLogger.WEB_SECURITY_LOGGER.tracef("Save request in session '%s'", session.getIdInternal());
            try {
                saveRequest(request, session);
            } catch (IOException ioe) {
                WebLogger.WEB_SECURITY_LOGGER.tracef("Request body too big to save during authentication");
                try {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN, sm.getString("authenticator.requestBodyTooBig"));
                } catch (IOException e) {
                 // Ignore IOException here (client disconnect)
                    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) {
                WebLogger.WEB_SECURITY_LOGGER.unsupportedEncoding(e.getLocalizedMessage());
            }
        }
        String username = request.getParameter(Constants.FORM_USERNAME);
        String password = request.getParameter(Constants.FORM_PASSWORD);

        WebLogger.WEB_SECURITY_LOGGER.tracef("Authenticating username '%s'", username);
        principal = realm.authenticate(username, password);
        if (principal == null) {
            forwardToErrorPage(request, response, config);
            return (AuthStatus.FAILURE);
        }

        WebLogger.WEB_SECURITY_LOGGER.tracef("Authentication of '%s' was successful", username);
        if (session == null)
            session = request.getSessionInternal(false);
        if (session == null) {
            WebLogger.WEB_SECURITY_LOGGER.tracef("User took so long to log on the session expired");
            try {
                response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT, sm.getString("authenticator.sessionExpired"));
            } catch (IOException e) {
             // Ignore IOException here (client disconnect)
            }
            return (AuthStatus.FAILURE);
        }

        // save the authenticated Principal in our session.
        session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);

        // save the username and password as well.
        session.setNote(Constants.SESS_USERNAME_NOTE, username);
        session.setNote(Constants.SESS_PASSWORD_NOTE, password);

        // redirect the user to the original request URI (which will cause the original request to be restored).
        requestURI = savedRequestURL(session);
        WebLogger.WEB_SECURITY_LOGGER.tracef("Redirecting to original '%s'", requestURI);
        try {
            if (requestURI == null)
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, sm.getString("authenticator.formlogin"));
            else
                response.sendRedirect(response.encodeRedirectURL(requestURI));
        } catch (IOException ioe) {
         // Ignore IOException here (client disconnect)
        }
        return (AuthStatus.FAILURE);
    }
View Full Code Here

         if (ssoDomain != null)
         {
            cookie.setDomain(ssoDomain);
         }

         Response response = (Response) SecurityAssociationValve.activeResponse.get();
         response.addCookie(cookie);

         // Register this principal with our SSO valve
         sso.register(ssoId, principal, AUTH_TYPE, username, this.getPasswordAsString(password));
         request.setNote(Constants.REQ_SSOID_NOTE, ssoId);
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();
     
      // 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();

         response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      }
      catch (IOException e)
      {
         log.error("IOException ", e);
      }
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
         {
            response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT,
                                sm.getString("authenticator.sessionExpired"));
         }
         catch (IOException e)
         {
            log.error(e.getLocalizedMessage(),e);
         }
          return (AuthStatus.FAILURE);
      }

      // Save the authenticated Principal in our session
      session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);

      // Save the username and password as well
      session.setNote(Constants.SESS_USERNAME_NOTE, username);
      session.setNote(Constants.SESS_PASSWORD_NOTE, password);

      // Redirect the user to the original request URI (which will cause
      // the original request to be restored)
      requestURI = savedRequestURL(session);
      log.trace("Redirecting to original '" + requestURI + "'");
      try
      {
         if (requestURI == null)
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                               sm.getString("authenticator.formlogin"));
        else
            response.sendRedirect(response.encodeRedirectURL(requestURI))
      }
      catch(IOException ioe)
      {
         log.error(ioe.getLocalizedMessage(),ioe);
      }
View Full Code Here

TOP

Related Classes of org.apache.catalina.connector.Response

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.