source:
Git/src/main/java/com/wediscussmovies/project/LoggedUser.java@
6f91f99
Last change on this file since 6f91f99 was 7f36551, checked in by , 3 years ago | |
---|---|
|
|
File size: 732 bytes |
Line | |
---|---|
1 | package com.wediscussmovies.project; |
2 | |
3 | import com.wediscussmovies.project.model.User; |
4 | import org.springframework.security.authentication.AnonymousAuthenticationToken; |
5 | import org.springframework.security.core.Authentication; |
6 | import org.springframework.security.core.context.SecurityContextHolder; |
7 | import org.springframework.security.core.userdetails.UserDetails; |
8 | |
9 | public class LoggedUser { |
10 | |
11 | static public User getLoggedUser(){ |
12 | |
13 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
14 | if (!(auth instanceof AnonymousAuthenticationToken)) { |
15 | UserDetails userDetails = (UserDetails) auth.getPrincipal(); |
16 | return (User) userDetails; |
17 | } |
18 | return null; |
19 | } |
20 | |
21 | } |
Note:
See TracBrowser
for help on using the repository browser.