Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * JBoss, Home of Professional Open Source.
  * Copyright 2013 Red Hat, Inc., and individual contributors
  * as indicated by the @author tags.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.undertow.servlet.handlers.security;
Servlet specific extension to SinglePortConfidentialityHandler

Author(s):
Darran Lofthouse
    private final ConfidentialPortManager portManager;
    public ServletConfidentialityConstraintHandler(final ConfidentialPortManager portManagerfinal HttpHandler next) {
        super(next, -1);
        this. = portManager;
    }
    @Override
    public void handleRequest(HttpServerExchange exchangethrows Exception {
        final ServletRequestContext servletRequestContext = exchange.getAttachment(.);
        final AuthorizationManager authorizationManager = servletRequestContext.getDeployment().getDeploymentInfo().getAuthorizationManager();
        TransportGuaranteeType connectionGuarantee = servletRequestContext.getOriginalRequest().isSecure() ? . : .;
        TransportGuaranteeType transportGuarantee = authorizationManager.transportGuarantee(connectionGuarantee,
                servletRequestContext.getTransportGuarenteeType(), servletRequestContext.getOriginalRequest());
        servletRequestContext.setTransportGuarenteeType(transportGuarantee);
        if (. == transportGuarantee) {
            HttpServletResponse response = (HttpServletResponseservletRequestContext.getServletResponse();
            response.sendError(403);
            return;
        }
        super.handleRequest(exchange);
    }
    @Override
    protected boolean confidentialityRequired(HttpServerExchange exchange) {
        // TODO - We may be able to add more flexibility here especially with authentication mechanisms such as Digest for
        // INTEGRAL - for now just use SSL.
        return (. == transportGuarantee || . == transportGuarantee);
    }
    @Override
    protected URI getRedirectURI(HttpServerExchange exchangethrows URISyntaxException {
        return super.getRedirectURI(exchange.getConfidentialPort(exchange));
    }
New to GrepCode? Check out our FAQ X