本文整理汇总了Java中org.springframework.security.ldap.authentication.LdapAuthenticationProvider类的典型用法代码示例。如果您正苦于以下问题:Java LdapAuthenticationProvider类的具体用法?Java LdapAuthenticationProvider怎么用?Java LdapAuthenticationProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LdapAuthenticationProvider类属于org.springframework.security.ldap.authentication包,在下文中一共展示了LdapAuthenticationProvider类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
private LdapAuthenticationProvider build() throws Exception {
BaseLdapPathContextSource contextSource = getContextSource();
LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource);
LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator();
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProviderProxy(
ldapAuthenticator, authoritiesPopulator);
SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper();
simpleAuthorityMapper.setPrefix(rolePrefix);
simpleAuthorityMapper.afterPropertiesSet();
ldapAuthenticationProvider.setAuthoritiesMapper(simpleAuthorityMapper);
if (userDetailsContextMapper != null) {
ldapAuthenticationProvider
.setUserDetailsContextMapper(userDetailsContextMapper);
}
return ldapAuthenticationProvider;
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:19,代码来源:LdapAuthenticationProviderConfigurer.java
示例2: getLdapAuthenticationProviders
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
/**
* Get the LDAP authentication providers, by iterating over all the bind authenticators and putting them in a map of
* the settings key.
*
* @return The LDAP authentication provers
*/
public Map<String, LdapAuthenticationProvider> getLdapAuthenticationProviders() {
if (ldapAuthenticationProviders == null) {
ldapAuthenticationProviders = new HashMap<>();
Map<String, BindAuthenticator> authMap = authenticator.getAuthenticators();
for (Map.Entry<String, BindAuthenticator> entry : authMap.entrySet()) {
LdapAuthenticationProvider ldapAuthenticationProvider =
new LdapAuthenticationProvider(entry.getValue());
if (messageSource != null) {
ldapAuthenticationProvider.setMessageSource(messageSource);
}
ldapAuthenticationProviders.put(entry.getKey(), ldapAuthenticationProvider);
}
}
return ldapAuthenticationProviders;
}
示例3: authenticationProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
LdapAuthoritiesPopulator lap,
UserDetailsContextMapper cm){
return new LdapAuthenticationProvider(ba, lap){{
setUserDetailsContextMapper(cm);
}};
}
示例4: setMessageSource
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
@Override
public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource;
if (ldapAuthenticationProviders != null) {
for (LdapAuthenticationProvider ldapAuthenticationProvider : ldapAuthenticationProviders.values()) {
ldapAuthenticationProvider.setMessageSource(messageSource);
}
}
}
示例5: supports
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
@Override
public boolean supports(Class<?> authentication) {
if (centralConfig.getDescriptor().getSecurity().isLdapEnabled()) {
for (LdapAuthenticationProvider ldapAuthenticationProvider : getLdapAuthenticationProviders().values()) {
if (ldapAuthenticationProvider.supports(authentication)) {
return true;
}
}
}
return false;
}
示例6: loadProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的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: loadLdapAuthenticationProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
/**
* Reloads LDAP Context Source and depending objects if properties were changed
* @return corresponding LDAP authentication provider
*/
LdapAuthenticationProvider loadLdapAuthenticationProvider() {
if (reloadLdapServerProperties()) {
LOG.info("LDAP Properties changed - rebuilding Context");
LdapContextSource springSecurityContextSource = new LdapContextSource();
List<String> ldapUrls = ldapServerProperties.get().getLdapUrls();
springSecurityContextSource.setUrls(ldapUrls.toArray(new String[ldapUrls.size()]));
springSecurityContextSource.setBase(ldapServerProperties.get().getBaseDN());
if (!ldapServerProperties.get().isAnonymousBind()) {
springSecurityContextSource.setUserDn(ldapServerProperties.get().getManagerDn());
springSecurityContextSource.setPassword(ldapServerProperties.get().getManagerPassword());
}
try {
springSecurityContextSource.afterPropertiesSet();
} catch (Exception e) {
LOG.error("LDAP Context Source not loaded ", e);
throw new UsernameNotFoundException("LDAP Context Source not loaded", e);
}
//TODO change properties
String userSearchBase = ldapServerProperties.get().getUserSearchBase();
String userSearchFilter = ldapServerProperties.get().getUserSearchFilter();
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(userSearchBase, userSearchFilter, springSecurityContextSource);
AmbariLdapBindAuthenticator bindAuthenticator = new AmbariLdapBindAuthenticator(springSecurityContextSource, configuration);
bindAuthenticator.setUserSearch(userSearch);
LdapAuthenticationProvider authenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
providerThreadLocal.set(authenticationProvider);
}
return providerThreadLocal.get();
}
示例8: authenticationProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
LdapAuthoritiesPopulator lap){
return new LdapAuthenticationProvider(ba, lap);
}
示例9: configure
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
@Override
public void configure(B builder) throws Exception {
LdapAuthenticationProvider provider = postProcess(build());
builder.authenticationProvider(provider);
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:6,代码来源:LdapAuthenticationProviderConfigurer.java
示例10: getADBindAuthentication
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
private Authentication getADBindAuthentication (Authentication authentication) {
try {
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(adURL);
ldapContextSource.setUserDn(adBindDN);
ldapContextSource.setPassword(adBindPassword);
ldapContextSource.setReferral(adReferral);
ldapContextSource.setCacheEnvironmentProperties(true);
ldapContextSource.setAnonymousReadOnly(false);
ldapContextSource.setPooled(true);
ldapContextSource.afterPropertiesSet();
if (adUserSearchFilter==null || adUserSearchFilter.trim().isEmpty()) {
adUserSearchFilter="(sAMAccountName={0})";
}
FilterBasedLdapUserSearch userSearch=new FilterBasedLdapUserSearch(adBase, adUserSearchFilter,ldapContextSource);
userSearch.setSearchSubtree(true);
BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
bindAuthenticator.afterPropertiesSet();
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator);
if (userName != null && userPassword != null
&& !userName.trim().isEmpty()
&& !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
final UserDetails principal = new User(userName, userPassword,
grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(
principal, userPassword, grantedAuths);
authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
if (groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication;
} else {
LOG.error("AD Authentication Failed userName or userPassword is null or empty");
return null;
}
} catch (Exception e) {
LOG.error("AD Authentication Failed:", e);
return null;
}
}
示例11: getLdapBindAuthentication
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
private Authentication getLdapBindAuthentication(
Authentication authentication) {
try {
if (isDebugEnabled) {
LOG.debug("==> AtlasLdapAuthenticationProvider getLdapBindAuthentication");
}
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
LdapContextSource ldapContextSource = getLdapContextSource();
DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = getDefaultLdapAuthoritiesPopulator(ldapContextSource);
if (ldapUserSearchFilter == null
|| ldapUserSearchFilter.trim().isEmpty()) {
ldapUserSearchFilter = "(uid={0})";
}
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(
ldapBase, ldapUserSearchFilter, ldapContextSource);
userSearch.setSearchSubtree(true);
BindAuthenticator bindAuthenticator = getBindAuthenticator(
userSearch, ldapContextSource);
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(
bindAuthenticator, defaultLdapAuthoritiesPopulator);
if (userName != null && userPassword != null
&& !userName.trim().isEmpty()
&& !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
final UserDetails principal = new User(userName, userPassword,
grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(
principal, userPassword, grantedAuths);
authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
if(groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication;
} else {
LOG.error("LDAP Authentication::userName or userPassword is null or empty for userName "
+ userName);
}
} catch (Exception e) {
LOG.error(" getLdapBindAuthentication LDAP Authentication Failed:", e);
}
if (isDebugEnabled) {
LOG.debug("<== AtlasLdapAuthenticationProvider getLdapBindAuthentication");
}
return authentication;
}
示例12: getProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
public LdapAuthenticationProvider getProvider() {
return cache.computeIfAbsent(CACHE_KEY, x -> loadProvider());
}
示例13: getProvider
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; //导入依赖的package包/类
LdapAuthenticationProvider getProvider();