Beispiel #1
0
 public static String getRoleType() {
   MyUser myUser = getMyUser();
   if (myUser != null && myUser.getId() != null) {
     return myUser.getRole().getBasicType();
   } else {
     return "";
   }
 }
Beispiel #2
0
 public static User getUser() {
   SecurityContext securityContext = SecurityContextHolder.getContext();
   Authentication authentication = securityContext.getAuthentication();
   MyUser myUser = (MyUser) authentication.getPrincipal();
   User user = new User();
   user.setId(myUser.getId());
   user.setName(myUser.getName());
   user.setUsername(myUser.getUsername());
   return user;
 }
Beispiel #3
0
  public static MyUser getMyUser() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    try {
      return (MyUser) authentication.getPrincipal();
    } catch (Exception e) {
      MyUser myUser = new MyUser();
      Role role = new Role();
      role.setBasicType("all");

      myUser.setRole(role);
      return myUser;
    }
  }