복붙노트

[SPRING] 스프링 보안, 폼 로그인 및 동시 세션

SPRING

스프링 보안, 폼 로그인 및 동시 세션

사용자가 한 번 이상 서명하지 못하도록 제한하려고합니다. 이전 세션이 만료되도록합니다.

주제에 대한 문서를 확인했습니다. 이 문서를 문서와 매우 유사하게 설정했지만 사용자는 한 번에 하나의 세션으로 제한되지 않습니다. 동일한 사용자와 여러 번 (여러 브라우저에서) 로그인 할 수 있으며 동시에 여러 세션을 진행할 수 있습니다.

여기 내 보안 설정의 관련 비트로 생각되는 것들이 있습니다. 사용자 정의 UserDetailsService, UserDetails 및 AuthenticationFilter 구현을 사용하고 있습니다.


    <http entry-point-ref="authenticationEntryPoint">
        <!-- Make sure everyone can access the login page -->
        <intercept-url pattern="/login.do*" filters="none" />

        [...]

        <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
        <custom-filter position="FORM_LOGIN_FILTER" ref="authenticationFilter" />

        <logout logout-url="/logout" logout-success-url="/login.do" />
    </http>

    <authentication-manager alias="authenticationManager">
        <authentication-provider user-service-ref="userDetailsService">
            <password-encoder hash="sha" />
        </authentication-provider>
    </authentication-manager>

    <beans:bean id="userDetailsService" class="[...]">
        <beans:property name="userManager" ref="userManager" />
    </beans:bean>

    <beans:bean id="authenticationFilter" class="[...]">
        <beans:property name="authenticationManager" ref="authenticationManager" />
        <beans:property name="eventPublisher">
            <beans:bean
                class="org.springframework.security.authentication.DefaultAuthenticationEventPublisher" />
        </beans:property>
        <beans:property name="filterProcessesUrl" value="/security_check" />
        <beans:property name="authenticationFailureHandler">
            <beans:bean
                class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
                <beans:property name="defaultFailureUrl" value="/login.do?login_error=true" />
            </beans:bean>
        </beans:property>
        <beans:property name="sessionAuthenticationStrategy"
            ref="sessionAuthenticationStrategy" />
    </beans:bean>

    <beans:bean id="authenticationEntryPoint"
        class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <beans:property name="loginFormUrl" value="/login.do" />
    </beans:bean>

    <beans:bean id="concurrencyFilter"
        class="org.springframework.security.web.session.ConcurrentSessionFilter">
        <beans:property name="sessionRegistry" ref="sessionRegistry" />
        <beans:property name="expiredUrl" value="/login.do?login_error=true!" />
    </beans:bean>

    <beans:bean id="sessionAuthenticationStrategy"
        class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
        <beans:constructor-arg name="sessionRegistry"
            ref="sessionRegistry" />
        <beans:property name="maximumSessions" value="1" />
    </beans:bean>

    <beans:bean id="sessionRegistry"
        class="org.springframework.security.core.session.SessionRegistryImpl" />

또한 web.xml 파일에 org.springframework.security.web.session.HttpSessionEventPublisher를 리스너로 등록했습니다.

내가 말할 수있는 한, 나는 문서에 따라 이것을 설정했다. 왜 이것이 작동하지 않는지 나는 말할 수 없다. 양식 기반 로그인을 사용하고 있다는 사실과 관련이 있습니까? 또는 위에서 언급 한 내 사용자 정의 구현?

해결법

  1. ==============================

    1.나는 그것을 알아. UserDetails를 다시 구현하는 경우 SessionRegistryImpl에 사용할 hashCode () 메서드를 제공해야합니다. 이것은 설명서에 언급되어 있지 않습니다.

    나는 그것을 알아. UserDetails를 다시 구현하는 경우 SessionRegistryImpl에 사용할 hashCode () 메서드를 제공해야합니다. 이것은 설명서에 언급되어 있지 않습니다.

  2. ==============================

    2.이미 답변을 받았지만 특정 필터를 구성 할 필요가없는 훨씬 간단한 솔루션이 있다는 것을 알고 있습니다. http 태그에 다음 XML을 추가하여 세션을 구성 할 수 있습니다.

    이미 답변을 받았지만 특정 필터를 구성 할 필요가없는 훨씬 간단한 솔루션이 있다는 것을 알고 있습니다. http 태그에 다음 XML을 추가하여 세션을 구성 할 수 있습니다.

    <session-management invalid-session-url="/login">
      <concurrency-control max-sessions="1" expired-url="/login" />
    </session-management>
    

    양식 기반 로그인 구성의 나머지도 지나치게 복잡합니다. http://codehustler.org/blog/spring-security-form-login-tutorial/ 여기에 양식을 올바르게 구성하는 방법을 보여주는 게시물을 작성했습니다.

  3. from https://stackoverflow.com/questions/3670991/spring-security-form-login-and-concurrent-sessions by cc-by-sa and MIT license