• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SpringSecurityLdapTemplate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.ldap.SpringSecurityLdapTemplate的典型用法代码示例。如果您正苦于以下问题:Java SpringSecurityLdapTemplate类的具体用法?Java SpringSecurityLdapTemplate怎么用?Java SpringSecurityLdapTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SpringSecurityLdapTemplate类属于org.springframework.security.ldap包,在下文中一共展示了SpringSecurityLdapTemplate类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: searchForUser

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
/**
 * Return the DirContextOperations containing the user's information
 *
 * @param dn full DN of the user to search for.
 *
 * @return An DirContextOperations object containing the details of the located user's
 * directory entry
 *
 * @throws UsernameNotFoundException if no matching entry is found.
 */
@Override
public DirContextOperations searchForUser(String dn) {
    log.debug("Searching for dn '{}'.", dn);

    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(getContextSource());

    template.setSearchControls(getSearchControls());

    try {
        return template.retrieveEntry(dn, null);
    } catch (IncorrectResultSizeDataAccessException ex) {
        if (ex.getActualSize() == 0) {
            throw new UsernameNotFoundException("User " + dn + " not found in directory.");
        }
        // Search should never return multiple results if properly configured, so just rethrow
        throw ex;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:29,代码来源:LdapFullDnSearch.java


示例2: uid2ext

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
public String uid2ext(String uid) {
 	String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value();
 	if ("uid".equals(externalIdAttribute)) return uid; // Nothing to translate
     try {
     	
ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");

String query = ApplicationProperty.AuthenticationLdapLogin2UserId.value();

SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {externalIdAttribute});

return user == null ? null : user.getStringAttribute(externalIdAttribute);

     } catch (Exception e) {
     	sLog.warn("Unable to translate uid to " + externalIdAttribute + ": " + e.getMessage());
     }
     
     return null;
 }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:21,代码来源:SpringLdapExternalUidTranslation.java


示例3: ext2uid

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
public String ext2uid(String externalUserId) {
 	String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value();
 	if ("uid".equals(externalIdAttribute)) return externalUserId; // Nothing to translate
     try {
     	
     	ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");

String query = ApplicationProperty.AuthenticationLdapUserId2Login.value().replace("%", externalIdAttribute);

SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", externalIdAttribute), new String[] {"uid"});

return user == null ? null : user.getStringAttribute("uid");

     } catch (Exception e) {
     	sLog.warn("Unable to translate " + externalIdAttribute + " to uid: " + e.getMessage());
     }
     return null;
 }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:20,代码来源:SpringLdapExternalUidTranslation.java


示例4: searchForUser

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
private DirContextOperations searchForUser(DirContext context, String username)
		throws NamingException {
	SearchControls searchControls = new SearchControls();
	searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

	String bindPrincipal = createBindPrincipalDomainAlias(username);
	String searchRoot = rootDn != null ? rootDn : searchRootFromPrincipal(bindPrincipal);

	try {
		return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context,
				searchControls, searchRoot, searchFilter,
				new Object[] { bindPrincipal });
	}
	catch (IncorrectResultSizeDataAccessException incorrectResults) {
		// Search should never return multiple results if properly configured - just
		// rethrow
		if (incorrectResults.getActualSize() != 0) {
			throw incorrectResults;
		}
		// If we found no results, then the username/password did not match
		UsernameNotFoundException userNameNotFoundException = new UsernameNotFoundException(
				"User " + username + " not found in directory.", incorrectResults);
		throw badCredentials(userNameNotFoundException);
	}
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:26,代码来源:ActiveDirectoryAliasLdapAuthenticationProvider.java


示例5: searchForUser

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
/**
 * Return the DirContextOperations containing the user's information
 *
 * @param username the kerberos username to search for.
 *
 * @return An DirContextOperations object containing the details of the located user's
 * directory entry
 *
 * @throws UsernameNotFoundException if no matching entry is found.
 */
public DirContextOperations searchForUser(String username) {
    String[] data = username.split("@");
    eq(data.length, 2, () -> new UsernameNotFoundException("Wrong username format for " + username));

    String accountName = data[0];
    String domainName = data[1];

    String[] domainData = domainName.split("\\.");

    String searchBase = Stream.of(domainData)
                              .map(part -> "dc=" + part)
                              .collect(Collectors.joining(","));

    log.debug("Searching for user '{}' in '{}', with user search {}.", accountName, searchBase, this);


    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(getContextSource());

    template.setSearchControls(getSearchControls());

    try {
        return template.searchForSingleEntry(searchBase, getSearchFilter(), new String[] { accountName });

    } catch (IncorrectResultSizeDataAccessException ex) {
        if (ex.getActualSize() == 0) {
            throw new UsernameNotFoundException("User " + username + " not found in directory.");
        }
        // Search should never return multiple results if properly configured, so just rethrow
        throw ex;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:42,代码来源:KerberosFilterBasedLdapUserSearch.java


示例6: doLookup

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
@Override
public UserInfo doLookup(String uid) throws Exception {
	try {
		ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource");
		
		String query = ApplicationProperty.AuthenticationLdapIdentify.value(); 
		String idAttributeName = ApplicationProperty.AuthenticationLdapIdAttribute.value();

		SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source);
		DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {"uid", idAttributeName, "cn", "givenName", "sn", "mail"});

		if (user == null || user.getStringAttribute(idAttributeName) == null)
			return null;
           
       	UserInfo info = new UserInfo();
       	info.setExternalId(user.getStringAttribute(idAttributeName));
       	
       	info.setUserName(user.getStringAttribute("uid"));
       	if (info.getUserName() == null) info.setUserName(uid);
       	info.setName(user.getStringAttribute("cn"));
       	info.setFirstName(user.getStringAttribute("givenName"));
       	info.setLastName(user.getStringAttribute("sn"));
       	info.setEmail(user.getStringAttribute("mail"));

       	if (info.getEmail() == null) {
           	String email = info.getUserName() + "@";
       		for (String x: user.getNameInNamespace().split(","))
       			if (x.startsWith("dc=")) email += (email.endsWith("@") ? "" : ".") + x.substring(3);
           	if (!email.endsWith("@")) info.setEmail(email);
       	}
       	
       	return info;
	} catch (Exception e) {
		sLog.warn("Lookup for " + uid + " failed: " + e.getMessage());
	}

	return null;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:39,代码来源:SpringLdapExternalUidLookup.java


示例7: springSecurityLdapTemplate

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的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);
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:10,代码来源:LdapConfig.java


示例8: searchForUser

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public DirContextOperations searchForUser(String username) {
    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(
            initialDirContextFactory);
    List<LdapSearchBaseDefinition> searchBaseDefs = userSearchConfig.getSearchBases();
    String[] params = { LdapUtils.escapeLdapSearchFilterValue(username) };
    SearchControls searchControls = new SearchControls();
    template.setSearchControls(searchControls);
    searchControls.setReturningAttributes(userAttributesMapper.getMappedLdapAttributeNames());
    for (LdapSearchBaseDefinition searchBase : searchBaseDefs) {
        searchControls
        .setSearchScope(searchBase.isSearchSubtree() ? SearchControls.SUBTREE_SCOPE
                : SearchControls.ONELEVEL_SCOPE);
        try {
            return template.searchForSingleEntry(searchBase.getSearchBase(), userSearchFilter,
                    params);
        } catch (IncorrectResultSizeDataAccessException e) {
            // ignore no results case to allow checking other search bases
            if (e.getActualSize() != 0) {
                // Search should never return multiple results if properly configured, so just
                // rethrow
                throw e;
            }
        }
    }
    throw new UsernameNotFoundException("User " + username + " not found in directory.");
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:31,代码来源:CommunoteLdapUserSearch.java


示例9: CHUserDetailsService

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
@Autowired
public CHUserDetailsService(LdapContextSource contextSource) {
    ldapTemplate = new SpringSecurityLdapTemplate(contextSource);
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ldapTemplate.setSearchControls(searchControls);
}
 
开发者ID:WISVCH,项目名称:connect,代码行数:8,代码来源:CHUserDetailsService.java


示例10: UserGroupLdapAuthoritiesPopulator

import org.springframework.security.ldap.SpringSecurityLdapTemplate; //导入依赖的package包/类
public UserGroupLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) {
	super(contextSource, groupSearchBase);
	this.ldapTemplate = new SpringSecurityLdapTemplate(contextSource);
	this.ldapTemplate.setSearchControls(searchControls);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:6,代码来源:UserGroupLdapAuthoritiesPopulator.java



注:本文中的org.springframework.security.ldap.SpringSecurityLdapTemplate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ResourceBlacklistRequestProto类代码示例发布时间:2022-05-22
下一篇:
Java RandomAdaptor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap