当前位置: 首页>>代码示例>>Java>>正文


Java LdapAttribute类代码示例

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


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

示例1: modifyLdapEntry

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
/**
 * Modify ldap entry.
 *
 * @param serverCon the server con
 * @param dn        the dn
 * @param attr      the attr
 * @param add       the add
 */
public static void modifyLdapEntry(final LDAPConnection serverCon, final String dn, final LdapAttribute attr,
                                   final AttributeModificationType add) {
    try {
        final String address = "ldap://" + serverCon.getConnectedAddress() + ':' + serverCon.getConnectedPort();
        try (Connection conn = DefaultConnectionFactory.getConnection(address)) {
            try {
                conn.open();
                final ModifyOperation modify = new ModifyOperation(conn);
                modify.execute(new ModifyRequest(dn, new AttributeModification(add, attr)));
            } catch (final Exception e) {
                LOGGER.debug(e.getMessage(), e);
            }
        }
    } finally {
        serverCon.close();
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:LdapTestUtils.java

示例2: getString

import org.ldaptive.LdapAttribute; //导入依赖的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

示例3: executeModifyOperation

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
/**
 * Execute modify operation boolean.
 *
 * @param currentDn         the current dn
 * @param connectionFactory the connection factory
 * @param attributes        the attributes
 * @return the boolean
 */
public static boolean executeModifyOperation(final String currentDn,
                                             final ConnectionFactory connectionFactory,
                                             final Map<String, Set<String>> attributes) {
    try (Connection modifyConnection = createConnection(connectionFactory)) {
        final ModifyOperation operation = new ModifyOperation(modifyConnection);
        final List<AttributeModification> mods = new ArrayList<>();
        for (final Map.Entry<String, Set<String>> entry : attributes.entrySet()) {
            mods.add(new AttributeModification(AttributeModificationType.REPLACE,
                    new LdapAttribute(entry.getKey(), entry.getValue().toArray(new String[]{}))));
        }
        final ModifyRequest request = new ModifyRequest(currentDn,
                mods.toArray(new AttributeModification[]{}));
        request.setReferralHandler(new ModifyReferralHandler());
        operation.execute(request);
        return true;
    } catch (final LdapException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:29,代码来源:LdapUtils.java

示例4: mapFromRegisteredService

import org.ldaptive.LdapAttribute; //导入依赖的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:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:DefaultLdapRegisteredServiceMapper.java

示例5: fetchCRLFromLdap

import org.ldaptive.LdapAttribute; //导入依赖的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

示例6: fetchX509CRLFromAttribute

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
/**
 * Gets x509 cRL from attribute. Retrieves the binary attribute value,
 * decodes it to base64, and fetches it as a byte-array resource.
 *
 * @param aval the attribute, which may be null if it's not found
 * @return the x 509 cRL from attribute
 * @throws Exception if attribute not found or could could not be decoded.
 */
protected X509CRL fetchX509CRLFromAttribute(final LdapAttribute aval) throws Exception {
    if (aval != null) {
        final byte[] val = aval.getBinaryValue();
        if (val == null || val.length == 0) {
            throw new CertificateException("Empty attribute. Can not download CRL from ldap");
        }
        final byte[] decoded64 = CompressionUtils.decodeBase64ToByteArray(val);
        if (decoded64 == null) {
            throw new CertificateException("Could not decode the attribute value to base64");
        }
        logger.debug("Retrieved CRL from ldap as byte array decoded in base64. Fetching...");
        return super.fetch(new ByteArrayResource(decoded64));
    }
    throw new CertificateException("Attribute not found. Can not retrieve CRL");
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:LdaptiveResourceCRLFetcher.java

示例7: handleWarning

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
@Override
protected void handleWarning(
        final AccountState.Warning warning,
        final AuthenticationResponse response,
        final LdapPasswordPolicyConfiguration configuration,
        final List<MessageDescriptor> messages) {

    final LdapAttribute attribute = response.getLdapEntry().getAttribute(this.warningAttributeName);
    boolean matches = false;
    if (attribute != null) {
        logger.debug("Found warning attribute {} with value {}", attribute.getName(), attribute.getStringValue());
        matches = this.warningAttributeValue.equals(attribute.getStringValue());
    }
    logger.debug("matches={}, displayWarningOnMatch={}", matches, displayWarningOnMatch);
    if (displayWarningOnMatch == matches) {
        super.handleWarning(warning, response, configuration, messages);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:OptionalWarningAccountStateHandler.java

示例8: getString

import org.ldaptive.LdapAttribute; //导入依赖的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

示例9: createLdapEntries

import org.ldaptive.LdapAttribute; //导入依赖的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

示例10: generateAuthorizationForLdapEntry

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
@Override
protected CommonProfile generateAuthorizationForLdapEntry(final CommonProfile profile, final LdapEntry userEntry) {
    try {
        LOGGER.debug("Attempting to get roles for user [{}].", userEntry.getDn());
        final Response<SearchResult> response = this.groupSearchExecutor.search(
                this.connectionFactory,
                Beans.newLdaptiveSearchFilter(this.groupSearchExecutor.getSearchFilter().getFilter(),
                        Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(userEntry.getDn())));
        LOGGER.debug("LDAP role search response: [{}]", response);
        final SearchResult groupResult = response.getResult();

        for (final LdapEntry entry : groupResult.getEntries()) {
            final LdapAttribute groupAttribute = entry.getAttribute(this.groupAttributeName);
            if (groupAttribute == null) {
                LOGGER.warn("Role attribute not found on entry [{}]", entry);
                continue;
            }
            addProfileRolesFromAttributes(profile, groupAttribute, this.groupPrefix);
        }
    } catch (final LdapException e) {
        throw new RuntimeException("LDAP error fetching roles for user.", e);
    }
    return profile;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:LdapUserGroupsToRolesAuthorizationGenerator.java

示例11: getString

import org.ldaptive.LdapAttribute; //导入依赖的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

示例12: executeModifyOperation

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
/**
 * Execute modify operation boolean.
 *
 * @param currentDn         the current dn
 * @param connectionFactory the connection factory
 * @param attributes        the attributes
 * @return true/false
 */
public static boolean executeModifyOperation(final String currentDn, final ConnectionFactory connectionFactory,
                                             final Map<String, Set<String>> attributes) {
    try (Connection modifyConnection = createConnection(connectionFactory)) {
        final ModifyOperation operation = new ModifyOperation(modifyConnection);
        final List<AttributeModification> mods = attributes.entrySet()
                .stream().map(entry -> new AttributeModification(AttributeModificationType.REPLACE,
                        new LdapAttribute(entry.getKey(), entry.getValue().toArray(new String[]{})))).collect(Collectors.toList());
        final ModifyRequest request = new ModifyRequest(currentDn,
                mods.toArray(new AttributeModification[]{}));
        request.setReferralHandler(new ModifyReferralHandler());
        operation.execute(request);
        return true;
    } catch (final LdapException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:LdapUtils.java

示例13: mapFromRegisteredService

import org.ldaptive.LdapAttribute; //导入依赖的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

示例14: getGraphics

import org.ldaptive.LdapAttribute; //导入依赖的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

示例15: fetchCRLFromLdap

import org.ldaptive.LdapAttribute; //导入依赖的package包/类
/**
 * Downloads a CRL from given LDAP url.
 *
 * @param r the resource that is the ldap url.
 * @return the x 509 cRL
 * @throws IOException          the exception thrown if resources cant be fetched
 * @throws CRLException         the exception thrown if resources cant be fetched
 * @throws CertificateException if connection to ldap fails, or attribute to get the revocation list is unavailable
 */
protected X509CRL fetchCRLFromLdap(final Object r) throws CertificateException, IOException, CRLException {
    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(this.certificateAttribute);

            if (attribute.isBinary()) {
                LOGGER.debug("Located entry [{}]. Retrieving first attribute [{}]", entry, attribute);
                return fetchX509CRLFromAttribute(attribute);
            }
            LOGGER.warn("Found certificate attribute [{}] but it is not marked as a binary attribute", this.certificateAttribute);
        }

        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.getMessage());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:35,代码来源:LdaptiveResourceCRLFetcher.java


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