我正在使用Spring Boot构建一个与LDAP集成的应用程序.我能够成功连接到LDAP服务器并验证用户身份.现在我需要添加remember-me功能.我试图通过不同的帖子(这个)查看,但无法找到我的问题的答案.Spring Spring官方文件指出
如果您使用的身份验证提供程序不使用UserDetailsService(例如,LDAP提供程序),那么除非您的应用程序上下文中还有UserDetailsService bean,否则它将无法工作
在这里,我的工作代码有一些初步的想法,以添加记住我的功能:
WebSecurityConfig
import com.ui.security.CustomUserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.event.LoggerListener;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
String DOMAIN = "ldap-server.com";
String URL = "ldap://ds.ldap-server.com:389";
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/ui/**").authenticated()
.antMatchers("/", "/home", "/UIDL/**", "/ui/**").permitAll()
.anyRequest().authenticated()
;
http
.formLogin()
.loginPage("/login").failureUrl("/login?error=true").permitAll()
.and().logout().permitAll()
;
// Not …Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-security-ldap spring-boot
目前我的应用程序中有一个身份验证机制,即使用LDAP进行身份验证和授权.我的安全配置如下所示
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.httpBasic();
}
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Value("${ldap-${env}.manager.dn}")
private String managerDn;
@Value("${ldap-${env}.manager.pass}")
private String managerPass;
@Value("${ldap-${env}.server.url}")
private String url;
@Value("${ldap.password.attribute:userPassword}")
private String passwordAttr;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().userDnPatterns("uid={0},ou=people").groupSearchBase("ou=groups")
.groupSearchFilter("(member={0})").userSearchBase("ou=people").userSearchFilter("(uid={0})")
.userDetailsContextMapper(new CustomLdapPersonContextMapper())
// .passwordCompare()
// .passwordAttribute(passwordAttr)
// .passwordEncoder(new PlaintextPasswordEncoder())
// .and()
.contextSource().managerDn(managerDn).managerPassword(managerPass).url(url);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在某些情况下,用户可能会使用会话令牌进入会话令牌,该会话令牌可以从会话密钥服务器进行身份验证,并且有效令牌会返回用户名,然后可以使用该用户名从LDAP为该用户加载身份验证信息.所以我的第二个身份验证机制应该首先发生,如果http头中存在会话令牌,它应该执行令牌身份验证然后执行ldap查找,如果没有会话令牌,它应该属于当前的身份验证机制.如何添加第二层身份验证.
这里有一个spring-security示例ldap-xml,它运行ldap服务器并导入LDIF文件以进行测试:
[...]
<s:ldap-server ldif="classpath:users.ldif" port="33389"/>
<s:authentication-manager>
<s:ldap-authentication-provider
group-search-filter="member={0}"
group-search-base="ou=groups"
user-search-base="ou=people"
user-search-filter="uid={0}"
/>
<s:authentication-provider ref='secondLdapProvider' />
</s:authentication-manager>
[...]
Run Code Online (Sandbox Code Playgroud)
[...]
dn: uid=rod,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
uid: rod
userPassword: koala
[...]
Run Code Online (Sandbox Code Playgroud)
我需要修改这个工作示例,其中user-search-criteria基于sAMAccountName而不是uid.我修改users.ldif如下:
[...]
dn: cn=rod,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
sAMAccountName: rod
userPassword: koala
[...]
Run Code Online (Sandbox Code Playgroud)
但是,在导入users时,apached会显示警告.ldif:
OID for name 'samaccountname' was not found within the OID registry
Run Code Online (Sandbox Code Playgroud)
似乎我需要通过修改LDAP模式来添加这个新属性sAMAccountName.如何在ldap-xml示例中执行此操作?
在这个要点示例中,他们使用"changetype:add"修改架构.但是在users.ldif中添加此项会导致错误 …
我正在使用ActiveDirectoryLdapAuthenticationProvider带有Spring Boot 的Spring Security (基于注释的配置)来使用Active Directory进行身份验证并生成令牌.一切正常.
我希望添加一些模拟整个过程的集成测试,我想可能会使用Spring嵌入式LDAP服务器.
我在网上找到的另一个例子中添加了这个ldif文件.
#Actual test data
dn: dc=test,dc=com
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: local
# Organizational Units
dn: ou=groups,dc=test,dc=com
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=test,dc=com
objectclass: top
objectclass: organizationalUnit
ou: people
# Create People
dn: uid=testuser,ou=people,dc=test,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Test
sn: User
uid: testuser
password: secret
# Create Groups
dn: cn=developers,ou=groups,dc=test,dc=com
objectclass: top
objectclass: groupOfUniqueNames
cn: developers
ou: developer
uniqueMember: uid=testuser,ou=people,dc=test,dc=com
dn: cn=managers,ou=groups,dc=test,dc=com …Run Code Online (Sandbox Code Playgroud) active-directory spring-security ldif spring-security-ldap spring-boot
请问有关spring-security-oauth2 2.0.7的配置问题.我通过GlobalAuthenticationConfigurerAdapter使用LDAP进行身份验证:
@SpringBootApplication
@Controller
@SessionAttributes("authorizationRequest")
public class AuthorizationServer extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(AuthorizationServer.class, args);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
registry.addViewController("/oauth/confirm_access").setViewName("authorize");
}
@Configuration
public static class JwtConfiguration {
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory(
new ClassPathResource("keystore.jks"), "foobar".toCharArray())
.getKeyPair("test");
converter.setKeyPair(keyPair);
return converter;
}
@Bean
public JwtTokenStore jwtTokenStore(){
return new JwtTokenStore(jwtAccessTokenConverter());
}
}
@Configuration
@EnableAuthorizationServer
public static class OAuth2Config extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {
private static …Run Code Online (Sandbox Code Playgroud) spring spring-security spring-security-ldap spring-security-oauth2
新手问题所以请耐心等待......
目前我有一个Grails 2.4.4应用程序,它使用spring-security-ldap 2.0.1通过OpenLdap服务器对+授权用户进行身份验证.
LDAP人员担心,在迁移到Production时可能不会缓存此应用程序可能会影响LDAP服务器的性能.他们建议使用Redis作为用户的应用程序级缓存,b4命中LDAP服务器.
在潜入POC之前,我想先了解一些方向,确保我从正确的道路开始:
i)我简单地查看了Grail org的'Grails 1&2 Plugins',当我搜索Redis时出现了几个插件......哪一个实际上与我想要实现的相关?
ii)假设我已经将Redis缓存集成到我的Grails中,我如何/在哪里告诉spring-security-ldap先查看Redis缓存,b4如何点击Ldap服务器?
在此先感谢任何信息/指南..
我有一个自定义的Spring Security过滤器,扩展了GenericFilterBean.
为了进行自动依赖和bean创建,我添加了一个@Component注释.
在我的安全配置中,我也注册过滤器,如:
@Autowired
private RestAuthenticationFilter restAuthenticationFilter;
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.addFilterBefore(restAuthenticationFilter, LogoutFilter.class)
Run Code Online (Sandbox Code Playgroud)
一切都运行良好,除了我的过滤器被调用两次......似乎Spring也自动将过滤器添加到标准过滤器.
这里最好的方法是什么?
UPDATE
@Dave这是你的意思吗?它似乎工作.
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends WebMvcConfigurerAdapter {
@Autowired
private RestAuthenticationFilter restAuthenticationFilter;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ApplicationSecurity applicationSecurity() {
return new ApplicationSecurity();
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setEnabled(false);
filterRegistrationBean.setFilter(restAuthenticationFilter);
return filterRegistrationBean;
}
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Autowired
private …Run Code Online (Sandbox Code Playgroud) 我试图确定是否可以在同一spring oauth2授权服务中为每个客户端ID使用不同的身份验证提供程序.
特别是,我想允许外部用户登录我们公司网站的资源所有者密码令牌授予,以及企业用户的隐式授权.企业用户存储在我们的企业Active Directory服务器中,而外部用户存储在单独的LDAP服务器中.
是否有可能以某种方式将AuthenticationManager绑定到clientId?
spring spring-security spring-security-ldap spring-security-oauth2
总之,用户正在经过身份验证,但我似乎确实已经登录到用户帐户。
我目前正在一个项目上实施 LDAP 身份验证。看来,身份验证部分正在工作,因为我的应用程序确实接受了正确的凭据。我遇到的问题是我似乎无法在 jsp 视图中访问“principal”。(在切换到 LDAP 之前我能够访问所有这些)。运行跟踪时,我的 CustomUserDetails 服务正在查询并提取正确的帐户信息。任何帮助表示赞赏
这将显示正确的用户名:
<sec:authorize access="isAuthenticated()">
<h2><sec:authentication property="name"/></h2>
</sec:authorize>
Run Code Online (Sandbox Code Playgroud)
这不起作用(它在 LDAP 之前确实有效)
<sec:authorize access="isAuthenticated()">
<h2><sec:authentication property="principal.firstName"/></h2>
</sec:authorize>
Run Code Online (Sandbox Code Playgroud)
相关代码SecurityConfig.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.authentication.UserDetailsServiceLdapAuthoritiesPopulator;
import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private CustomUserDetailsService userDetailsService;
@Bean
public CustomSaltSource customSaltSource(){ return new CustomSaltSource();}
@Bean
public AuthenticationSuccessHandler myAuthenticationSuccessHandler(){
return new AuthenticationSuccessHandler();
}
@Autowired
void configureGlobal(AuthenticationManagerBuilder auth) throws …Run Code Online (Sandbox Code Playgroud) 我们正在使用 Spring Security Ldap 库 (v4.0.4) 从我们客户端的 Active Directory (ldap://domain:389) 中获取用户列表,并对他们进行身份验证以登录到我们的 Web 应用程序。
微软最近发布了启用 LDAP 通道绑定和 LDAP 签名的公告:https : //portal.msrc.microsoft.com/en-us/security-guidance/advisory/ADV190023
“LDAP 通道绑定和 LDAP 签名提供了提高 LDAP 客户端和 Active Directory 域控制器之间通信安全性的方法。Active Directory 域控制器上存在一组不安全的 LDAP 通道绑定和 LDAP 签名默认配置,允许 LDAP 客户端与其通信没有强制执行 LDAP 通道绑定和 LDAP 签名。这可以打开 Active Directory 域控制器以提升特权漏洞。”
我们被问到在他们的服务器上启用 LDAP 通道绑定和 LDAP 签名是否会影响我们的流程。我在文档中找不到关于这些的信息:https : //docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#ldap
Spring Security Ldap 库 (v4.0.4) 是否支持这些?如果是这样,我们是否应该更改任何配置以确保事情不受影响?
spring active-directory spring-security spring-ldap spring-security-ldap