main
Last change
on this file was 980eeda, checked in by Test <matonikolov77@…>, 2 years ago |
Restructuring project
|
-
Property mode
set to
100644
|
File size:
732 bytes
|
Rev | Line | |
---|
[5b447b0] | 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 | }
|
---|
[7f36551] | 20 |
|
---|
[5b447b0] | 21 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.