整理 spring boot cas ,学习spring boot cas
1 application.properties
#CAS服务地址http://xxx.xxx.xx.xx:8080 cas.server.host.url=http://xxx.xxx.xx.xx:8080 #CAS服务登录地址 cas.server.host.login_url=${cas.server.host.url}/login #CAS服务登出地址 cas.server.host.logout_url=${cas.server.host.url}/logout?service=${app.server.host.url} #应用访问地址 app.server.host.url=http://localhost:8085 #应用登录地址 app.login.url=/cas #应用登出地址 app.logout.url=/logout
2 读取application.properties
@Component public class MyCasProperties { @Value("${cas.server.host.url}") private String casServerUrl; @Value("${cas.server.host.login_url}") private String casServerLoginUrl; @Value("${cas.server.host.logout_url}") private String casServerLogoutUrl; @Value("${app.server.host.url}") private String appServerUrl; @Value("${app.login.url}") private String appLoginUrl; @Value("${app.logout.url}") private String appLogoutUrl; public String getCasServerUrl() { return casServerUrl; } public void setCasServerUrl(String casServerUrl) { this.casServerUrl = casServerUrl; } public String getCasServerLoginUrl() { return casServerLoginUrl; } public void setCasServerLoginUrl(String casServerLoginUrl) { this.casServerLoginUrl = casServerLoginUrl; } public String getCasServerLogoutUrl() { return casServerLogoutUrl; } public void setCasServerLogoutUrl(String casServerLogoutUrl) { this.casServerLogoutUrl = casServerLogoutUrl; } public String getAppServerUrl() { return appServerUrl; } public void setAppServerUrl(String appServerUrl) { this.appServerUrl = appServerUrl; } public String getAppLoginUrl() { return appLoginUrl; } public void setAppLoginUrl(String appLoginUrl) { this.appLoginUrl = appLoginUrl; } public String getAppLogoutUrl() { return appLogoutUrl; } public void setAppLogoutUrl(String appLogoutUrl) { this.appLogoutUrl = appLogoutUrl; } }
3 启用web权限 WebSecurityConfigurerAdapter
@Configuration @EnableWebSecurity//启用web权限 public class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { @Autowired private MyCasProperties myCasProperties; @Autowired MyMetadataSourceService mySecurityMetadataSource; @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { super.configure(auth); auth.authenticationProvider(casAuthenticationProvider()); } &#