Package org.eclipse.jetty.server

Examples of org.eclipse.jetty.server.Handler


     */
    @Override
    public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        final Response base_response = baseRequest.getResponse();
        final Handler handler=getHandler();

        if (handler==null)
            return;

        final Authenticator authenticator = _authenticator;

        if (checkSecurity(baseRequest))
        {
            //See Servlet Spec 3.1 sec 13.6.3
            if (authenticator != null)
                authenticator.prepareRequest(baseRequest);
           
            RoleInfo roleInfo = prepareConstraintInfo(pathInContext, baseRequest);

            // Check data constraints
            if (!checkUserDataPermissions(pathInContext, baseRequest, base_response, roleInfo))
            {
                if (!baseRequest.isHandled())
                {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN);
                    baseRequest.setHandled(true);
                }
                return;
            }

            // is Auth mandatory?
            boolean isAuthMandatory =
                isAuthMandatory(baseRequest, base_response, roleInfo);

            if (isAuthMandatory && authenticator==null)
            {
                LOG.warn("No authenticator for: "+roleInfo);
                if (!baseRequest.isHandled())
                {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN);
                    baseRequest.setHandled(true);
                }
                return;
            }

            // check authentication
            Object previousIdentity = null;
            try
            {
                Authentication authentication = baseRequest.getAuthentication();
                if (authentication==null || authentication==Authentication.NOT_CHECKED)
                    authentication=authenticator==null?Authentication.UNAUTHENTICATED:authenticator.validateRequest(request, response, isAuthMandatory);

                if (authentication instanceof Authentication.Wrapped)
                {
                    request=((Authentication.Wrapped)authentication).getHttpServletRequest();
                    response=((Authentication.Wrapped)authentication).getHttpServletResponse();
                }

                if (authentication instanceof Authentication.ResponseSent)
                {
                    baseRequest.setHandled(true);
                }
                else if (authentication instanceof Authentication.User)
                {
                    Authentication.User userAuth = (Authentication.User)authentication;
                    baseRequest.setAuthentication(authentication);
                    if (_identityService!=null)
                        previousIdentity = _identityService.associate(userAuth.getUserIdentity());

                    if (isAuthMandatory)
                    {
                        boolean authorized=checkWebResourcePermissions(pathInContext, baseRequest, base_response, roleInfo, userAuth.getUserIdentity());
                        if (!authorized)
                        {
                            response.sendError(HttpServletResponse.SC_FORBIDDEN, "!role");
                            baseRequest.setHandled(true);
                            return;
                        }
                    }

                    handler.handle(pathInContext, baseRequest, request, response);
                    if (authenticator!=null)
                        authenticator.secureResponse(request, response, isAuthMandatory, userAuth);
                }
                else if (authentication instanceof Authentication.Deferred)
                {
                    DeferredAuthentication deferred= (DeferredAuthentication)authentication;
                    baseRequest.setAuthentication(authentication);

                    try
                    {
                        handler.handle(pathInContext, baseRequest, request, response);
                    }
                    finally
                    {
                        previousIdentity = deferred.getPreviousAssociation();
                    }

                    if (authenticator!=null)
                    {
                        Authentication auth=baseRequest.getAuthentication();
                        if (auth instanceof Authentication.User)
                        {
                            Authentication.User userAuth = (Authentication.User)auth;
                            authenticator.secureResponse(request, response, isAuthMandatory, userAuth);
                        }
                        else
                            authenticator.secureResponse(request, response, isAuthMandatory, null);
                    }
                }
                else
                {
                    baseRequest.setAuthentication(authentication);
                    if (_identityService!=null)
                        previousIdentity = _identityService.associate(null);
                    handler.handle(pathInContext, baseRequest, request, response);
                    if (authenticator!=null)
                        authenticator.secureResponse(request, response, isAuthMandatory, null);
                }
            }
            catch (ServerAuthException e)
            {
                // jaspi 3.8.3 send HTTP 500 internal server error, with message
                // from AuthException
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
            }
            finally
            {
                if (_identityService!=null)
                    _identityService.disassociate(previousIdentity);
            }
        }
        else
            handler.handle(pathInContext, baseRequest, request, response);
    }
