2011-07-29 7 views
5

저는 스프링 MVC와 스프링 시큐리티를 사용하고 있습니다. 이 게시물을 찾을 때까지 내 리디렉션이 https를 http로 전환했습니다. Spring MVC "redirect:" prefix always redirects to http -- how do I make it stay on https?. 또한 AjaxUrlBasedViewResolver에서 redirectHttp10Compatible 속성을 false로 설정해야했습니다.로그인 후 스프링 보안이 http로 전환됩니다. https를 유지하려면 어떻게해야합니까?

문제는 로그인 후에 https가 여전히 http로 전환된다는 것입니다. 로그인 한 후 주소 표시 줄에 https로 돌아갈 수있는 앱을 설정할 수 있습니다. 또한, 대부분의 사용자에게 IP 인증을 사용하고 있는데,이 경우 https는 위의 솔루션 덕분입니다.

redirectHtp10Compatible을 login_security_check 또는 그와 비슷한 것에 추가하려고 시도했지만 막혔습니다. 여기 내 security-config.xml.

<?xml version="1.0" encoding="UTF-8"?> 

<beans:beans xmlns="http://www.springframework.org/schema/security" 
     xmlns:beans="http://www.springframework.org/schema/beans" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

<global-method-security pre-post-annotations="enabled" /> 

<http auto-config='true' access-denied-page="/login"> 
    <intercept-url pattern="/static/styles/**" filters="none" /> 
    <intercept-url pattern="/static/scripts/**" filters="none" /> 

    <intercept-url pattern="/login/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/error/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/api/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/ajaxTimeOut" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/checkSystem" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/adminUser/**" access="ROLE_SSADMIN" /> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 

    <form-login login-page="/ajaxTimeOut" login-processing-url="/login_security_check" authentication-failure-url="/login?login_error=t" default-target-url="/" always-use-default-target="true" /> 
    <logout logout-url="/logout" logout-success-url="/"/> 
    <custom-filter position="PRE_AUTH_FILTER" ref="ipPreAuthFilter" /> 
</http> 

<beans:bean id="ipAuthDetailsSource" class="com.mydomain.security.IPBasedPreAuthenticatedDetailsSource" /> 

<beans:bean id="ipPreAuthFilter" class="com.mydomain.security.IPPreAuthenticationFilter"> 
    <beans:property name="authenticationManager" ref="preAuthManager" /> 
    <beans:property name="authenticationDetailsSource" ref="ipAuthDetailsSource" /> 
</beans:bean> 

<beans:bean id="preAuthManager" class="org.springframework.security.authentication.ProviderManager"> 
    <beans:property name="providers"> 
     <beans:list> 
      <beans:ref local="preAuthProvider"/> 
     </beans:list> 
    </beans:property> 
</beans:bean> 

<beans:bean id="preAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"> 
    <beans:property name="preAuthenticatedUserDetailsService" ref="preAuthUserService" /> 
</beans:bean> 

<beans:bean id="preAuthUserService" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService" /> 

<authentication-manager> 
    <authentication-provider user-service-ref="userService"> 
     <password-encoder ref="passwordEncoder" > 
      <salt-source user-property="salt" /> 
     </password-encoder> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="userService" class="com.mydomain.security.UserServiceImpl" /> 
<beans:bean id="passwordEncoder" class="com.mydomain.security.PasswordEncoder"> 
    <beans:constructor-arg value="256" /> 
</beans:bean> 

감사합니다.

+0

이 모든 관련 봄 보안 설정을 해주십시오 알려 주시기 어떤 버전의 Spring Security를 ​​사용하고 있습니까? –

+0

@Marc 한 가지 질문 : 사용자가 직접 로그인 페이지를 호출하는 방법 (http (s) : //.../login을 입력)? (사용자가 http (s) : //.../ adminUser/,,,를 요청한 경우)?, 두 번째 질문 : 사용자가 http 또는 https를 통해이 작업을 수행합니까? – Ralph

+0

사용자가 IP 인증을받지 않은 경우 로그인 페이지로 리디렉션됩니다. IP 인증을받은 경우 요청 된 페이지 또는 홈 페이지로 이동합니다. 사용자는 http 또는 https를 사용할 수 있으며 사이트에 연결되는 프로토콜에 상관없이 앱을 유지해야합니다. – Marc

답변

-1

노드

그냥이 같은

intercep-URL에 보안 URL에 필요한 채널 속성을 추가

<intercept-url pattern="/**" access="ROLE_USER" requires-channel="https" /> 
관련 문제