public static String getRoleType() { MyUser myUser = getMyUser(); if (myUser != null && myUser.getId() != null) { return myUser.getRole().getBasicType(); } else { return ""; } }
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; }
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; } }