source: Git/src/main/java/com/wediscussmovies/project/LoggedUser.java@ 5b447b0

main
Last change on this file since 5b447b0 was 5b447b0, checked in by Test <matonikolov77@…>, 2 years ago

Adding models and resources

  • Property mode set to 100644
File size: 731 bytes
Line 
1package com.wediscussmovies.project;
2
3import com.wediscussmovies.project.model.User;
4import org.springframework.security.authentication.AnonymousAuthenticationToken;
5import org.springframework.security.core.Authentication;
6import org.springframework.security.core.context.SecurityContextHolder;
7import org.springframework.security.core.userdetails.UserDetails;
8
9public 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}
Note: See TracBrowser for help on using the repository browser.