| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package cn.seecoder.web.infrastructure.security;
- import cn.seecoder.web.model.enums.UserIdentity;
- import org.springframework.security.core.GrantedAuthority;
- import org.springframework.security.core.authority.SimpleGrantedAuthority;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * @author PuHong Weng
- * @date 2021/3/8
- * @description:
- */
- public abstract class WebSecurityConstants {
- private static final String ROLE_PREFIX = "ROLE_";
- public static final String STUDENT_ROLE = "STUDENT";
- public static final String TEACHER_ROLE = "TEACHER";
- public static final String ADMIN_ROLE = "ADMIN";
- public static final String STAFF_ROLE = "STAFF";
- public static final String HR_ROLE = "HR";
- public static final String SEEC_ROLE = "SEEC";
- public static final String SEECX_ROLE = "SEECX";
- public static final String ASSISTANT_ROLE = "ASSISTANT";
- public static final GrantedAuthority STUDENT_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + STUDENT_ROLE);
- public static final GrantedAuthority TEACHER_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + TEACHER_ROLE);
- public static final GrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + ADMIN_ROLE);
- public static final GrantedAuthority STAFF_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + STAFF_ROLE);
- public static final GrantedAuthority HR_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + HR_ROLE);
- public static final GrantedAuthority SEEC_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + SEEC_ROLE);
- public static final GrantedAuthority SEECX_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + SEECX_ROLE);
- public static final GrantedAuthority ASSISTANT_AUTHORITY = new SimpleGrantedAuthority(ROLE_PREFIX + ASSISTANT_ROLE);
- private static final Map<UserIdentity,GrantedAuthority> authorityTable= new HashMap<>();
- static {
- authorityTable.put(UserIdentity.STUDENT, STUDENT_AUTHORITY);
- authorityTable.put(UserIdentity.TEACHER, TEACHER_AUTHORITY);
- authorityTable.put(UserIdentity.ADMIN, ADMIN_AUTHORITY);
- authorityTable.put(UserIdentity.STAFF, STAFF_AUTHORITY);
- authorityTable.put(UserIdentity.HR, HR_AUTHORITY);
- authorityTable.put(UserIdentity.SEEC, SEEC_AUTHORITY);
- authorityTable.put(UserIdentity.SEECX, SEECX_AUTHORITY);
- authorityTable.put(UserIdentity.ASSISTANT, ASSISTANT_AUTHORITY);
- }
- public static GrantedAuthority getAuthority(UserIdentity identity){
- return authorityTable.get(identity);
- }
- }
|