All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadleafcommerce.common.security.channel.ProtoInsecureChannelProcessor Maven / Gradle / Ivy

There is a newer version: 3.1.15-GA
Show newest version
/*
 * #%L
 * BroadleafCommerce Common Libraries
 * %%
 * Copyright (C) 2009 - 2013 Broadleaf Commerce
 * %%
 * 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.
 * #L%
 */
package org.broadleafcommerce.common.security.channel;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.channel.InsecureChannelProcessor;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.ServletException;

/**
 * 

Very similar to the {@link InsecureChannelProcessor} except that instead of relying on only the HttpServletRequest * this also allows * inspection of the X-Forwarded-Proto header to determine if the request is secure. This class is required when the * application is deployed to an environment where SSL termination happens at a layer above the servlet container * (like at a load balancer)

* *

This is intended to be used in conjunction with the {@link ProtoChannelBeanPostProcessor}. See that class for * more information on how to configure.

* *

This class encapsulates functionality given in {@link InsecureChannelProcessor} so it is unnecessary to configure * both

* * @author Jeff Fischer * @author Phillip Verheyden (phillipuniverse) * @see {@link InsecureChannelProcessor} * @see {@link ProtoSecureChannelProcessor} */ public class ProtoInsecureChannelProcessor extends InsecureChannelProcessor { @Override public void decide(FilterInvocation invocation, Collection config) throws IOException, ServletException { if ((invocation == null) || (config == null)) { throw new IllegalArgumentException("Nulls cannot be provided"); } for (ConfigAttribute attribute : config) { if (supports(attribute)) { if (invocation.getHttpRequest().getHeader("X-Forwarded-Proto") != null && "https".equalsIgnoreCase(invocation.getHttpRequest().getHeader("X-Forwarded-Proto"))) { //We can't rely entirely on "!invocation.getHttpRequest().isSecure()" because many times, //when SSL terminates somewhere else, the proxied request will not be secure. //In this case, someone may have gone to a secured page, and then tried to go back to an unsecured page. getEntryPoint().commence(invocation.getRequest(), invocation.getResponse()); } else if (invocation.getHttpRequest().getHeader("X-Forwarded-Proto") != null && "http".equalsIgnoreCase(invocation.getHttpRequest().getHeader("X-Forwarded-Proto"))) { return; } else if (!invocation.getHttpRequest().isSecure()) { return; } else { getEntryPoint().commence(invocation.getRequest(), invocation.getResponse()); } } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy