Spring Security version: spring-boot-starter-security:1.3.0.RC1
Noticing that the annotation @AuthenticationPrincipal
has been deprecated.
Possible different way to accomplish the same thing and wondering if this is the correct way to get user information within a Spring MVC Controller.
@RequestMapping(method = RequestMethod.GET)
public String getIndex(HttpSession session, Device device, Model model, Principal principal) {
/**
* Spring Security Fetch User
*/
if (principal != null) {
String username = principal.getName();
User currentUser = userRepository.findByEmail(username);
model.addAttribute("user", currentUser.getFirstName());
}
return "view";
}
On another note I found not having the HttpSession session
would result in stale sessions causing page load errors.
The first thing to note is that Spring Security OAuth 2.4. 0 officially deprecates all its classes. The second thing is that according to the Spring Security - OAuth 2.0 Features Matrix - FAQ: We are no longer planning on adding Authorization Server support to Spring Security.
The type WebSecurityConfigurerAdapter is deprecatedWell, it's because the developers of Spring framework encourage users to move towards a component-based security configuration.
The principal is the currently logged in user. However, you retrieve it through the security context which is bound to the current thread and as such it's also bound to the current request and its session.
Spring Boot provides a default global AuthenticationManager (with only one user) unless you pre-empt it by providing your own bean of type AuthenticationManager . The default is secure enough on its own for you not to have to worry about it much, unless you actively need a custom global AuthenticationManager .
The annotation has been moved to another package.
Use org.springframework.security.core.annotation.AuthenticationPrincipal
instead of the deprecated org.springframework.security.web.bind.annotation.AuthenticationPrincipal
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With