@Test public void testGetSessionUserNotInstanceSessionUser() { List<GrantedAuthority> auths = new ArrayList<>(); auths.add(new SimpleGrantedAuthority("ROLE1")); auths.add(new SimpleGrantedAuthority("ROLE2")); UserDetails userDetails = new User("admin", "password", auths); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( userDetails, null, auths); SecurityContextHolder.getContext().setAuthentication(authentication); SessionUser actual = SecurityUtil.getSessionUser(); assertNull(actual); }
public static SessionUser getSessionUser() { try { final Object userObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (userObj instanceof SessionUser) { return ((SessionUser) userObj); } } catch (final NullPointerException npe) { _log.warn("No Security Context Found!"); } catch (final Exception e) { _log.error(e.getMessage()); } return null; }
SecurityUtil { public static SessionUser getSessionUser() { try { final Object userObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (userObj instanceof SessionUser) { return ((SessionUser) userObj); } } catch (final NullPointerException npe) { _log.warn("No Security Context Found!"); } catch (final Exception e) { _log.error(e.getMessage()); } return null; } }
SecurityUtil { public static SessionUser getSessionUser() { try { final Object userObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (userObj instanceof SessionUser) { return ((SessionUser) userObj); } } catch (final NullPointerException npe) { _log.warn("No Security Context Found!"); } catch (final Exception e) { _log.error(e.getMessage()); } return null; }  }
SecurityUtil { public static SessionUser getSessionUser() { try { final Object userObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (userObj instanceof SessionUser) { return ((SessionUser) userObj); } } catch (final NullPointerException npe) { _log.warn("No Security Context Found!"); } catch (final Exception e) { _log.error(e.getMessage()); } return null; }  static SessionUser getSessionUser(); SessionUser getUser(); static boolean currentUserHasPermission(final String permission); static Integer userTimeZone(); static Date userNow(); Date getNow(); }
SecurityUtil { public static SessionUser getSessionUser() { try { final Object userObj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (userObj instanceof SessionUser) { return ((SessionUser) userObj); } } catch (final NullPointerException npe) { _log.warn("No Security Context Found!"); } catch (final Exception e) { _log.error(e.getMessage()); } return null; }  static SessionUser getSessionUser(); SessionUser getUser(); static boolean currentUserHasPermission(final String permission); static Integer userTimeZone(); static Date userNow(); Date getNow();  }