title: security util using SecurityContextHolder in spring application
body: <p>in my spring application I have some aspects for controller methods where I do some security checks. beacause of I need several checks more often I wrapped them into static helper methods of a "sercurityUtil" class.:</p>
  
  <pre><code>public abstract class SecurityUtils {
  
      public static Authentication getCurrentAuthentication(){
          return SecurityContextHolder.getContext().getAuthentication();
      }
  
      public static ChroniosUser getAuthenticatedUser(){
          return (ChroniosUser) getCurrentAuthentication().getPrincipal();
      }
  
      public static boolean authenticationHasRole(Authentication authentication, Role role){
          SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role.getRoleIdentifier());
          return authentication.getAuthorities().contains(grantedAuthority);
      }
  
      public static boolean authenticatedUserIsAdmin(){
          Authentication authentication = getCurrentAuthentication();
          return authenticationHasRole(authentication, ADMIN);
      }
  
      ...
  }
  </code></pre>
  
  <p>is this a valid and good approach?
  or shut I wrap these helper functions into a spring service?</p>
  
  <p>thank you.</p>
  
  <p>PS: I know that I can use @PreAuthorize ... but my aspects are more complex.</p>