• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

인자를 두개 넘기게 할수 있는 방법있을까요??

22.11.09 14:16 작성 조회수 202

1

[spring][spring security] 기존에는

1)Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); ------> 2) public class CustomAuthenticationProvider implements AuthenticationProvider authenticate(authenticationToken) 메소드 ------> 3)public class PrincipalDetailService implements UserDetailsService

1)을 호출하면 2)클래스와 3) 클래스가 사용됩니다.

------------------------------------------------------------------------

저는 여기서 !!!! 인자를 2개 넘기고 싶습니다.

1)Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken, "인자 추가")

------> 2) public class CustomAuthenticationProvider implements AuthenticationProvider의 authenticate (authenticationToken, "인자 추가") 메소드 하면 에러가 납니다.

이미 security가 지원하는 AuthenticationProvider을 받아서 쓰는 거라 인자 추가가 안되는 것 같습니다... 스 할 수 있는 방법이나 아이디어가 있으실까요?? 어떤 아이디어도 좋습니다 !

참고로) AuthenticationProvider는 읽기 전용이라 수정이 안되기도 하고, spring이 제가 만든 AuthenticationProvider 사용하지 않습니다...!

 

답변 1

답변을 작성해보세요.

0

원칙적으로 인터페이스에 정의된 메서드의 사양은 변경이 불가능합니다.

인터페이스의 규약을 벗어나는 것 자체가 인터페이스를 사용하는 취지에 맞지 않습니다.

그것보다는 이런 방법이 더 좋습니다

Authentication 의 구현체인 UsernamePasswordAuthenticationToken 을 보시면 details 속성이 있습니다.

이 속성에는 타입에 관계없이 여러 값들을 저장할 수 있습니다.

그래서 추가적인 파라미터를 이 속성에 저장하고 필요할 때 꺼내어 사용하시면 됩니다.

이것과 관련해서는

섹션 3. 실전프로젝트 -인증 프로세스 Form 인증 구현

  • 8) 인증 부가 기능 - WebAuthenticationDetails, AuthenticationDetailsSource

     

    강의를 참고하시기 바랍니다.