Clean Code that Works.

그냥 일반 DB를 하이버네이트를 써서 스프링 시큐리티로 만든 User 클래스를 사용하면, 로그인도 잘 되고 아무 문제가 없는데

User 클래스를 Neo4j로 사용하면 로그인 하는데 문제가 발생한다.


User 클래스에는 시큐리티 플러그인이 만들어준 "beforeInsert", "beforeUpdate" 메서드가 있고, 여기서 password 인코딩을 해준다.

위 이벤트들은 GORM에서 지원해 주는 것들(http://grails.org/doc/latest/guide/GORM.html#eventsAutoTimestamping)


근데 Neo4j를 사용하면.. 그냥 list 를 호출하는데도 beforeUpdate 가 계속 호출되어, 패스워드 값이 여러번 변경된다.. 

무려 3번. 그냥 list를 호출하는데도.. -_-;; 이건 뭐야!!


저게 존재하는 이유가 패스워드 인코딩을 하기 위한거니..

해결 방법은. 

User 클래스의 위의 두 메서드( beforeInsert, beforeUpdate)를 제거 하고, UserController에서 패스워드 인코딩 하는 내용을 넣어 주는 걸로 변경 함. 


꼼수로.. 하이버네이트와 Neo4j를 같이 써볼려고 했는데..

Neo4j로 쓰는 도메인과 하이버네이트로 쓰는 도메인은.. Neo4j에서 참조가 안되는 관계로 포기.


예를 들어 Neo4j 는 '학교' 이고 하이버네이트가 '학생'일때 '학교'는 '학생'을 참조하고 있으면 에러남..

당연한 이야기긴 한데.. 뭔가 GORM에서 해결했을것 같은 느낌이 들어서 시도해봄...


아 그리고 User 클래스 만들어 주는 템플릿은 스프링 시큐리티 프러그인 내에 "Person.groovy.template"로 존재함.

스프링 처럼 DI를 받을 수 있는데...

FBUserDetailService를 di 받아서 사용할 경우 일반적으로 
def fbUserDetailService 이런 형식의 카멜 표기법으로 정의하는것으로 생각한다.

하지만 되지 않아!!!!!

http://grails.org/doc/latest/guide/services.html#dependencyInjectionServices 

저기 문서의 가운데를 보면

NOTE: Normally the property name is generated by lower casing the first letter of the type. For example, an instance of the BookService class would map to a property named bookService.

To be consistent with standard JavaBean conventions, if the first 2 letters of the class name are upper case, the property name is the same as the class name. For example, the property name of theJDBCHelperService class would be JDBCHelperService, not jDBCHelperService or jdbcHelperService.

See section 8.8 of the JavaBean specification for more information on de-capitalization rules.



JDBCHelperService를 DI 받을려면 JDBCHelperService로 작명을 해주어야 한다고 한다.

뭐 그럼 나도 사용할 때

def FBUserDetailService 로 하면 됨 @_@