2

As you know @AuthenticationPrincipal in web.bind.annotation.AuthenticationPrincipal is depreacted . It is recommended to use core.annotation.AuthenticationPrincipal. So we have changed import statements as core.annotation.AuthenticationPrincipal and now we are getting below error :

org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.xxx.authentication.OurUserDetailsImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.xxx.xxx.authentication.OurUserDetailsImpl.<init>()

Are there any known problem related with this annotation ? P.S we are using parameterized constructor and we dont have a default constructor so I am aware of this. Many thanks.

Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51
Mesut Dogan
  • 572
  • 7
  • 16
  • What version of Spring Security are you using? Does it work with the deprecated `@AuthenticationPrincipal` annotation? How are you adding AuthenticationPrincipalArgumentResolver? Did you ensure that `org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver` is being used vs `org.springframework.security.web.bind.support.AuthenticationPrincipalArgumentResolver` – Rob Winch Mar 25 '16 at 13:36
  • Yes it works with deprecated annotation. Spring Security version is 4.0.3 and we didnt add AuthenticationPrincipalArgumentResolver yet. As soon as We add it I will share the result . Thanks – Mesut Dogan Mar 25 '16 at 13:52
  • Great ! It works now thanks for your support. – Mesut Dogan Mar 25 '16 at 13:57
  • Glad I could help. Is there a reason you feel that you missed this (i.e. do we need to make this obvious in documentation in a spot or multiple spots we missed?) – Rob Winch Mar 25 '16 at 14:00
  • @RobWinch how do you add `AuthenticationPrincipalArgumentResolver` when using annotation-based configuration? It seems I need to tell `spring-webmvc` to use it in my rest app, but it doesn't and just ignores `spring-security` - https://stackoverflow.com/questions/54352315/spring-security-authenticates-and-creates-principal-but-controller-gets-differen – Adam Jan 24 '19 at 18:54

1 Answers1

5

Make sure you are using org.springframework.security.web.method.annotation.AuthenticationPrincipalArgum‌​entResolver as apposed to org.springframework.security.web.bind.support.AuthenticationPrincipalArgum‌​entResolver.

UPDATE I created #3771 to track making this easier to follow in the documentation.

Rob Winch
  • 21,440
  • 2
  • 59
  • 76