gpt4 book ai didi

java - 通过CAS服务器对Spring Web应用程序进行身份验证

转载 作者:行者123 更新时间:2023-11-30 06:59:52 25 4
gpt4 key购买 nike

我在我的服务器上安装了 CAS 服务器。 (在 apache tomcat 中进行 war 部署)。我在该 CAS 服务器上有我的用户信息,例如用户名和密码。 (将来它将连接到LDAP或简单关系数据库以获取用户凭证。问题就在这里。我想通过这个CAS服务器验证我的spring应用程序,但我找不到任何正确的spring安全配置。我的配置文件是:

        @Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/assets","/css", "/js","/font-awesome","/bootstrap","/images").permitAll()
.antMatchers("/", "/home").authenticated()
// .antMatchers("/hi").access("hasRole('ROLE_SUBSCRIPTION') or hasRole('ROLE_ADMIN')")
.antMatchers("/edit").authenticated()
// .antMatchers("/playlists/*").authenticated()
// .antMatchers("/createplaylist").authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}

@Bean
public ServiceProperties serviceProperties() {
ServiceProperties sp = new ServiceProperties();
sp.setService(env.getRequiredProperty(CAS_SERVICE_URL));
sp.setSendRenew(false);
return sp;
}
@Bean
public Set<String> adminList() {
Set<String> admins = new HashSet<String>();
String adminUserName = env.getProperty(APP_ADMIN_USER_NAME);

admins.add("admin");
if (adminUserName != null && !adminUserName.isEmpty()) {
admins.add(adminUserName);
}
return admins;
}

@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() {
return new CustomUserDetailsService(adminList());
}
@Bean
public CasAuthenticationProvider casAuthenticationProvider() {
CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider();
// casAuthenticationProvider.setAuthenticationUserDetailsService(customUserDetailsService());
// casAuthenticationProvider.setServiceProperties(serviceProperties());
casAuthenticationProvider.setTicketValidator(cas20ServiceTicketValidator());
// casAuthenticationProvider.setKey("an_id_for_this_auth_provider_only");
return casAuthenticationProvider;
}
@Bean
public Cas20ServiceTicketValidator cas20ServiceTicketValidator() {
return new Cas20ServiceTicketValidator(env.getRequiredProperty(CAS_URL_PREFIX));
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
auth.authenticationProvider(casAuthenticationProvider());
}

最佳答案

嗯,我在 GitHub 上找到了一个简单的 Spring Cas 客户端自动配置,只需两个 Action :)首先添加依赖第二个只是添加注释 https://github.com/Unicon/cas-client-autoconfig-support

关于java - 通过CAS服务器对Spring Web应用程序进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41113815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com