本文整理汇总了Java中org.springframework.security.ldap.authentication.BindAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java BindAuthenticator类的具体用法?Java BindAuthenticator怎么用?Java BindAuthenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BindAuthenticator类属于org.springframework.security.ldap.authentication包,在下文中一共展示了BindAuthenticator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJndiSpring
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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: authenticate
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Override
public DirContextOperations authenticate(Authentication authentication) {
//Spring expects an exception on failed authentication
if (authenticators != null && centralConfig.getDescriptor().getSecurity().isLdapEnabled()) {
RuntimeException authenticationException = null;
for (BindAuthenticator authenticator : authenticators.values()) {
DirContextOperations user = null;
try {
user = authenticator.authenticate(authentication);
} catch (RuntimeException e) {
authenticationException = e;
}
if (user != null) {
return user;
}
}
if (authenticationException != null) {
throw authenticationException;
}
throw new AuthenticationServiceException(LDAP_SERVICE_MISCONFIGURED);
} else {
throw new AuthenticationServiceException(NO_LDAP_SERVICE_CONFIGURED);
}
}
示例3: getLdapAuthenticationProviders
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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;
}
示例4: bindAuthenticator
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Bean
public BindAuthenticator bindAuthenticator(FilterBasedLdapUserSearch userSearch){
return new BindAuthenticator(contextSource()){{
setUserSearch(userSearch);
}};
}
示例5: authenticationProvider
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
LdapAuthoritiesPopulator lap,
UserDetailsContextMapper cm){
return new LdapAuthenticationProvider(ba, lap){{
setUserDetailsContextMapper(cm);
}};
}
示例6: authenticate
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
/**
* Tries to authenticate the user. If the authentication fails an appropriate
* {@link AuthenticationException} is thrown
*
* @param username
* the user name of the user to authenticate.
* @param password
* the password
* @param usernameAttribute
* determines whether the username parameter refers to an email address or alias
* @return the VO of the authenticated user
* @throws LdapAttributeMappingException
* in case the result returned from can not be mapped to the the VO
*/
public ExternalUserVO authenticate(String username, String password,
LdapUserAttribute usernameAttribute) throws LdapAttributeMappingException {
LOGGER.debug("Attempting authentication of user {} against LDAP directory", username);
LdapUserAttributesMapper mapper = new LdapUserAttributesMapper(ldapConfig);
LdapContextSource context = LdapSearchUtils.createLdapContext(ldapConfig, mapper);
DirContextOperations ldapDetails;
CommunoteLdapUserSearch search;
// simple authentication via search for user and bind with the found DN
if (ldapConfig.getSaslMode() == null) {
// create ldap search based on the given user attribute and reusing context
search = new CommunoteLdapUserSearch(ldapConfig.getUserSearch(), mapper, context,
usernameAttribute, null, null);
// create Bind authenticator (which first checks with a search whether the user exists
// and than tries to bind with that user and provided pwd)
BindAuthenticator authenticator = new BindAuthenticator(context);
authenticator.setUserSearch(search);
// authenticate with ldap server with username and password
ldapDetails = authenticator.authenticate(new UsernamePasswordAuthenticationToken(
username, password));
} else {
// do search as that user
search = new CommunoteLdapUserSearch(ldapConfig.getUserSearch(), mapper, context,
usernameAttribute, username, password);
ldapDetails = search.searchForUser(username);
}
ExternalUserVO userVO = search.transformResult(ldapDetails);
checkAccountStatus(ldapDetails, username);
// LDAP account status allows logging in thus set user status to active
userVO.setStatus(UserStatus.ACTIVE);
return userVO;
}
示例7: getBindAuthenticator
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
private BindAuthenticator getBindAuthenticator(
FilterBasedLdapUserSearch userSearch,
LdapContextSource ldapContextSource) throws Exception {
BindAuthenticator bindAuthenticator = new BindAuthenticator(
ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
String[] userDnPatterns = new String[] { ldapUserDNPattern };
bindAuthenticator.setUserDnPatterns(userDnPatterns);
bindAuthenticator.afterPropertiesSet();
return bindAuthenticator;
}
示例8: createBindAuthenticators
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
private Map<String, BindAuthenticator> createBindAuthenticators() {
Map<String, BindAuthenticator> result = Maps.newLinkedHashMap();
LdapGroupAddon groupAddon = ContextHelper.get().beanForType(AddonsManager.class).addonByType(
LdapGroupAddon.class);
List<LdapSetting> ldapSettings = groupAddon.getEnabledLdapSettings();
for (LdapSetting ldapSetting : ldapSettings) {
LdapContextSource contextSource = createSecurityContext(ldapSetting);
ArtifactoryBindAuthenticator bindAuthenticator =
new ArtifactoryBindAuthenticator(contextSource, ldapSetting);
result.put(ldapSetting.getKey(), bindAuthenticator);
}
return result;
}
示例9: bindAuthenticator
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Bean
public BindAuthenticator bindAuthenticator() {
BindAuthenticator auth = new BindAuthenticator(contextSource());
if (StringUtils.isNotEmpty(ldapDnPattern)) {
auth.setUserDnPatterns(new String[]{ldapDnPattern});
}
if (StringUtils.isNotEmpty(ldapSearchPattern)) {
auth.setUserSearch(userSearch());
}
return auth;
}
示例10: loadProvider
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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;
}
}
示例11: LDAPAuthenticator
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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;
}
}
}
示例12: ldapAuthenticator
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Bean
public LdapAuthenticator ldapAuthenticator() {
BindAuthenticator authenticator = new BindAuthenticator(ldapContextSource());
authenticator.setUserAttributes(new String[] {ldapUserIdAttr});
if (!"".equals(ldapSearchFilter)) {
logger.debug("ldapSearch: {} {}", ldapSearchBase, ldapSearchFilter);
authenticator.setUserSearch(new FilterBasedLdapUserSearch(ldapSearchBase, ldapSearchFilter, ldapContextSource()));
} else {
logger.debug("ldapUserDn: {}", ldapUserDn);
authenticator.setUserDnPatterns(new String[] {ldapUserDn});
}
return authenticator;
}
示例13: authenticationProvider
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的package包/类
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
LdapAuthoritiesPopulator lap){
return new LdapAuthenticationProvider(ba, lap);
}
示例14: getADBindAuthentication
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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;
}
}
示例15: getLdapBindAuthentication
import org.springframework.security.ldap.authentication.BindAuthenticator; //导入依赖的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;
}