Package org.apache.catalina.connector

Examples of org.apache.catalina.connector.Response


        SecurityConstraint[] constraints =
                new SecurityConstraint[] { constraintOne, constraintTwo };

        // Set up the mock request and response
        Request request = new Request();
        Response response = new TesterResponse();
        Context context = new TesterContext();
        for (String applicationRole : applicationRoles) {
            context.addSecurityRole(applicationRole);
        }
        request.getMappingData().context = context;
View Full Code Here


        TesterMapRealm mapRealm = new TesterMapRealm();

        // Set up the mock request and response
        TesterRequest request = new TesterRequest();
        Response response = new TesterResponse();
        Context context = new TesterContext();
        context.addSecurityRole(ROLE1);
        context.addSecurityRole(ROLE2);
        request.getMappingData().context = context;
View Full Code Here

            // the StandardEngineValve
            return;
        }
       
        super.setContext(ctx);
        Response response = (Response) getResponse();
        // Assert response!=null
        if (response != null) {
            String[] cacheControls = ((PwcWebModule) ctx).getCacheControls();
            for (int i=0; cacheControls!=null && i<cacheControls.length; i++) {
                response.addHeader("Cache-Control", cacheControls[i]);
            }
        }

        sunWebXmlChecked = false;
    }
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.debugf("No certificates included with this request");
            try {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates"));
            } catch (IOException e) {
                log.errorf("Caught Exception: %s", e.getLocalizedMessage());
            }
            return (AuthStatus.FAILURE);
        }

        // Authenticate the specified certificate chain
        principal = context.getRealm().authenticate(certs);
        if (principal == null) {
            log.debugf("Realm.authenticate() returned false");
            try {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.unauthorized"));
            } catch (IOException e) {
                log.errorf("Caught Exception: %s", e.getLocalizedMessage());
            }
            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);
            log.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)) {
                log.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;
                    }
                }
                log.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);
            log.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)) {
                log.tracef("Proceed to restored request");
                return (AuthStatus.SUCCESS);
            } else {
                log.tracef("Restore of original request failed");

                try {
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                } catch (IOException e) {
                    log.errorf("Caught Exception: %s", e.getLocalizedMessage());
                }
                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);
            log.tracef("Save request in session '%s'", session.getIdInternal());
            try {
                saveRequest(request, session);
            } catch (IOException ioe) {
                log.tracef("Request body too big to save during authentication");
                try {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN, sm.getString("authenticator.requestBodyTooBig"));
                } catch (IOException e) {
                    log.errorf("Caught Exception in Form authentication: %s", e.getLocalizedMessage());
                    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.errorf("Caught Exception: %s", e.getLocalizedMessage());
            }
        }
        String username = request.getParameter(Constants.FORM_USERNAME);
        String password = request.getParameter(Constants.FORM_PASSWORD);

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

        log.tracef("Authentication of '%s' was successful", username);
        if (session == null)
            session = request.getSessionInternal(false);
        if (session == null) {
            log.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) {
                log.errorf("Caught Exception: %s", e.getLocalizedMessage());
            }
            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.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) {
            log.errorf("Caught Exception: %s", ioe.getLocalizedMessage());
        }
        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();

        // 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);
                CharChunk authorizationCC = authorization.getCharChunk();
                Base64.decode(authorizationBC, authorizationCC);

                // get username and password from the authorization char chunk.
                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.errorf("Caught Exception: %s", e.getLocalizedMessage());
        }

        return AuthStatus.FAILURE;
View Full Code Here

        getTomcatInstance().start();

        MockFilterChain filterChain = new MockFilterChain();

        // TEST
        remoteIpFilter.doFilter(request, new Response(), filterChain);
        return filterChain.getRequest();
    }
View Full Code Here

        getTomcatInstance().start();

        MockFilterChain filterChain = new MockFilterChain();

        // TEST
        remoteIpFilter.doFilter(request, new Response(), filterChain);
        return filterChain.getRequest();
    }
View Full Code Here

        getTomcatInstance().start();

        MockFilterChain filterChain = new MockFilterChain();

        // TEST
        remoteIpFilter.doFilter(request, new Response(), filterChain);
        return filterChain.getRequest();
    }
View Full Code Here

    /**
     * write a specific response header - x-O{xxx}
     */
    protected String responseHeader(Request request,String header) {
        Response response = request.getResponse() ;
        if (null != response) {
            String[] values = response.getHeaderValues(header);
            if(values.length > 0) {
                StringBuffer buf = new StringBuffer();
                for (int i = 0; i < values.length; i++) {
                    String string = values[i];
                    buf.append(string) ;
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.