1
0

WebSecurityConstants.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package cn.seecoder.web.infrastructure.security;
  2. import cn.seecoder.web.model.enums.UserIdentity;
  3. import org.springframework.security.core.GrantedAuthority;
  4. import org.springframework.security.core.authority.SimpleGrantedAuthority;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. /**
  8. * @author PuHong Weng
  9. * @date 2021/3/8
  10. * @description:
  11. */
  12. public abstract class WebSecurityConstants {
  13. private static final String ROLE_PREFIX = "ROLE_";
  14. public static final String STUDENT_ROLE = "STUDENT";
  15. public static final String TEACHER_ROLE = "TEACHER";
  16. public static final String ADMIN_ROLE = "ADMIN";
  17. public static final String STAFF_ROLE = "STAFF";
  18. public static final String HR_ROLE = "HR";
  19. public static final String SEEC_ROLE = "SEEC";
  20. public static final String SEECX_ROLE = "SEECX";
  21. public static final String ASSISTANT_ROLE = "ASSISTANT";
  22. public static final GrantedAuthority STUDENT_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + STUDENT_ROLE);
  23. public static final GrantedAuthority TEACHER_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + TEACHER_ROLE);
  24. public static final GrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + ADMIN_ROLE);
  25. public static final GrantedAuthority STAFF_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + STAFF_ROLE);
  26. public static final GrantedAuthority HR_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + HR_ROLE);
  27. public static final GrantedAuthority SEEC_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + SEEC_ROLE);
  28. public static final GrantedAuthority SEECX_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + SEECX_ROLE);
  29. public static final GrantedAuthority ASSISTANT_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + ASSISTANT_ROLE);
  30. private static final Map<UserIdentity,GrantedAuthority> authorityTable= new HashMap<>();
  31. static {
  32. authorityTable.put(UserIdentity.STUDENT, STUDENT_AUTHORITY);
  33. authorityTable.put(UserIdentity.TEACHER, TEACHER_AUTHORITY);
  34. authorityTable.put(UserIdentity.ADMIN, ADMIN_AUTHORITY);
  35. authorityTable.put(UserIdentity.STAFF, STAFF_AUTHORITY);
  36. authorityTable.put(UserIdentity.HR, HR_AUTHORITY);
  37. authorityTable.put(UserIdentity.SEEC, SEEC_AUTHORITY);
  38. authorityTable.put(UserIdentity.SEECX, SEECX_AUTHORITY);
  39. authorityTable.put(UserIdentity.ASSISTANT, ASSISTANT_AUTHORITY);
  40. }
  41. public static GrantedAuthority getAuthority(UserIdentity identity){
  42. return authorityTable.get(identity);
  43. }
  44. }