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


Java LdapEntry.getAttribute方法代码示例

本文整理汇总了Java中org.ldaptive.LdapEntry.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java LdapEntry.getAttribute方法的具体用法?Java LdapEntry.getAttribute怎么用?Java LdapEntry.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ldaptive.LdapEntry的用法示例。


在下文中一共展示了LdapEntry.getAttribute方法的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;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:17,代码来源:LdapAuthenticator.java

示例2: 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

示例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;
    }

    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

示例4: 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

示例5: 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

示例6: 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 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

示例7: getMultiValuedAttributeValues

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Gets the attribute values if more than one, otherwise an empty list.
 *
 * @param entry the entry
 * @param attrName the attr name
 * @return the collection of attribute values
 */
private Collection<String> getMultiValuedAttributeValues(@NotNull final LdapEntry entry, @NotNull final String attrName) {
    final LdapAttribute attrs = entry.getAttribute(attrName);
    if (attrs != null) {
        return attrs.getStringValues();
    }
    return Collections.emptyList();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:DefaultLdapRegisteredServiceMapper.java

示例8: processSpnegoAttribute

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Verify spnego attribute value.
 *
 * @param searchResult the search result
 * @return true if attribute value exists and has a value
 */
protected boolean processSpnegoAttribute(final Response<SearchResult> searchResult) {
    final SearchResult result = searchResult.getResult();

    if (result == null || result.getEntries().isEmpty()) {
        logger.debug("Spnego attribute is not found in the search results");
        return false;
    }
    final LdapEntry entry = result.getEntry();
    final LdapAttribute attribute = entry.getAttribute(this.spnegoAttributeName);
    return verifySpnegyAttributeValue(attribute);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:LdapSpnegoKnownClientSystemsFilterAction.java

示例9: getLdapPrincipalIdentifier

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Gets ldap principal identifier. If the principal id attribute is defined, it's retrieved.
 * If no attribute value is found, a warning is generated and the provided username is used instead.
 * If no attribute is defined, username is used instead.
 *
 * @param username  the username
 * @param ldapEntry the ldap entry
 * @return the ldap principal identifier
 * @throws LoginException in case the principal id cannot be determined.
 */
protected String getLdapPrincipalIdentifier(final String username, final LdapEntry ldapEntry) throws LoginException {
    if (StringUtils.isNotBlank(this.principalIdAttribute)) {
        final LdapAttribute principalAttr = ldapEntry.getAttribute(this.principalIdAttribute);
        if (principalAttr == null || principalAttr.size() == 0) {

            if (this.allowMissingPrincipalAttributeValue) {
                LOGGER.warn("The principal id attribute [{}] is not found. CAS cannot construct the final authenticated principal "
                                + "if it's unable to locate the attribute that is designated as the principal id. "
                                + "Attributes available on the LDAP entry are [{}]. Since principal id attribute is not available, CAS will "
                                + "fall back to construct the principal based on the provided user id: [{}]",
                        this.principalIdAttribute, ldapEntry.getAttributes(), username);
                return username;
            }
            LOGGER.error("The principal id attribute [{}] is not found. CAS is configured to disallow missing principal attributes",
                    this.principalIdAttribute);
            throw new LoginException("Principal id attribute is not found for " + principalAttr);
        }

        if (principalAttr.size() > 1) {
            if (!this.allowMultiplePrincipalAttributeValues) {
                throw new LoginException("Multiple principal values are not allowed: " + principalAttr);
            }
            LOGGER.warn("Found multiple values for principal id attribute: [{}]. Using first value=[{}].", principalAttr, principalAttr.getStringValue());
        }
        LOGGER.debug("Retrieved principal id attribute [{}]", principalAttr.getStringValue());
        return principalAttr.getStringValue();
    }

    LOGGER.debug("Principal id attribute is not defined. Using the default provided user id [{}]", username);
    return username;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:42,代码来源:LdapAuthenticationHandler.java

示例10: generateAuthorizationForLdapEntry

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
@Override
protected CommonProfile generateAuthorizationForLdapEntry(final CommonProfile profile, final LdapEntry userEntry) {
    if (userEntry.getAttributes().isEmpty()) {
        throw new IllegalStateException("No attributes are retrieved for this user.");
    }

    final LdapAttribute attribute = userEntry.getAttribute(this.roleAttribute);
    if (attribute == null) {
        throw new IllegalStateException("Configured role attribute cannot be found for this user");
    }

    addProfileRoles(userEntry, profile, attribute, this.rolePrefix);
    return profile;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:LdapUserAttributesToRolesAuthorizationGenerator.java

示例11: findEmail

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
@Override
public String findEmail(final String username) {
    try {
        final PasswordManagementProperties.Ldap ldap = passwordManagementProperties.getLdap();
        final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldap.getUserFilter(),
                Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME,
                Arrays.asList(username));
        LOGGER.debug("Constructed LDAP filter [{}] to locate account email", filter);

        final ConnectionFactory factory = Beans.newLdaptivePooledConnectionFactory(ldap);
        final Response<SearchResult> response = LdapUtils.executeSearchOperation(factory, ldap.getBaseDn(), filter);
        LOGGER.debug("LDAP response to locate account email is [{}]", response);

        if (LdapUtils.containsResultEntry(response)) {
            final LdapEntry entry = response.getResult().getEntry();
            LOGGER.debug("Found LDAP entry [{}] to use for the account email", entry);

            final String attributeName = passwordManagementProperties.getReset().getEmailAttribute();
            final LdapAttribute attr = entry.getAttribute(attributeName);
            if (attr != null) {
                final String email = attr.getStringValue();
                LOGGER.debug("Found email address [{}] for user [{}]. Validating...", email, username);
                if (EmailValidator.getInstance().isValid(email)) {
                    LOGGER.debug("Email address [{}] matches a valid email address", email);
                    return email;
                }
                LOGGER.error("Email [{}] is not a valid address", email);
            } else {
                LOGGER.error("Could not locate an LDAP attribute [{}] for [{}] and base DN [{}]",
                        attributeName, filter.format(), ldap.getBaseDn());
            }
            return null;
        }
        LOGGER.error("Could not locate an LDAP entry for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:LdapPasswordManagementService.java

示例12: processSpnegoAttribute

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Verify spnego attribute value.
 *
 * @param searchResult the search result
 * @return true if attribute value exists and has a value
 */
protected boolean processSpnegoAttribute(final Response<SearchResult> searchResult) {
    final SearchResult result = searchResult.getResult();

    if (result == null || result.getEntries().isEmpty()) {
        LOGGER.debug("Spnego attribute is not found in the search results");
        return false;
    }
    final LdapEntry entry = result.getEntry();
    final LdapAttribute attribute = entry.getAttribute(this.spnegoAttributeName);
    LOGGER.debug("Spnego attribute [{}] found as [{}] for [{}]", attribute.getName(), attribute.getStringValue(), entry.getDn());
    return verifySpnegoAttributeValue(attribute);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:LdapSpnegoKnownClientSystemsFilterAction.java

示例13: getEligibleAccountsForSurrogateToProxy

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
@Override
public Collection<String> getEligibleAccountsForSurrogateToProxy(final String username) {
    final Collection<String> eligible = new LinkedHashSet<>();
    try {
        final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldapProperties.getSearchFilter(), Arrays.asList(username));
        LOGGER.debug("Using search filter: [{}]", filter);

        final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory,
                ldapProperties.getBaseDn(), filter);
        LOGGER.debug("LDAP response: [{}]", response);

        if (!LdapUtils.containsResultEntry(response)) {
            return eligible;
        }

        final LdapEntry ldapEntry = response.getResult().getEntry();
        final LdapAttribute attribute = ldapEntry.getAttribute(ldapProperties.getMemberAttributeName());
        if (attribute == null || attribute.getStringValues().isEmpty()) {
            return eligible;
        }

        final Pattern pattern = RegexUtils.createPattern(ldapProperties.getMemberAttributeValueRegex());
        eligible.addAll(
                attribute.getStringValues()
                        .stream()
                        .map(pattern::matcher)
                        .filter(Matcher::matches)
                        .map(p -> p.group(1))
                        .collect(Collectors.toList()));

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return eligible;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:36,代码来源:LdapSurrogateUsernamePasswordService.java

示例14: createPrincipal

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Creates a CAS principal with attributes if the LDAP entry contains principal attributes.
 *
 * @param username Username that was successfully authenticated which is used for principal ID when
 *                 {@link #setPrincipalIdAttribute(String)} is not specified.
 * @param ldapEntry LDAP entry that may contain principal attributes.
 *
 * @return Principal if the LDAP entry contains at least a principal ID attribute value, null otherwise.
 *
 * @throws LoginException On security policy errors related to principal creation.
 */
protected Principal createPrincipal(final String username, final LdapEntry ldapEntry) throws LoginException {
    final String id;
    if (this.principalIdAttribute != null) {
        final LdapAttribute principalAttr = ldapEntry.getAttribute(this.principalIdAttribute);
        if (principalAttr == null || principalAttr.size() == 0) {
            throw new LoginException(this.principalIdAttribute + " attribute not found for " + username);
        }
        if (principalAttr.size() > 1) {
            if (this.allowMultiplePrincipalAttributeValues) {
                logger.warn(
                        "Found multiple values for principal ID attribute: {}. Using first value={}.",
                        principalAttr,
                        principalAttr.getStringValue());
            } else {
                throw new LoginException("Multiple principal values not allowed: " + principalAttr);
            }
        }
        id = principalAttr.getStringValue();
    } else {
        id = username;
    }
    final Map<String, Object> attributeMap = new LinkedHashMap<String, Object>(this.principalAttributeMap.size());
    for (String ldapAttrName : this.principalAttributeMap.keySet()) {
        final LdapAttribute attr = ldapEntry.getAttribute(ldapAttrName);
        if (attr != null) {
            logger.debug("Found principal attribute: {}", attr);
            final String principalAttrName = this.principalAttributeMap.get(ldapAttrName);
            if (attr.size() > 1) {
                attributeMap.put(principalAttrName, attr.getStringValues());
            } else {
                attributeMap.put(principalAttrName, attr.getStringValue());
            }
        }
    }
    return new SimplePrincipal(id, attributeMap);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:48,代码来源:LdapAuthenticationHandler.java

示例15: createPrincipal

import org.ldaptive.LdapEntry; //导入方法依赖的package包/类
/**
 * Creates a CAS principal with attributes if the LDAP entry contains principal attributes.
 *
 * @param username Username that was successfully authenticated which is used for principal ID when
 *                 {@link #setPrincipalIdAttribute(String)} is not specified.
 * @param ldapEntry LDAP entry that may contain principal attributes.
 *
 * @return Principal if the LDAP entry contains at least a principal ID attribute value, null otherwise.
 *
 * @throws LoginException On security policy errors related to principal creation.
 */
protected Principal createPrincipal(final String username, final LdapEntry ldapEntry) throws LoginException {
    logger.debug("Creating LDAP principal for {} based on {}", username, ldapEntry.getDn());
    final String id;
    if (this.principalIdAttribute != null) {
        final LdapAttribute principalAttr = ldapEntry.getAttribute(this.principalIdAttribute);
        if (principalAttr == null || principalAttr.size() == 0) {
            logger.error("The principal id attribute {} is not found. CAS cannot construct the final authenticated principal "
                    + "if it's unable to locate the attribute that is designated as the principal id. Attributes available are {}",
                    this.principalIdAttribute, ldapEntry.getAttributes());
            throw new LoginException(this.principalIdAttribute + " attribute not found for " + username);
        }

        if (principalAttr.size() > 1) {
            if (this.allowMultiplePrincipalAttributeValues) {
                logger.warn(
                        "Found multiple values for principal ID attribute: {}. Using first value={}.",
                        principalAttr,
                        principalAttr.getStringValue());
            } else {
                throw new LoginException("Multiple principal values not allowed: " + principalAttr);
            }
        }
        id = principalAttr.getStringValue();
        logger.debug("Retrieved principal id attribute {}", id);
    } else {
        id = username;
        logger.debug("Principal id attribute is not defined. Using the default id {}", id);
    }
    final Map<String, Object> attributeMap = new LinkedHashMap<>(this.principalAttributeMap.size());
    for (final Map.Entry<String, String> ldapAttr : this.principalAttributeMap.entrySet()) {
        final LdapAttribute attr = ldapEntry.getAttribute(ldapAttr.getKey());
        if (attr != null) {
            logger.debug("Found principal attribute: {}", attr);
            final String principalAttrName = ldapAttr.getValue();
            if (attr.size() > 1) {
                logger.debug("Principal attribute: {} is multivalued", attr);
                attributeMap.put(principalAttrName, attr.getStringValues());
            } else {
                attributeMap.put(principalAttrName, attr.getStringValue());
            }
        }
    }

    attributeMap.put(LDAP_ATTRIBUTE_ENTRY_DN, ldapEntry.getDn());

    logger.debug("Created LDAP principal for id {} and {} attributes", id, attributeMap.size());
    return this.principalFactory.createPrincipal(id, attributeMap);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:60,代码来源:LdapAuthenticationHandler.java


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