Clean Code that Works.

간만에 spring security 로 ip 필터링을 할 부분이 있어서 적용중에...


문서를 보면 hasIpAddress(10.54.100.0/24)  이런 부분이 있다.

음..딱 보면 10.54.100.0~24 까지 ip 필터링을 하는가 보다... 라고 생각하고 그렇게 했는데. 

이 뜻이 아니다. -ㅁ-;;


http://forum.springsource.org/showthread.php?102783-How-to-use-hasIpAddress

위 블로그에 똑같은 질문을 했는데, 친절하게 답변을 해줘서 이해가 쉬웠다.


만약 10.54.100.0 ~255 까지 ip를 블럭 하고 싶으면, 

10.54.100.0/24 이렇게 쓰면된다. 그런데 뒤에 /24는 무엇이란 말인가.

24가 의미하는것은 ip 주소의 subnet mask의 바이너리 값을 더 한것이다.


일반적으로 윈도우나 리눅스에서 ipconfig를 쳐보면 sutnet mask(mask)를 확인할 수 있다.

255.255.255.0

255의 바이너리 값이 11111111 이 되므로

(11111111) * 3 = 24, 이 24가 위 표현에서 /24가 되는것이다.


헐~ 역시 스프링 시큐리티 문서는 아직도 불친절해 -ㄴ-

afterInvocationManager

Spring2010. 5. 31. 10:17
In our application, only principals with permissions to read the given customer should be allowed to obtain it. To make this check, the Customer instance is retrieved and passed to the AclEntryAfterInvocationProvider. If the authenticated object does not have the permission to read it, then the provider will throw AccessDeniesException.

http://www.denksoft.com/wordpress/web-development/acl-spring-security-tutorial/

참고 하고 있는 블로그에 있는 내용인데.. 뭔말이야 @_@;;
일단 오브젝트를 겟 한 다음에 권한을 체크 한다는 내용 같다.

그게 무슨말이야.!!!

그전 메소드 시큐리티에서는 오브젝트를 get 하기 전에, 즉 쿼리를 날리기 전에 보안 검사를 하고 있는데,
이것은 쿼리를 실행 한 후 오브젝트를 get 한 후에 이 오브젝트들을 하나 하나 보안 검사를 해서, 보안검사에 통과할 경우 오브젝트들을 보여준다.

오우 좋은데 @_@

그러니까 검색 한 다음에 검색 결과에서 필터링을 할 수 있다는 말!!
그럼 요곳들을 어떻게 쓰느냐.. 일단 아래 설정 처럼 설정 파일을 정의 해 주고.
<sec:global-method-security secured-annotations="enabled" access-decision-manager-ref="businessAccessDecisionManager">
  <sec:after-invocation-provider ref="afterAclCollectionRead"/>
  <sec:after-invocation-provider ref="afterAclRead"/>
 </sec:global-method-security>

그런 다음에 보안 설정을 할 메서드에 @Secured를 설정 해 주면 된다.
@Secured( {"AFTER_ACL_COLLECTION_READ"})
 public ArrayList<AclBbs> getList( PagingUtil pagingUtil) {
  HashMap<String, Integer> params = new HashMap<String, Integer>();
  params.put( PagingUtil.START, pagingUtil.getStart());
  params.put( PagingUtil.LIMIT, pagingUtil.getLimit());
  params.put( PagingUtil.TOTALCOUNT, pagingUtil.getTotalCount());
  return aclBbsDAO.getList( params);
 }

이렇게 해서
스프링 시큐리티는 대충 내맘대로 정리 완료??