本文整理汇总了Java中org.ldaptive.LdapAttribute.getStringValue方法的典型用法代码示例。如果您正苦于以下问题:Java LdapAttribute.getStringValue方法的具体用法?Java LdapAttribute.getStringValue怎么用?Java LdapAttribute.getStringValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ldaptive.LdapAttribute
的用法示例。
在下文中一共展示了LdapAttribute.getStringValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例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;
}
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;
}
示例3: 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;
}
示例4: getString
import org.ldaptive.LdapAttribute; //导入方法依赖的package包/类
private String getString(final LdapEntry entry, final String attribute, final String nullValue) {
final LdapAttribute attr = entry.getAttribute(attribute);
if (attr == null) {
return nullValue;
}
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;
}
示例5: createPrincipal
import org.ldaptive.LdapAttribute; //导入方法依赖的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<>(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) {
attributeMap.put(principalAttrName, attr.getStringValues());
} else {
attributeMap.put(principalAttrName, attr.getStringValue());
}
}
}
return this.principalFactory.createPrincipal(id, attributeMap);
}
示例6: getLdapPrincipalIdentifier
import org.ldaptive.LdapAttribute; //导入方法依赖的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;
}
示例7: findEmail
import org.ldaptive.LdapAttribute; //导入方法依赖的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;
}
示例8: createPrincipal
import org.ldaptive.LdapAttribute; //导入方法依赖的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);
}
示例9: getString
import org.ldaptive.LdapAttribute; //导入方法依赖的package包/类
/**
* Reads a String value from the LdapEntry.
*
* @param ctx the ldap entry
* @param attribute the attribute name
* @param nullValue the value which should be returning in case of a null value
*/
public static String getString(final LdapEntry ctx, final String attribute, final String nullValue) {
final LdapAttribute attr = ctx.getAttribute(attribute);
if (attr == null) {
return nullValue;
}
final String v = attr.getStringValue();
if (v != null) {
return v;
}
return nullValue;
}
示例10: createPrincipal
import org.ldaptive.LdapAttribute; //导入方法依赖的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);
}
示例11: createPrincipal
import org.ldaptive.LdapAttribute; //导入方法依赖的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) {
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());
}
}
}
logger.debug("Created LDAP principal for id {} and {} attributes", id, attributeMap.size());
return this.principalFactory.createPrincipal(id, attributeMap);
}