本文整理汇总了Java中org.ldaptive.LdapEntry类的典型用法代码示例。如果您正苦于以下问题:Java LdapEntry类的具体用法?Java LdapEntry怎么用?Java LdapEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LdapEntry类属于org.ldaptive包,在下文中一共展示了LdapEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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));
}
}
示例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);
}
}