01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

>[font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b][/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]        <dependency>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <groupId>org.pac4j</groupId>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <artifactId>pac4j-cas</artifactId>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <version>3.8.3</version>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]        </dependency>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b][/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]        <dependency>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <groupId>io.buji</groupId>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <artifactId>buji-pac4j</artifactId>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]            <version>4.1.1</version>[/b][/color][/font][/align][align=left][font=-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif][color=#24292e][b]        </dependency>[/b][/color][/font]/mw_shl_code][/align][align=left]JAVA配置[/align][align=left][mw_shl_code=java,true]//Pac4jConfig.java 配置中

 @Bean

 public CasConfiguration casConfig() {

  final CasConfiguration configuration = new CasConfiguration();

  //CAS server登录地址

  configuration.setLoginUrl(casServerUrl + "/login");

  configuration.setAcceptAnyProxy(true);

  configuration.setPrefixUrl(casServerUrl + "/");

  //监控CAS服务端登出,登出后销毁本地session实现双向登出

  DefaultLogoutHandler logoutHandler = new DefaultLogoutHandler();

  logoutHandler.setDestroySession(true);

  configuration.setLogoutHandler(logoutHandler);

  return configuration;

 }

//ShiroConfig.java 中

//shiro 过滤器配置中增加SecurityFilter,CallbackFilter ,LogoutFilter

 @Bean("shiroFilter")

 public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {

  ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();

  shiroFilterFactoryBean.setSecurityManager(securityManager);

  //获取filters

  Map<String, Filter> filters = shiroFilterFactoryBean.getFilters();

  filters.put("authc", new MySystemFilter());

  // cas 资源认证拦截器

  SecurityFilter securityFilter = new SecurityFilter();

  securityFilter.setConfig(exPac4jConfig);

  securityFilter.setClients(clientName);

  filters.put("securityFilter", securityFilter);

  //cas 认证后回调拦截器

  CallbackFilter callbackFilter = new CallbackFilter();

  callbackFilter.setConfig(exPac4jConfig);

  filters.put("callbackFilter", callbackFilter);

  shiroFilterFactoryBean.setFilters(filters);

  // 本地登出同步登出CAS服务器

  LogoutFilter pac4jCentralLogout = new LogoutFilter();

  pac4jCentralLogout.setConfig(exPac4jConfig);

  pac4jCentralLogout.setCentralLogout(true);

  pac4jCentralLogout.setLocalLogout(true);

  filters.put("pac4jCentralLogout", pac4jCentralLogout);

  //拦截器.

  Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();

  filterChainDefinitionMap.put("/logout", "logout");

  filterChainDefinitionMap.put("/pac4jCentralLogout", "pac4jCentralLogout");

  filterChainDefinitionMap.put("/cas", "securityFilter");

  filterChainDefinitionMap.put("/callback", "callbackFilter");

  filterChainDefinitionMap.put("/**", "authc");

  shiroFilterFactoryBean.setLoginUrl("/login");

  shiroFilterFactoryBean.setSuccessUrl("index");

  shiroFilterFactoryBean.setUnauthorizedUrl("/error/403");

  shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

  return shiroFilterFactoryBean;

 }

 @Bean

 public SecurityManager securityManager() {

  DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();

  securityManager.setAuthenticator(exModularRealmAuthenticator());

  List<Realm> realms = new ArrayList<>();

  realms.add(exSystemRealm());

 // casRealm继承Pac4jRealm 与shiro的Realm使用方法相同

  realms.add(casRealm);

  securityManager.setRealms(realms);

  securityManager.setCacheManager(redisCacheManager());

 //增加pac4jSubjectFactory

  securityManager.setSubjectFactory(pac4jSubjectFactory);

  securityManager.setRememberMeManager(cookieRememberMeManager());

  securityManager.setSessionManager(sessionManager());

  return securityManager;

 }