View Full Code Here


    {
        _server = new Server();
        _connector = new LocalConnector(_server);
        _server.addConnector(_connector);

        Handler testHandler = new AbstractHandler()
        {
            public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
                    ServletException
            {
                PrintWriter writer = response.getWriter();
View Full Code Here

        recursiveRemoveContext(chcoll,handler);
    }

    private void recursiveRemoveContext(HandlerCollection coll, ContextHandler context)
    {
        Handler children[] = coll.getHandlers();
        int originalCount = children.length;

        for (int i = 0, n = children.length; i < n; i++)
        {
            Handler child = children[i];
            LOG.debug("Child handler {}",child);
            if (child.equals(context))
            {
                LOG.debug("Removing handler {}",child);
                coll.removeHandler(child);
                child.destroy();
                if (LOG.isDebugEnabled())
                    LOG.debug("After removal: {} (originally {})",coll.getHandlers().length,originalCount);
            }
            else if (child instanceof HandlerCollection)
            {
View Full Code Here

        return null;
    }

    private void checkIfContextIsFree(String path)
    {
        Handler serverHandler = _server.getHandler();
                if (serverHandler instanceof ContextHandler)
                {
                        ContextHandler ctx = (ContextHandler) serverHandler;
                        if (ctx.getContextPath().equals(path))
                        throw new RuntimeException("another context already bound to path " + path);
View Full Code Here

    public List<WebAppContext> getWebAppContexts()
    {
        List<WebAppContext> contexts = new ArrayList<>();
        HandlerCollection handlers = (HandlerCollection)_server.getHandler();
        Handler children[] = handlers.getChildHandlers();

        for (Handler handler : children)
        {
            if (handler instanceof WebAppContext)
            {
View Full Code Here

        // the id="RequestLog"
        RequestLogHandler requestLog = new RequestLogHandler();
        CaptureLog captureLog = new CaptureLog();
        requestLog.setRequestLog(captureLog);
       
        Handler origServerHandler = server.getHandler();
        requestLog.setHandler(origServerHandler);
        server.setHandler(requestLog);
       
        // Lastly, the behavior as defined by deployment of a webapp
        // Add the Servlet Context
View Full Code Here

        if (isRunning())
            throw new IllegalStateException(RUNNING);

        super.setServer(server);

        Handler h = getHandler();
        if (h != null)
            h.setServer(server);
    }
View Full Code Here

    @Override
    public void destroy()
    {
        if (!isStopped())
            throw new IllegalStateException("!STOPPED");
        Handler child = getHandler();
        if (child != null)
        {
            setHandler(null);
            child.destroy();
        }
        super.destroy();
    }
View Full Code Here

        if (async.isAsync())
        {
            ContextHandler context=async.getContextHandler();
            if (context!=null)
            {
                Handler branch = _contextBranches.get(context);
               
                if (branch==null)
                    context.handle(target,baseRequest,request, response);
                else
                    branch.handle(target, baseRequest, request, response);
                return;
            }
        }
       
        // data structure which maps a request to a context; first-best match wins
        // { context path => [ context ] }
        // }
        if (target.startsWith("/"))
        {
            int limit = target.length()-1;

            while (limit>=0)
            {
                // Get best match
                Map.Entry<String,Branch[]> branches = _pathBranches.getBest(target,1,limit);
               
               
                if (branches==null)
                    break;
               
                int l=branches.getKey().length();
                if (l==1 || target.length()==l || target.charAt(l)=='/')
                {
                    for (Branch branch : branches.getValue())
                    {
                        branch.getHandler().handle(target,baseRequest, request, response);
                        if (baseRequest.isHandled())
                            return;
                    }
                }
               
View Full Code Here

            throw new IllegalStateException(STARTED);

        if (handler!=null)
            handler.setServer(getServer());
       
        Handler old=_handler;
        _handler=handler;
        updateBean(old,_handler);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.Handler

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.