本文整理汇总了Java中org.ldaptive.LdapEntry类的典型用法代码示例。如果您正苦于以下问题:Java LdapEntry类的具体用法?Java LdapEntry怎么用?Java LdapEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LdapEntry类属于org.ldaptive包,在下文中一共展示了LdapEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createProfile
import org.ldaptive.LdapEntry; //导入依赖的package包/类
protected LdapProfile createProfile(final String username, final String[] ldapAttributes, final LdapEntry entry) {
final LdapProfile profile = new LdapProfile();
profile.setId(username);
for (String ldapAttribute: ldapAttributes) {
final LdapAttribute entryAttribute = entry.getAttribute(ldapAttribute);
if (entryAttribute != null) {
logger.debug("Found attribute: {}", ldapAttribute);
if (entryAttribute.size() > 1) {
profile.addAttribute(ldapAttribute, entryAttribute.getStringValues());
} else {
profile.addAttribute(ldapAttribute, entryAttribute.getStringValue());
}
}
}
return profile;
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:17,代码来源:LdapAuthenticator.java
示例2: readLdif
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Reads an LDIF into a collection of LDAP entries. The components performs a simple property
* replacement in the LDIF data where <pre>${ldapBaseDn}</pre> is replaced with the environment-specific base
* DN.
*
* @param ldif LDIF resource, typically a file on filesystem or classpath.
* @param baseDn The directory branch where the entry resides.
*
* @return LDAP entries contained in the LDIF.
*
* @throws IOException On IO errors reading LDIF.
*/
public static Collection<LdapEntry> readLdif(final InputStream ldif, final String baseDn) throws IOException {
final StringBuilder builder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(ldif))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(BASE_DN_PLACEHOLDER)) {
builder.append(line.replace(BASE_DN_PLACEHOLDER, baseDn));
} else {
builder.append(line);
}
builder.append(NEWLINE);
}
}
return new LdifReader(new StringReader(builder.toString())).read().getEntries();
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:LdapTestUtils.java
示例3: getString
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Reads a String value from the LdapEntry.
*
* @param entry the ldap entry
* @param attribute the attribute name
* @param nullValue the value which should be returning in case of a null value
* @return the string
*/
public static String getString(final LdapEntry entry, final String attribute, final String nullValue) {
final LdapAttribute attr = entry.getAttribute(attribute);
if (attr == null) {
return nullValue;
}
final String v;
if (attr.isBinary()) {
final byte[] b = attr.getBinaryValue();
v = new String(b, Charset.forName("UTF-8"));
} else {
v = attr.getStringValue();
}
if (StringUtils.isNotBlank(v)) {
return v;
}
return nullValue;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:LdapUtils.java
示例4: update
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Update the ldap entry with the given registered service.
*
* @param rs the rs
* @return the registered service
*/
private RegisteredService update(final RegisteredService rs) {
String currentDn = null;
if (ldapServiceMapper == null) {
return null;
}
try {
final Response<SearchResult> response = searchForServiceById(rs.getId());
if (LdapUtils.containsResultEntry(response)) {
currentDn = response.getResult().getEntry().getDn();
}
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
if (StringUtils.isNotBlank(currentDn)) {
logger.debug("Updating registered service at {}", currentDn);
final LdapEntry entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
LdapUtils.executeModifyOperation(currentDn, this.connectionFactory, entry);
}
return rs;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:31,代码来源:LdapServiceRegistryDao.java
示例5: mapFromRegisteredService
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public LdapEntry mapFromRegisteredService(final String dn, final RegisteredService svc) {
try {
if (svc.getId() == RegisteredService.INITIAL_IDENTIFIER_VALUE) {
((AbstractRegisteredService) svc).setId(System.nanoTime());
}
final String newDn = getDnForRegisteredService(dn, svc);
LOGGER.debug("Creating entry {}", newDn);
final Collection<LdapAttribute> attrs = new ArrayList<>();
attrs.add(new LdapAttribute(this.idAttribute, String.valueOf(svc.getId())));
final StringWriter writer = new StringWriter();
this.jsonSerializer.toJson(writer, svc);
attrs.add(new LdapAttribute(this.serviceDefinitionAttribute, writer.toString()));
attrs.add(new LdapAttribute(LdapUtils.OBJECTCLASS_ATTRIBUTE, "top", this.objectClass));
return new LdapEntry(newDn, attrs);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:23,代码来源:DefaultLdapRegisteredServiceMapper.java
示例6: load
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
final List<RegisteredService> list = new LinkedList<>();
if (ldapServiceMapper == null) {
return list;
}
try {
final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory,
this.baseDn, new SearchFilter(this.loadFilter));
if (LdapUtils.containsResultEntry(response)) {
for (final LdapEntry entry : response.getResult().getEntries()) {
final RegisteredService svc = this.ldapServiceMapper.mapToRegisteredService(entry);
list.add(svc);
}
}
} catch (final LdapException e) {
logger.error(e.getMessage(), e);
}
return list;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:LdapServiceRegistryDao.java
示例7: testAuthenticateNotFound
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Test
public void testAuthenticateNotFound() throws Exception {
if (!this.supportsNotFound) {
return;
}
String username;
for (final LdapEntry entry : this.testEntries) {
username = getUsername(entry);
try {
this.handler.authenticate(new UsernamePasswordCredential("nobody", "badpassword"));
fail("Should have thrown AccountNotFoundException.");
} catch (final AccountNotFoundException e) {
assertNotNull(e.getMessage());
}
}
}
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:LdapAuthenticationHandlerTests.java
示例8: load
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
final List<RegisteredService> list = new LinkedList<>();
if (ldapServiceMapper == null) {
return list;
}
try (final Connection connection = getConnection()) {
final Response<SearchResult> response =
executeSearchOperation(connection, new SearchFilter(this.loadFilter));
if (hasResults(response)) {
for (final LdapEntry entry : response.getResult().getEntries()) {
final RegisteredService svc = this.ldapServiceMapper.mapToRegisteredService(entry);
list.add(svc);
}
}
} catch (final LdapException e) {
logger.error(e.getMessage(), e);
}
return list;
}
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:22,代码来源:LdapServiceRegistryDao.java
示例9: getString
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Reads a String value from the LdapEntry.
*
* @param entry the ldap entry
* @param attribute the attribute name
* @param nullValue the value which should be returning in case of a null value
* @return the string
*/
public static String getString(final LdapEntry entry, final String attribute, final String nullValue) {
final LdapAttribute attr = entry.getAttribute(attribute);
if (attr == null) {
return nullValue;
}
String v = null;
if (attr.isBinary()) {
final byte[] b = attr.getBinaryValue();
v = new String(b, Charset.forName("UTF-8"));
} else {
v = attr.getStringValue();
}
if (StringUtils.isNotBlank(v)) {
return v;
}
return nullValue;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:LdapUtils.java
示例10: load
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
Connection connection = null;
final List<RegisteredService> list = new LinkedList<>();
try {
connection = getConnection();
final Response<SearchResult> response =
executeSearchOperation(connection, new SearchFilter(this.loadFilter));
if (hasResults(response)) {
for (final LdapEntry entry : response.getResult().getEntries()) {
final RegisteredService svc = this.ldapServiceMapper.mapToRegisteredService(entry);
list.add(svc);
}
}
} catch (final LdapException e) {
logger.error(e.getMessage(), e);
} finally {
LdapUtils.closeConnection(connection);
}
return list;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:LdapServiceRegistryDao.java
示例11: verifyAuthenticateSuccess
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Test
public void verifyAuthenticateSuccess() throws Exception {
for (final LdapEntry entry : this.getEntries()) {
final String username = getUsername(entry);
final String psw = entry.getAttribute("userPassword").getStringValue();
final HandlerResult result = this.handler.authenticate(
new UsernamePasswordCredential(username, psw));
assertNotNull(result.getPrincipal());
assertEquals(username, result.getPrincipal().getId());
assertEquals(
entry.getAttribute("displayName").getStringValue(),
result.getPrincipal().getAttributes().get("displayName"));
assertEquals(
entry.getAttribute("mail").getStringValue(),
result.getPrincipal().getAttributes().get("mail"));
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:LdapAuthenticationHandlerTests.java
示例12: load
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
Connection connection = null;
final List<RegisteredService> list = new LinkedList<RegisteredService>();
try {
connection = this.connectionFactory.getConnection();
final Response<SearchResult> response =
executeSearchOperation(connection, new SearchFilter(this.loadFilter));
if (hasResults(response)) {
for (final LdapEntry entry : response.getResult().getEntries()) {
final RegisteredService svc = this.ldapServiceMapper.mapToRegisteredService(entry);
list.add(svc);
}
}
} catch (final LdapException e) {
logger.error(e.getMessage(), e);
} finally {
LdapUtils.closeConnection(connection);
}
return list;
}
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:22,代码来源:LdapServiceRegistryDao.java
示例13: readLdif
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Reads an LDIF into a collection of LDAP entries. The components performs a simple property
* replacement in the LDIF data where <pre>${ldapBaseDn}</pre> is replaced with the environment-specific base
* DN.
*
* @param ldif LDIF resource, typically a file on filesystem or classpath.
* @param baseDn The directory branch where the entry resides.
*
* @return LDAP entries contained in the LDIF.
*
* @throws IOException On IO errors reading LDIF.
*/
public static Collection<LdapEntry> readLdif(final InputStream ldif, final String baseDn) throws IOException {
final StringBuilder builder = new StringBuilder();
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(ldif))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(BASE_DN_PLACEHOLDER)) {
builder.append(line.replace(BASE_DN_PLACEHOLDER, baseDn));
} else {
builder.append(line);
}
builder.append(NEWLINE);
}
}
return new LdifReader(new StringReader(builder.toString())).read().getEntries();
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:LdapTestUtils.java
示例14: createLdapEntries
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Creates the given LDAP entries.
*
* @param connection Open LDAP connection used to connect to directory.
* @param entries Collection of LDAP entries.
*
* @throws Exception On LDAP errors.
*/
public static void createLdapEntries(final LDAPConnection connection, final Collection<LdapEntry> entries) throws Exception {
for (final LdapEntry entry : entries) {
final Collection<Attribute> attrs = new ArrayList<>(entry.getAttributeNames().length);
for (final LdapAttribute a : entry.getAttributes()) {
attrs.add(new Attribute(a.getName(), a.getStringValues()));
}
connection.add(new AddRequest(entry.getDn(), attrs));
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:LdapTestUtils.java
示例15: fetchCRLFromLdap
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Downloads a CRL from given LDAP url.
*
* @param r the resource that is the ldap url.
* @return the x 509 cRL
* @throws Exception if connection to ldap fails, or attribute to get the revocation list is unavailable
*/
protected X509CRL fetchCRLFromLdap(final Object r) throws Exception {
try {
final String ldapURL = r.toString();
logger.debug("Fetching CRL from ldap {}", ldapURL);
final Response<SearchResult> result = performLdapSearch(ldapURL);
if (result.getResultCode() == ResultCode.SUCCESS) {
final LdapEntry entry = result.getResult().getEntry();
final LdapAttribute attribute = entry.getAttribute();
logger.debug("Located entry [{}]. Retrieving first attribute [{}]",
entry, attribute);
return fetchX509CRLFromAttribute(attribute);
} else {
logger.debug("Failed to execute the search [{}]", result);
}
throw new CertificateException("Failed to establish a connection ldap and search.");
} catch (final LdapException e) {
logger.error(e.getMessage(), e);
throw new CertificateException(e);
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:32,代码来源:LdaptiveResourceCRLFetcher.java
示例16: getString
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Reads a String value from the LdapEntry.
*
* @param entry the ldap entry
* @param attribute the attribute name
* @param nullValue the value which should be returning in case of a null value
* @return the string
*/
public static String getString(final LdapEntry entry, final String attribute, final String nullValue) {
final LdapAttribute attr = entry.getAttribute(attribute);
if (attr == null) {
return nullValue;
}
final String v;
if (attr.isBinary()) {
final byte[] b = attr.getBinaryValue();
v = new String(b, StandardCharsets.UTF_8);
} else {
v = attr.getStringValue();
}
if (StringUtils.isNotBlank(v)) {
return v;
}
return nullValue;
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:LdapUtils.java
示例17: update
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Update the ldap entry with the given registered service.
*
* @param rs the rs
* @return the registered service
*/
private RegisteredService update(final RegisteredService rs) {
String currentDn = null;
try {
final Response<SearchResult> response = searchForServiceById(rs.getId());
if (LdapUtils.containsResultEntry(response)) {
currentDn = response.getResult().getEntry().getDn();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
if (StringUtils.isNotBlank(currentDn)) {
LOGGER.debug("Updating registered service at [{}]", currentDn);
final LdapEntry entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
LdapUtils.executeModifyOperation(currentDn, this.connectionFactory, entry);
}
return rs;
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:LdapServiceRegistryDao.java
示例18: mapFromRegisteredService
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public LdapEntry mapFromRegisteredService(final String dn, final RegisteredService svc) {
try {
if (svc.getId() == RegisteredService.INITIAL_IDENTIFIER_VALUE) {
((AbstractRegisteredService) svc).setId(System.currentTimeMillis());
}
final String newDn = getDnForRegisteredService(dn, svc);
LOGGER.debug("Creating entry [{}]", newDn);
final Collection<LdapAttribute> attrs = new ArrayList<>();
attrs.add(new LdapAttribute(ldap.getIdAttribute(), String.valueOf(svc.getId())));
final StringWriter writer = new StringWriter();
this.jsonSerializer.to(writer, svc);
attrs.add(new LdapAttribute(ldap.getServiceDefinitionAttribute(), writer.toString()));
attrs.add(new LdapAttribute(LdapUtils.OBJECTCLASS_ATTRIBUTE, "top", ldap.getObjectClass()));
return new LdapEntry(newDn, attrs);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:DefaultLdapRegisteredServiceMapper.java
示例19: getGraphics
import org.ldaptive.LdapEntry; //导入依赖的package包/类
@Override
public ByteSource getGraphics(final String username) {
try {
final GraphicalUserAuthenticationProperties gua = casProperties.getAuthn().getGua();
final Response<SearchResult> response = searchForId(username);
if (LdapUtils.containsResultEntry(response)) {
final LdapEntry entry = response.getResult().getEntry();
final LdapAttribute attribute = entry.getAttribute(gua.getLdap().getImageAttribute());
if (attribute != null && attribute.isBinary()) {
return ByteSource.wrap(attribute.getBinaryValue());
}
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return ByteSource.empty();
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:LdapUserGraphicalAuthenticationRepository.java
示例20: populateCertificateRevocationListAttribute
import org.ldaptive.LdapEntry; //导入依赖的package包/类
/**
* Populate certificate revocation list attribute.
* Dynamically set the attribute value to the crl content.
* Encode it as base64 first. Doing this in the code rather
* than in the ldif file to ensure the attribute can be populated
* without dependencies on the classpath and or filesystem.
* @throws Exception the exception
*/
private static void populateCertificateRevocationListAttribute() throws Exception {
final Collection<LdapEntry> col = getDirectory().getLdapEntries();
for (final LdapEntry ldapEntry : col) {
if (ldapEntry.getDn().equals(DN)) {
final LdapAttribute attr = new LdapAttribute(true);
byte[] value = new byte[1024];
IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
value = EncodingUtils.encodeBase64ToByteArray(value);
attr.setName("certificateRevocationList");
attr.addBinaryValue(value);
LdapTestUtils.modifyLdapEntry(getDirectory().getConnection(), ldapEntry, attr);
}
}
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:AbstractX509LdapTests.java
注:本文中的org.ldaptive.LdapEntry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论