List of usage examples for javax.naming.directory Attribute get
Object get() throws NamingException;
From source file:org.eurekastreams.server.persistence.mappers.ldap.AttributesToDisplayNameSuffixTransformer.java
/** * Transform the input Attributes to the display name suffix, or null if not found or not applicable. * /*w w w. jav a 2 s . co m*/ * @param inAttributes * The Attributes to transform to the display name suffix * @return Transformed object. */ public String transform(final Attributes inAttributes) { String result = null; try { Attribute attribute = inAttributes.get(attributeName); log.debug("Matching attribute(with brackets added): [" + attributeName + " = " + attribute.get() + "]"); if (attribute != null && attribute.get().toString().matches(regularExpression)) { log.debug("Matched - result (with brackets added): [" + displayNameSuffix + "]"); result = displayNameSuffix; } } catch (Exception ex) { log.error("Error transforming Attributes to displayNameSuffix: ", ex); result = null; } return result; }
From source file:ca.uhnresearch.pughlab.authentication.LdapAccountDetails.java
public String getAttributeAsString(String attrID) { Attribute att = attributes.get(attrID); if (att == null) { return null; }//from w w w . j av a2 s . c o m try { return att.get().toString(); } catch (NamingException e) { return null; } }
From source file:edu.kit.scc.ldap.LdapPosixUserAttributeMapper.java
@Override public PosixUser mapFromAttributes(Attributes attributes) throws NamingException { PosixUser posixUser = new PosixUser(); String uid = (String) attributes.get("uid").get(); if (uid != null) { posixUser.setUid(uid);/* w ww .j a v a 2 s.c om*/ } String commonName = (String) attributes.get("cn").get(); if (commonName != null) { posixUser.setCommonName(commonName); } String surName = (String) attributes.get("sn").get(); if (surName != null) { posixUser.setSurName(surName); } String homeDirectory = (String) attributes.get("homeDirectory").get(); if (homeDirectory != null) { posixUser.setHomeDirectory(homeDirectory); } Attribute gidNumber = attributes.get("gidNumber"); if (gidNumber != null) { posixUser.setGidNumber((String) gidNumber.get()); } Attribute uidNumber = attributes.get("uidNumber"); if (uidNumber != null) { posixUser.setUidNumber((String) uidNumber.get()); } Attribute description = attributes.get("description"); if (description != null) { posixUser.setDescription((String) description.get()); } Attribute userPassword = attributes.get("userPassword"); if (userPassword != null) { posixUser.setUserPassword((byte[]) userPassword.get()); } Attribute gecos = attributes.get("gecos"); if (gecos != null) { posixUser.setGecos((String) gecos.get()); } Attribute loginShell = attributes.get("loginShell"); if (loginShell != null) { posixUser.setLoginShell((String) loginShell.get()); } Attribute uniqueIdentifier = attributes.get("uniqueIdentifier"); if (uniqueIdentifier != null) { posixUser.setUniqueIdentifier((String) uniqueIdentifier.get()); } Attribute mail = attributes.get("mail"); if (mail != null) { posixUser.setMail((String) mail.get()); } Attribute givenName = attributes.get("givenName"); if (givenName != null) { posixUser.setGivenName((String) givenName.get()); } return posixUser; }
From source file:org.acegisecurity.userdetails.ldap.LdapUserDetailsMapper.java
/** * Extension point to allow customized creation of the user's password from * the attribute stored in the directory. * * @param passwordAttribute the attribute instance containing the password * @return a String representation of the password. *///from w ww . jav a 2 s .c om protected String mapPassword(Attribute passwordAttribute) throws NamingException { Object retrievedPassword = passwordAttribute.get(); if (!(retrievedPassword instanceof String)) { // Assume it's binary retrievedPassword = new String((byte[]) retrievedPassword); } return (String) retrievedPassword; }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleCalendarResourceAccountAttributesMapper.java
@Override public Object mapFromAttributes(Attributes attributes) throws NamingException { OracleCalendarResourceAccount user = new OracleCalendarResourceAccount(owner); NamingEnumeration<String> attributeNames = attributes.getIDs(); Map<String, String> attributesMap = new HashMap<String, String>(); while (attributeNames.hasMore()) { String attributeName = attributeNames.next(); Attribute attribute = attributes.get(attributeName); String value = (String) attribute.get(); if (null != value) { value = value.trim();//from w w w . ja v a 2 s .com } final String lcAttributeName = attributeName.toLowerCase(); attributesMap.put(lcAttributeName, value); if (RESOURCE_OWNER_USERNAME.equals(lcAttributeName)) { user.setAccountOwnerUsername(value); } else if (AbstractOracleCalendarAccount.CTCALXITEMID.equals(lcAttributeName)) { user.setCtcalxitemid(value); } else if (OracleLdapCalendarResourceAccountDaoImpl.CN.equals(lcAttributeName)) { user.setResourceName(value); } else if (OracleLdapCalendarResourceAccountDaoImpl.POSTALADDRESS.equals(lcAttributeName)) { user.setLocation(value); } else if (AbstractOracleCalendarAccount.WISCEDUCALEMAIL.equals(lcAttributeName)) { user.setEmailAddress(value); } } user.setAttributes(attributesMap); String contactInfo = buildContactInformation( getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.GIVENNAME), getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.SN), getAttributeValue(attributes, OracleLdapCalendarResourceAccountDaoImpl.TELEPHONENUMBER)); user.setContactInformation(contactInfo); String oracleGuid = this.oracleGUIDSource.getOracleGUID(user); user.setOracleGuid(oracleGuid); user.getAttributes().put(AbstractOracleCalendarAccount.ORACLE_GUID_ATTRIBUTE, oracleGuid); return user; }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleCalendarResourceAccountAttributesMapper.java
/** * Get the specified attribute, or null. * If the attribute is not empty, it's value is {@link String#trim()}'d. * /* w w w.j a v a 2s . c o m*/ * @param attributes * @param attributeName * @return * @throws NamingException */ String getAttributeValue(Attributes attributes, String attributeName) throws NamingException { Attribute attribute = attributes.get(attributeName); if (null != attribute) { String value = (String) attribute.get(); if (null != value) { value = value.trim(); } return value; } return null; }
From source file:org.jasig.cas.adaptors.ldap.remote.RemoteIpLookupCredentialsToPrincipalResolver.java
protected String extractPrincipalId(final Credentials credentials) { final RemoteAddressCredentials c = (RemoteAddressCredentials) credentials; final String formattedIpAddress = getFormattedIpAddress(c.getRemoteAddress().trim()); if (!StringUtils.hasText(formattedIpAddress)) { return null; }//from w w w . j ava2 s .c o m if (log.isDebugEnabled()) { log.debug("Original IP address: " + c.getRemoteAddress()); log.debug("Formatted IP address: " + formattedIpAddress); } final String attributeId = getAttributeIds()[0]; final List principalList = this.getLdapTemplate().search(getSearchBase(), LdapUtils.getFilterWithValues(getFilter(), formattedIpAddress), getSearchControls(), new AttributesMapper() { public Object mapFromAttributes(final Attributes attrs) throws NamingException { final Attribute attribute = attrs.get(attributeId); return attribute == null ? null : attribute.get(); } }); if (principalList.isEmpty()) { log.debug("LDAP search returned zero results."); return null; } if (principalList.size() > 1) { log.error("LDAP search returned multiple results " + "for filter \"" + getFilter() + "\", " + "which is not allowed."); return null; } return (String) principalList.get(0); }
From source file:openscim.restful.server.resources.group.ldap.GroupAttributesMapper.java
public Object mapFromAttributes(Attributes attributes) throws NamingException { // create a group resource Group group = ResourceUtilities.FACTORY.createGroup(); // get the gid attribute name String gidAtttributeName = properties.getProperty(GID_ATTRIBUTE, DEFAULT_GID_ATTRIBUTE); // get the gid Attribute gidAttribute = attributes.get(gidAtttributeName); if (gidAttribute != null) group.setId((String) gidAttribute.get()); // get the member attribute name String memberAtttributeName = properties.getProperty(MEMBER_ATTRIBUTE, DEFAULT_MEMBER_ATTRIBUTE); // get the members NamingEnumeration memberEnumeration = attributes.get(memberAtttributeName).getAll(); if (memberEnumeration != null) { // create a members resource List<PluralAttribute> members = new ArrayList<PluralAttribute>(); while (memberEnumeration.hasMoreElements()) { // get the next member String memberAttribute = (String) memberEnumeration.next(); if (memberAttribute != null) { PluralAttribute pluralAttribute = ResourceUtilities.FACTORY.createPluralAttribute(); // check if the member dns need to be concealed if (properties .getProperty(GroupAttributesMapper.CONCEAL_GROUP_DNS, GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS) .equalsIgnoreCase(GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS)) { Matcher matcher = pattern.matcher(memberAttribute); if (matcher.matches()) { memberAttribute = matcher.group(1); }// w w w . java 2 s . c om } pluralAttribute.setValue(memberAttribute); members.add(pluralAttribute); } } // add the members to the group resource group.setAny(members); } return group; }
From source file:com.ktds.ldap.populator.AttributeCheckAttributesMapper.java
public Object mapFromAttributes(Attributes attributes) throws NamingException { Assert.assertEquals("Values and attributes need to have the same length ", expectedAttributes.length, expectedValues.length);/* www .j a va 2 s.c o m*/ for (int i = 0; i < expectedAttributes.length; i++) { Attribute attribute = attributes.get(expectedAttributes[i]); Assert.assertNotNull("Attribute " + expectedAttributes[i] + " was not present", attribute); Assert.assertEquals(expectedValues[i], attribute.get()); } for (String absentAttribute : absentAttributes) { Assert.assertNull(attributes.get(absentAttribute)); } return null; }
From source file:org.jasig.portlet.contacts.adapters.impl.ldap.ConfigurableContactAttributesMapper.java
private String getValue(Attribute attribute) throws javax.naming.NamingException { if (attribute != null) { String value = (String) attribute.get(); if (value != null && !value.equalsIgnoreCase("empty")) { return value; }/*from w w w . j a v a 2 s . c o m*/ } return ""; }