Blame view

src/main/java/fr/plil/sio/web/mvc/SecurityServiceImpl.java 793 Bytes
94a17877   jcartign   Add SecurityServi...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  package fr.plil.sio.web.mvc;
  
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.security.core.context.SecurityContextHolder;
  import org.springframework.security.core.userdetails.UserDetails;
  import org.springframework.stereotype.Service;
  
  @Service
  public class SecurityServiceImpl implements SecurityService{
  
      private static final Logger logger = LoggerFactory.getLogger(SecurityServiceImpl.class);
  
      @Override
      public String findLoggedInUsername() {
19426ff3   jcartign   Fix SecurityServi...
17
          Object userDetails = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
94a17877   jcartign   Add SecurityServi...
18
19
20
          if (userDetails instanceof UserDetails) {
              return ((UserDetails)userDetails).getUsername();
          }
19426ff3   jcartign   Fix SecurityServi...
21
          logger.warn("cannot find logged user");
94a17877   jcartign   Add SecurityServi...
22
23
24
          return null;
      }
  }