本文整理汇总了Java中org.springframework.security.ldap.DefaultSpringSecurityContextSource.setUserDn方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultSpringSecurityContextSource.setUserDn方法的具体用法?Java DefaultSpringSecurityContextSource.setUserDn怎么用?Java DefaultSpringSecurityContextSource.setUserDn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.ldap.DefaultSpringSecurityContextSource
的用法示例。
在下文中一共展示了DefaultSpringSecurityContextSource.setUserDn方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJndiSpring
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Test
public void testJndiSpring() throws Exception {
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
"ldap://ldap.xxx:389/OU=xxx");
ctxSrc.setUserDn(USER_LDAP);
ctxSrc.setPassword(PASSWORD_LDAP);
ctxSrc.afterPropertiesSet();
logger.info("Base LDAP Path: " + ctxSrc.getBaseLdapPath());
logger.info("Principal: "
+ ctxSrc.getAuthenticationSource().getPrincipal().toString());
logger.info("Credentials: "
+ ctxSrc.getAuthenticationSource().getCredentials());
Authentication bob = new UsernamePasswordAuthenticationToken("bob",
"bob");
BindAuthenticator authenticator = new BindAuthenticator(ctxSrc);
authenticator.setUserSearch(new FilterBasedLdapUserSearch("",
"(&(objectCategory=Person)(sAMAccountName={0}))", ctxSrc));
authenticator.afterPropertiesSet();
authenticator.authenticate(bob);
DirContextOperations user = authenticator.authenticate(bob);
logger.info("User: {}", user);
}
示例2: build
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
private DefaultSpringSecurityContextSource build() throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
getProviderUrl());
if (managerDn != null) {
contextSource.setUserDn(managerDn);
if (managerPassword == null) {
throw new IllegalStateException(
"managerPassword is required if managerDn is supplied");
}
contextSource.setPassword(managerPassword);
}
contextSource = postProcess(contextSource);
if (url != null) {
return contextSource;
}
ApacheDSContainer apacheDsContainer = new ApacheDSContainer(root, ldif);
apacheDsContainer.setPort(getPort());
postProcess(apacheDsContainer);
return contextSource;
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:21,代码来源:LdapAuthenticationProviderConfigurer.java
示例3: build
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
private DefaultSpringSecurityContextSource build() throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
getProviderUrl());
if (managerDn != null) {
contextSource.setUserDn(managerDn);
if (managerPassword == null) {
throw new IllegalStateException(
"managerPassword is required if managerDn is supplied");
}
contextSource.setPassword(managerPassword);
}
// contextSource = postProcess(contextSource);
if (url != null) {
return contextSource;
}
ApacheDSContainer embeddedApacheContainer = new ApacheDSContainer(root, ldif);
embeddedApacheContainer.setPort(getPort());
apacheDsContainer = embeddedApacheContainer;
// postProcess(apacheDsContainer);
return contextSource;
}
示例4: springSecurityLdapTemplate
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Bean
SpringSecurityLdapTemplate springSecurityLdapTemplate() throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(configProps.url);
contextSource.setUserDn(configProps.managerDn);
contextSource.setPassword(configProps.managerPassword);
contextSource.afterPropertiesSet();
return new SpringSecurityLdapTemplate(contextSource);
}
示例5: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Bean
public LdapContextSource contextSource() {
DefaultSpringSecurityContextSource ctx = new DefaultSpringSecurityContextSource(ldapHost);
ctx.setUserDn(ldapUserDn);
ctx.setPassword(ldapUserPassword);
return ctx;
}
示例6: loadProvider
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
private LdapAuthenticationProvider loadProvider() {
LDAPSettings settings = cachedSettingsService.getCachedSettings(LDAPSettings.class);
if (settings.isEnabled()) {
// LDAP context
DefaultSpringSecurityContextSource ldapContextSource = new DefaultSpringSecurityContextSource(settings.getUrl());
ldapContextSource.setUserDn(settings.getUser());
ldapContextSource.setPassword(settings.getPassword());
try {
ldapContextSource.afterPropertiesSet();
} catch (Exception e) {
throw new CannotInitializeLDAPException(e);
}
// User search
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(
settings.getSearchBase(),
settings.getSearchFilter(),
ldapContextSource);
userSearch.setSearchSubtree(true);
// Bind authenticator
BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
// Provider
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
ldapAuthenticationProvider.setUserDetailsContextMapper(new ConfigurableUserDetailsContextMapper(settings));
// OK
return ldapAuthenticationProvider;
}
// LDAP not enabled
else {
return null;
}
}
示例7: LDAPAuthenticator
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
/**
* Default constructor.
* @param ldapSettings LDAP config map for an app
*/
public LDAPAuthenticator(Map<String, String> ldapSettings) {
if (ldapSettings != null && ldapSettings.containsKey("security.ldap.server_url")) {
String serverUrl = ldapSettings.get("security.ldap.server_url");
String baseDN = ldapSettings.get("security.ldap.base_dn");
String bindDN = ldapSettings.get("security.ldap.bind_dn");
String basePass = ldapSettings.get("security.ldap.bind_pass");
String searchBase = ldapSettings.get("security.ldap.user_search_base");
String searchFilter = ldapSettings.get("security.ldap.user_search_filter");
String dnPattern = ldapSettings.get("security.ldap.user_dn_pattern");
String passAttribute = ldapSettings.get("security.ldap.password_attribute");
boolean usePasswordComparison = ldapSettings.containsKey("security.ldap.compare_passwords");
DefaultSpringSecurityContextSource contextSource =
new DefaultSpringSecurityContextSource(Arrays.asList(serverUrl), baseDN);
contextSource.setAuthenticationSource(new SpringSecurityAuthenticationSource());
contextSource.setCacheEnvironmentProperties(false);
if (!bindDN.isEmpty()) {
contextSource.setUserDn(bindDN);
}
if (!basePass.isEmpty()) {
contextSource.setPassword(basePass);
}
LdapUserSearch userSearch = new FilterBasedLdapUserSearch(searchBase, searchFilter, contextSource);
if (usePasswordComparison) {
PasswordComparisonAuthenticator p = new PasswordComparisonAuthenticator(contextSource);
p.setPasswordAttributeName(passAttribute);
p.setPasswordEncoder(new LdapShaPasswordEncoder());
p.setUserDnPatterns(new String[]{dnPattern});
p.setUserSearch(userSearch);
authenticator = p;
} else {
BindAuthenticator b = new BindAuthenticator(contextSource);
b.setUserDnPatterns(new String[]{dnPattern});
b.setUserSearch(userSearch);
authenticator = b;
}
}
}
示例8: ldapContextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Bean
public LdapContextSource ldapContextSource() {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(ldapUrl);
/* TODO: implement support for LDAP bind using manager credentials */
if (!"".equals(ldapManagerUserDn) && !"".equals(ldapManagerPassword)) {
logger.debug("ldapManagerUserDn: {}", ldapManagerUserDn);
contextSource.setUserDn(ldapManagerUserDn);
contextSource.setPassword(ldapManagerPassword);
}
return contextSource;
}
示例9: configureAuthenticationManagerBuilder
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Override
public void configureAuthenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception {
LDAPProviderConfig[] configs = LDAPProviderConfig.loadAll(environment);
for (LDAPProviderConfig cfg: configs) {
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> configurer = new LdapAuthenticationProviderConfigurer<>();
String[] userDnPatterns = { cfg.userDnPattern };
if (userDnPatterns[0] == null || userDnPatterns[0].isEmpty()) userDnPatterns = new String[0];
if (cfg.managerDn != null && cfg.managerDn.isEmpty()) cfg.managerDn = null;
// Manually instantiate contextSource so it can be passed into authoritiesPopulator below.
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(cfg.url);
if (cfg.managerDn != null) {
contextSource.setUserDn(cfg.managerDn);
contextSource.setPassword(cfg.managerPassword);
}
if (Boolean.valueOf(cfg.startTLS) || STARTTLS_SIMPLE.equalsIgnoreCase(cfg.startTLS)) {
// Explicitly disable connection pooling, or Spring may attempt to StartTLS twice on the same connection.
contextSource.setPooled(false);
contextSource.setAuthenticationStrategy(new DefaultTlsDirContextAuthenticationStrategy());
} else if (STARTTLS_EXTERNAL.equalsIgnoreCase(cfg.startTLS)) {
contextSource.setAuthenticationStrategy(new ExternalTlsDirContextAuthenticationStrategy());
}
contextSource.afterPropertiesSet();
// Manually instantiate authoritiesPopulator because it uses a customized class.
CNLdapAuthoritiesPopulator authoritiesPopulator = new CNLdapAuthoritiesPopulator(contextSource, cfg.groupSearchBase);
authoritiesPopulator.setGroupRoleAttribute("cn");
authoritiesPopulator.setGroupSearchFilter(cfg.groupSearchFilter);
configurer
.userDnPatterns(userDnPatterns)
.userSearchBase(cfg.userSearchBase)
.userSearchFilter(cfg.userSearchFilter)
.ldapAuthoritiesPopulator(authoritiesPopulator)
.contextSource(contextSource)
.configure(auth);
}
}
示例10: configure
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
@Override
public SecurityConfigurer configure() throws Exception {
LOGGER.info("Configuring an LDAP Identity Provider");
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer =
new LdapAuthenticationProviderConfigurer<>();
// Create LDAP context
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
environment.getProperty("context-source-url"));
contextSource.setBase(environment.getProperty("context-source-base"));
contextSource.setUserDn(environment.getProperty("context-source-username"));
contextSource.setPassword(environment.getProperty("context-source-password"));
contextSource.afterPropertiesSet();
String userDNPattern = environment.getProperty("user-dn-pattern");
if (userDNPattern == null || userDNPattern.isEmpty()) {
ldapAuthenticationProviderConfigurer
.userSearchBase(environment.getProperty("user-search-base"))
.userSearchFilter(environment.getProperty("user-search-filter"));
} else {
ldapAuthenticationProviderConfigurer.userDnPatterns(userDNPattern);
}
ldapAuthenticationProviderConfigurer
.groupSearchBase(environment.getProperty("group-search-base", ""))
.groupSearchFilter(environment.getProperty("group-search-filter", "(uniqueMember={0})"))
.groupRoleAttribute(environment.getProperty("group-role-attribute", "cn"))
.rolePrefix("");
DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(contextSource,
environment.getProperty("group-search-base", ""));
populator.setRolePrefix("");
ldapAuthenticationProviderConfigurer.ldapAuthoritiesPopulator(populator).contextSource(contextSource);
// set up LDAP mapper
UserDetailsContextPropertiesMapper userDetailsContextPropertiesMapper = new UserDetailsContextPropertiesMapper();
userDetailsContextPropertiesMapper.setEnvironment(environment);
userDetailsContextPropertiesMapper.afterPropertiesSet();
ldapAuthenticationProviderConfigurer.userDetailsContextMapper(userDetailsContextPropertiesMapper);
return ldapAuthenticationProviderConfigurer;
}
示例11: createSecurityContext
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入方法依赖的package包/类
static LdapContextSource createSecurityContext(LdapSetting ldapSetting) {
String url = ldapSetting.getLdapUrl();
String scheme = getLdapScheme(url);
String baseUrl = getLdapBaseUrl(scheme, url);
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(scheme + baseUrl);
contextSource.setBase(adjustBase(url.substring((scheme + baseUrl).length())));
// set default connection timeout, read timeout and referral strategy.
HashMap<String, String> env = new HashMap<>();
String connectTimeout = ArtifactoryHome.get().getArtifactoryProperties().getProperty(
"artifactory.security.ldap.connect.timeoutMillis", "10000");
env.put("com.sun.jndi.ldap.connect.timeout",connectTimeout);
String readTimeout = ArtifactoryHome.get().getArtifactoryProperties().getProperty(
"artifactory.security.ldap.socket.timeoutMillis", "15000");
env.put("com.sun.jndi.ldap.read.timeout", readTimeout);
String referralStrategy = ArtifactoryHome.get().getArtifactoryProperties().getProperty(
"artifactory.security.ldap.referralStrategy", "follow");
env.put(Context.REFERRAL, referralStrategy);
String poolIdleTimeout = ArtifactoryHome.get().getArtifactoryProperties().getProperty(
"artifactory.security.ldap.pool.timeoutMillis", null);
if (poolIdleTimeout != null) {
env.put("com.sun.jndi.ldap.connect.pool.timeout", poolIdleTimeout);
}
contextSource.setBaseEnvironmentProperties(env);
SearchPattern searchPattern = ldapSetting.getSearch();
if (searchPattern != null) {
if (PathUtils.hasText(searchPattern.getManagerDn())) {
contextSource.setUserDn(searchPattern.getManagerDn());
contextSource.setPassword(CryptoHelper.decryptIfNeeded(searchPattern.getManagerPassword()));
} else {
contextSource.setAnonymousReadOnly(true);
}
}
try {
contextSource.afterPropertiesSet();
} catch (Exception e) {
throw new RuntimeException(e);
}
return contextSource;
}