Auto-Configuration Server
时间: 2023-11-07 16:29:50 浏览: 42
Auto-Configuration Server (ACS) 是一种用于远程管理和配置网络设备的服务器。它主要用于管理路由器、调制解调器、光猫等设备。ACS 可以通过 TR-069 协议与设备进行通信,从而实现设备的远程配置、故障排除、软件升级等功能。ACS 通常由服务提供商或网络运营商使用,以便更好地管理其设备和提供更好的服务。
相关问题
spring boot中cas-client-autoconfig-support 2.3.0-GA使用教程及原理解析
CAS(Central Authentication Service),即中央认证服务,是一种企业级的单点登录解决方案,通过认证服务器来实现用户的身份认证,并提供给多个Web应用系统进行认证授权。Spring Boot 中的 CAS Client Autoconfig Support 2.3.0-GA 是一个 CAS 客户端自动配置模块,可以在 Spring Boot 应用程序中轻松集成 CAS 认证功能。
以下是使用该模块的步骤:
1. 添加依赖
在 pom.xml 文件中添加以下依赖:
```xml
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>2.3.0-GA</version>
</dependency>
```
2. 配置 CAS 客户端
在 application.properties 或 application.yml 文件中添加以下 CAS 客户端配置:
```yaml
cas:
server-url-prefix: https://cas-server.com/cas
server-login-url: https://cas-server.com/cas/login
client-host-url: http://localhost:8080
```
其中,`server-url-prefix` 是 CAS 服务器的 URL 前缀,`server-login-url` 是 CAS 服务器的登录 URL,`client-host-url` 是应用程序的 URL。
3. 配置安全拦截器
在 Spring Security 配置中添加以下拦截器:
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CasAuthenticationEntryPoint casAuthenticationEntryPoint;
@Autowired
private CasAuthenticationProvider casAuthenticationProvider;
@Autowired
private CasLogoutFilter casLogoutFilter;
@Autowired
private CasAuthenticationFilter casAuthenticationFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(casAuthenticationEntryPoint)
.and()
.addFilter(casAuthenticationFilter)
.addFilterBefore(casLogoutFilter, LogoutFilter.class);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(casAuthenticationProvider);
}
}
```
其中,`CasAuthenticationEntryPoint` 是 CAS 认证入口点,`CasAuthenticationProvider` 是 CAS 认证提供程序,`CasLogoutFilter` 是 CAS 登出过滤器,`CasAuthenticationFilter` 是 CAS 认证过滤器。
4. 配置 CAS 服务
在 Spring Boot 应用程序中配置以下 CAS 服务:
```java
@Configuration
public class CasConfiguration {
@Bean
public ServiceProperties serviceProperties() {
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.setService("http://localhost:8080/login/cas");
serviceProperties.setSendRenew(false);
return serviceProperties;
}
@Bean
public CasAuthenticationProvider casAuthenticationProvider() {
CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider();
casAuthenticationProvider.setAuthenticationUserDetailsService(authenticationUserDetailsService());
casAuthenticationProvider.setServiceProperties(serviceProperties());
casAuthenticationProvider.setTicketValidator(cas20ServiceTicketValidator());
casAuthenticationProvider.setKey("casAuthenticationProviderKey");
return casAuthenticationProvider;
}
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService() {
return new UserDetailsServiceImpl();
}
@Bean
public Cas20ServiceTicketValidator cas20ServiceTicketValidator() {
return new Cas20ServiceTicketValidator("https://cas-server.com/cas");
}
@Bean
public CasAuthenticationFilter casAuthenticationFilter(ServiceProperties serviceProperties) throws Exception {
CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter();
casAuthenticationFilter.setServiceProperties(serviceProperties);
casAuthenticationFilter.setAuthenticationManager(authenticationManager());
return casAuthenticationFilter;
}
@Bean
public CasLogoutFilter casLogoutFilter() {
LogoutFilter logoutFilter = new LogoutFilter("https://cas-server.com/cas/logout", new SecurityContextLogoutHandler());
logoutFilter.setFilterProcessesUrl("/logout/cas");
return new CasLogoutFilter(logoutFilter);
}
@Bean
public CasAuthenticationEntryPoint casAuthenticationEntryPoint(ServiceProperties serviceProperties) {
CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint();
casAuthenticationEntryPoint.setLoginUrl("https://cas-server.com/cas/login");
casAuthenticationEntryPoint.setServiceProperties(serviceProperties);
return casAuthenticationEntryPoint;
}
}
```
以上就是使用 CAS Client Autoconfig Support 2.3.0-GA 的步骤和原理解析。该模块通过自动配置,可以帮助开发者快速集成 CAS 认证功能,提高开发效率。
springboot 如何调用cas-client-autoconfig-support 解析ticket
可以使用Spring Security CAS扩展来实现。在pom.xml文件中添加以下依赖项:
```
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-cas</artifactId>
<version>1.0.7.RELEASE</version>
</dependency>
```
然后在application.properties文件中添加以下配置:
```
# CAS server URL
cas.server.url=https://cas.example.com/cas
# CAS server login URL
cas.server.login.url=https://cas.example.com/cas/login
# CAS server logout URL
cas.server.logout.url=https://cas.example.com/cas/logout
# CAS service URL
cas.service.url=http://localhost:8080/login/cas
# CAS service name
cas.service.name=MyApp
# CAS service login URL
cas.service.login.url=http://localhost:8080/login
# CAS service logout URL
cas.service.logout.url=http://localhost:8080/logout
# CAS service validate URL
cas.service.validate.url=https://cas.example.com/cas/serviceValidate
# CAS service ticket parameter name
cas.service.ticket.parameterName=ticket
# CAS service renew parameter name
cas.service.renew.parameterName=renew
# CAS service gateway parameter name
cas.service.gateway.parameterName=gateway
# CAS service artifact parameter name
cas.service.artifact.parameterName=artifact
# CAS service proxy callback URL
cas.service.proxy.callbackUrl=http://localhost:8080/proxyCallback
# CAS service proxy callback parameter name
cas.service.proxy.callbackParameterName=pgtIou
# CAS service proxy granting ticket parameter name
cas.service.proxy.grantingTicket.parameterName=pgtIou
# CAS service proxy granting ticket storage class
cas.service.proxy.grantingTicket.storageClass=org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl
# CAS service proxy granting ticket storage file
cas.service.proxy.grantingTicket.storageFile=/tmp/cas-proxy-granting-tickets
# CAS service proxy granting ticket storage clean interval
cas.service.proxy.grantingTicket.storageCleanInterval=3600000
# CAS service proxy granting ticket storage clean up
cas.service.proxy.grantingTicket.storageCleanUp=true
# CAS service proxy granting ticket storage clean up interval
cas.service.proxy.grantingTicket.storageCleanUpInterval=3600000
# CAS service proxy granting ticket storage clean up max age
cas.service.proxy.grantingTicket.storageCleanUpMaxAge=7200000
```
然后在Spring Boot应用程序中添加以下配置类:
```
@Configuration
@EnableWebSecurity
@EnableCasSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CasAuthenticationEntryPoint casAuthenticationEntryPoint;
@Autowired
private CasAuthenticationProvider casAuthenticationProvider;
@Autowired
private SingleSignOutFilter singleSignOutFilter;
@Autowired
private CasAuthenticationFilter casAuthenticationFilter;
@Autowired
private CasProperties casProperties;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(casAuthenticationEntryPoint)
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.addLogoutHandler(new SingleSignOutHandler(casProperties.getServer().getLogoutUrl()))
.and()
.addFilterBefore(singleSignOutFilter, CasAuthenticationFilter.class)
.addFilter(casAuthenticationFilter);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(casAuthenticationProvider);
}
@Bean
public ServiceProperties serviceProperties() {
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.setService(casProperties.getService().getUrl());
serviceProperties.setSendRenew(false);
return serviceProperties;
}
@Bean
public CasAuthenticationEntryPoint casAuthenticationEntryPoint() {
CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint();
casAuthenticationEntryPoint.setLoginUrl(casProperties.getServer().getLoginUrl());
casAuthenticationEntryPoint.setServiceProperties(serviceProperties());
return casAuthenticationEntryPoint;
}
@Bean
public CasAuthenticationProvider casAuthenticationProvider() {
CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider();
casAuthenticationProvider.setAuthenticationUserDetailsService(new UserDetailsServiceImpl());
casAuthenticationProvider.setServiceProperties(serviceProperties());
casAuthenticationProvider.setTicketValidator(new Cas30ServiceTicketValidator(casProperties.getServer().getUrl()));
casAuthenticationProvider.setKey("casAuthenticationProviderKey");
return casAuthenticationProvider;
}
@Bean
public SingleSignOutFilter singleSignOutFilter() {
SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter();
singleSignOutFilter.setCasServerUrlPrefix(casProperties.getServer().getUrl());
singleSignOutFilter.setIgnoreInitConfiguration(true);
return singleSignOutFilter;
}
@Bean
public CasAuthenticationFilter casAuthenticationFilter() {
CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter();
casAuthenticationFilter.setAuthenticationManager(authenticationManager());
casAuthenticationFilter.setFilterProcessesUrl("/login/cas");
return casAuthenticationFilter;
}
}
```
最后,在Spring Boot应用程序中添加以下服务类:
```
@Service
public class UserDetailsServiceImpl implements AuthenticationUserDetailsService<CasAssertionAuthenticationToken> {
@Override
public UserDetails loadUserDetails(CasAssertionAuthenticationToken token) throws UsernameNotFoundException {
String username = token.getName();
List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
return new User(username, "", authorities);
}
}
```
现在,您可以使用Spring Boot应用程序调用CAS客户端自动配置支持来解析票据。