사용자 도구

사이트 도구


springframework:security

문서의 이전 판입니다!


Spring Security

  • 현재 페이지는 Spring Security 3.x 기준

http

  • <intercept-url pattern=“/someurl/*” filters=“none” /> 에서 filters=“none”이면 해당 URL에서는 Spring Security 관련 기능이 아무것도 작동하지 않게 된다.

Expression Handler

global-method-security에 핸들러 지정

<global-method-security>
  <expression-handler ref="myMethodSecurityExpressionHandler"/>
</global-method-security>

http에 핸들러 지정

  • SpringSecurity 3.0 에서는 XML 태그를 통해 웹 전반에 관한 expressionHandler 설정이 불가능 하다. SEC-1452 버그 참조. 3.1부터 가능.
  • access-decision-manager-ref를 지정함으로써만 가능하다. 다음 참조.
<!-- This must go before the http element in order to be used by security:authorize tags using the access attribute -->
<bean id="expressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler">
  <property name="roleHierarchy" ref="roleHierarchy" /> <!-- 꼭 필요한지는 의문 -->
</bean>
 
<security:http auto-config="true" use-expressions="true" access-decision-manager-ref="accessDecisionManager">
  ...
</security:http>
 
<!-- security:authorize tags using the url attribute will delegate to this accessDecisionManager -->
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
  <property name="decisionVoters">
    <list>
      <ref bean="webExpressionVoter" />
    </list>
  </property>
</bean>
 
<bean id="webExpressionVoter" class="org.springframework.security.web.access.expression.WebExpressionVoter">
  <property name="expressionHandler" ref="expressionHandler" />
</bean>
 
<!-- 꼭 필요한지는 의문 -->
<bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
  <property name="hierarchy">
    <value>
      ROLE_A > ROLE_B
      ROLE_B > ROLE_AUTHENTICATED
      ROLE_AUTHENTICATED >
      ROLE_UNAUTHENTICATED
    </value>
  </property>
</bean>

Access Denied Handler

Session에 예외 객체 저장현상

SpringSecurity는 로그인 혹은 권한 관련예외가 발생할 경우 세션에 해당 예외를 저장한다. (SimpleUrlAuthenticationFailureHandler의 saveException() 참조)

해당 예외는 WebAttributes.AUTHENTICATION_EXCEPTION의 값인 SPRING_SECURITY_LAST_EXCEPTION으로 저장된다.

문제는 기계화된 로그인 공격이 들어올 경우 모든 리퀘스트는 새로운 세션으로 간주되며 로그인 실패 예외들이 모두 세션에 저장되어 메모리 고갈을 일으킨다는 점이다. 이 때문에 AuthenticationFailureHandlerSimpleUrlAuthenticationFailureHandler를 상속하여 구현하면서 saveException()을 호출하지 않도록 하는 것이 좋다.

아예 세션에 로그인 실패 예외를 저장하지 않도록

saveException()을 호출하지 않도록 처리한 구현체를 다음과 같이 설정해 준다.

<form-login ... authentication-failure-handler-ref="AuthenticationFailureHandler구현체" />

이는 로그인 실패에 대한 것이며 권한 없음에 대한 예외는 다른 문제이다.

JSP에서 삭제

JSP에서 저장된 예외를 메시지 출력에 사용하는 경우가 있을 수 있는데, 이때는 JSP에서도 삭제하도록 해야 한다.

<c:remove var="SPRING_SECURITY_LAST_EXCEPTION" scope="session"/>
springframework/security.1358757828.txt.gz · 마지막으로 수정됨: 2013/01/21 17:43 저자 kwon37xi