Spring Roo, Spring Security, 사용자 추가하기
Spring/Spring Roo / 2011. 10. 11. 00:53
Spring Roo 에서는 간단하게 "security setup" 명령으로 Spring Security 기본 설정을 추가할 수 있습니다.
기본적으로 admin 과 user 계정을 제공하고 "sha-256" 로 암호화된 패스워드를 제공합니다.
계정 추가가 필요할 때는 다음과 같은 작업을 통해서 가능합니다.
*nix 계열 서버에서 아래와 같은 명령어로 암호화된 패스워드를 생성할 수 있습니다.
# echo -n vicki | sha256sum
9f6646bd8c323f20de7538195709835dea9ab11108ea88326bdfaeb32cb2d9a4 -
9f6646bd8c323f20de7538195709835dea9ab11108ea88326bdfaeb32cb2d9a4 -
위와 같이 "echo -n [패스워드] | sha256sum" 명령어를 입력하면 볼드체와 같이 암호화된 값을 확인할 수 있습니다.
생성된 패스워드를 이용하여 security 설정파일에 추가합니다.
/src/main/resources/META-INF/spring/applicationContext-security.xml
01 | < beans:beans > |
02 | ... |
03 |
04 | <!-- Configure Authentication mechanism --> |
05 | < authentication-manager alias = "authenticationManager" > |
06 | <!-- SHA-256 values can be produced using 'echo -n your_desired_password | sha256sum' (using normal *nix environments) --> |
07 | < authentication-provider > |
08 | < password-encoder hash = "sha-256" /> |
09 | < user-service > |
10 | < user name = "admin" password = "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918" authorities = "ROLE_ADMIN" /> |
11 | < user name = "user" password = "04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb" authorities = "ROLE_USER" /> |
12 | < user name = "vicki" password = "9f6646bd8c323f20de7538195709835dea9ab11108ea88326bdfaeb32cb2d9a4" authorities = "ROLE_USER" /> |
13 | </ user-service > |
14 | </ authentication-provider > |
15 | </ authentication-manager > |
16 |
17 | </ beans:beans > |
이제 /login 으로 접속하여 테스트 진행합니다.