本文整理汇总了Java中org.springframework.security.ldap.DefaultSpringSecurityContextSource类的典型用法代码示例。如果您正苦于以下问题:Java DefaultSpringSecurityContextSource类的具体用法?Java DefaultSpringSecurityContextSource怎么用?Java DefaultSpringSecurityContextSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultSpringSecurityContextSource类属于org.springframework.security.ldap包,在下文中一共展示了DefaultSpringSecurityContextSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: init
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
public void init() throws Exception {
if (!useLdapAuth()) {
return;
}
LdapContextSource contextSource = new DefaultSpringSecurityContextSource(ldapHost);
contextSource.setUserDn(ldapUsername);
contextSource.setPassword(ldapPassword);
contextSource.afterPropertiesSet();
DefaultLdapAuthoritiesPopulator ldapAuthoritiesPopulator =
new DefaultLdapAuthoritiesPopulator(contextSource, ldapGroupSearchBase);
ldapAuthoritiesPopulator.setGroupRoleAttribute(ldapGroupRoleAttribute);
ldapAuthoritiesPopulator.setGroupSearchFilter(ldapGroupSearchFilter);
ldapBindAuthenticator = new SimpleBindAunthenticator(contextSource, gizmoGroup);
ldapBindAuthenticator.setUserDnPatterns(new String[]{userDnPattern});
}
示例5: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
/**
* LDAP Server Context
* @return
*/
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(
Arrays.asList("ldap://corp.jbcpcalendar.com/"), "dc=corp,dc=jbcpcalendar,dc=com"){{
setUserDn("CN=Administrator,CN=Users,DC=corp,DC=jbcpcalendar,DC=com");
setPassword("admin123!");
}};
}
示例6: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
/**
* LDAP Server Context
* TODO: Need to get port / URL from properties.
* @return
*/
@Description("Embedded LDAP Context Config")
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(
Arrays.asList("ldap://localhost:" + LDAP_PORT + "/"), "dc=jbcpcalendar,dc=com"){{
setUserDn("[email protected],ou=Administrators");
// setUserDn("uid=admin, ou=system");
// setPassword("secret");
setPassword("admin1");
}};
}
示例7: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
/**
* LDAP Server Context
* @return
*/
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(
Arrays.asList("ldap://localhost:" + LDAP_PORT + "/"),
"dc=jbcpcalendar,dc=com");
}
示例8: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
/**
* LDAP Server Context
* @return
*/
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(
Arrays.asList("ldap://localhost:" + LDAP_PORT + "/"), "dc=jbcpcalendar,dc=com"){{
setUserDn("uid=admin,ou=system");
setPassword("secret");
}};
}
示例9: 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);
}
示例10: getLdapContextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
private LdapContextSource getLdapContextSource() throws Exception {
LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(
ldapURL);
ldapContextSource.setUserDn(ldapBindDN);
ldapContextSource.setPassword(ldapBindPassword);
ldapContextSource.setReferral(ldapReferral);
ldapContextSource.setCacheEnvironmentProperties(false);
ldapContextSource.setAnonymousReadOnly(false);
ldapContextSource.setPooled(true);
ldapContextSource.afterPropertiesSet();
return ldapContextSource;
}
示例11: 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;
}
示例12: 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;
}
}
示例13: 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;
}
}
}
示例14: 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;
}
示例15: contextSource
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; //导入依赖的package包/类
/**
* Provides a {@link org.springframework.security.ldap.DefaultSpringSecurityContextSource} for LDAP authenticaton.
* @return a new {@link org.springframework.security.ldap.DefaultSpringSecurityContextSource} containing the {@code address} and the {@code baseDn} of the LDAP server.
*/
@Bean
public DefaultSpringSecurityContextSource contextSource(){
return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:8389/"),"dc=openfleet,dc=org");
}