List of usage examples for javax.naming.directory BasicAttributes BasicAttributes
public BasicAttributes(boolean ignoreCase)
From source file:CreateCorbaSchema.java
/** * Add new attributes: corbaIor corbaRepositoryId *///from w w w . j av a 2 s .c om protected void updateAttributes(DirContext attrRoot, String[] attrIDs) throws NamingException { /* Get rid of old attr IDs */ for (int i = 0; i < attrIDs.length; i++) { attrRoot.destroySubcontext(attrIDs[i]); } /* Add new and updated attr definitions */ // corbaIor Attributes attrs = new BasicAttributes(true); // ignore case attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.14"); attrs.put("NAME", "corbaIor"); attrs.put("DESC", "Stringified interoperable object reference of a CORBA object"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.26"); attrs.put("EQUALITY", "caseIgnoreIA5Match"); attrs.put("SINGLE-VALUE", "true"); attrRoot.createSubcontext("corbaIor", attrs); System.out.println("Created corbaIor attribute"); // corbaRepositoryId attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.1.15"); attrs.put("NAME", "corbaRepositoryId"); attrs.put("DESC", "Repository ids of interfaces implemented by a CORBA object"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); attrs.put("EQUALITY", "caseExactMatch"); attrRoot.createSubcontext("corbaRepositoryId", attrs); System.out.println("Created corbaRepositoryId attribute"); }
From source file:org.jamwiki.ldap.LdapUserHandler.java
/** * *///from w w w . j a va 2 s .c o m public WikiUserInfo lookupWikiUserInfo(String username) throws Exception { InitialDirContext ctx = null; try { ctx = getContext(Environment.getValue(Environment.PROP_LDAP_LOGIN), Encryption.getEncryptedProperty(Environment.PROP_LDAP_PASSWORD, null)); BasicAttributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute(Environment.getValue(Environment.PROP_LDAP_FIELD_USERID), username)); NamingEnumeration answer = ctx.search(Environment.getValue(Environment.PROP_LDAP_CONTEXT), matchAttrs, SEARCH_ATTRIBUTES); return (!answer.hasMore()) ? null : this.initWikiUserInfo(answer); } finally { try { ctx.close(); } catch (Exception e) { } } }
From source file:org.mule.providers.ldap.util.DSManager.java
private void setUpPartition(MutableServerStartupConfiguration configuration) throws NamingException { // Add partition 'sevenSeas' MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration(); pcfg.setName("sevenSeas"); pcfg.setSuffix("o=sevenseas"); // Create some indices java.util.Set indexedAttrs = new HashSet(); indexedAttrs.add("objectClass"); indexedAttrs.add("o"); pcfg.setIndexedAttributes(indexedAttrs); // Create a first entry associated to the partition Attributes attrs = new BasicAttributes(true); // First, the objectClass attribute Attribute attr = new BasicAttribute("objectClass"); attr.add("top"); attr.add("organization"); attrs.put(attr);//from w w w.j a v a 2 s. c o m // The the 'Organization' attribute attr = new BasicAttribute("o"); attr.add("sevenseas"); attrs.put(attr); // Associate this entry to the partition pcfg.setContextEntry(attrs); // As we can create more than one partition, we must store // each created partition in a Set before initialization Set pcfgs = new HashSet(); pcfgs.add(pcfg); configuration.setContextPartitionConfigurations(pcfgs); // Create a working directory // File workingDirectory = new File( "server-work" ); // configuration.setWorkingDirectory( workingDirectory ); }
From source file:org.apache.archiva.redback.authentication.ldap.LdapBindAuthenticatorTest.java
private void bindUserObject(DirContext context, String cn, String dn) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("inetOrgPerson"); objectClass.add("person"); objectClass.add("organizationalperson"); attributes.put(objectClass);//www. j av a 2 s .c o m attributes.put("cn", cn); attributes.put("sn", "foo"); attributes.put("mail", "foo"); attributes.put("userPassword", passwordEncoder.encodePassword("foo")); attributes.put("givenName", "foo"); context.createSubcontext(dn, attributes); }
From source file:org.apache.archiva.redback.common.ldap.role.TestLdapRoleMapper.java
private void createGroup(DirContext context, String groupName, String dn, List<String> users) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("groupOfUniqueNames"); attributes.put(objectClass);//from w ww . ja v a2 s. co m attributes.put("cn", groupName); BasicAttribute basicAttribute = new BasicAttribute("uniquemember"); for (String user : users) { basicAttribute.add("uid=" + user + "," + suffix);// dc=archiva,dc=apache,dc=org" ); } attributes.put(basicAttribute); context.createSubcontext(dn, attributes); }
From source file:edu.vt.middleware.ldap.dsml.Dsmlv1.java
/** * This will take a DSML <code>Element</code> containing an entry of type * <dsml:entry name="name"/> and convert it to a LDAP search result. * * @param entryElement <code>Element</code> of DSML content * * @return <code>SearchResult</code> *//* ww w . java 2 s. c o m*/ protected SearchResult createSearchResult(final Element entryElement) { String name = ""; final Attributes entryAttributes = new BasicAttributes(true); SearchResult attrResults = null; if (entryElement != null) { name = entryElement.attributeValue("dn"); if (name == null) { name = ""; } if (entryElement.hasContent()) { final Iterator<?> ocIterator = entryElement.elementIterator("objectclass"); while (ocIterator.hasNext()) { final Element ocElement = (Element) ocIterator.next(); if (ocElement != null && ocElement.hasContent()) { final String ocName = "objectClass"; final Attribute entryAttribute = new BasicAttribute(ocName); final Iterator<?> valueIterator = ocElement.elementIterator("oc-value"); while (valueIterator.hasNext()) { final Element valueElement = (Element) valueIterator.next(); if (valueElement != null) { final String value = valueElement.getText(); if (value != null) { entryAttribute.add(value); } } } entryAttributes.put(entryAttribute); } } attrResults = super.createSearchResult(entryElement); } } if (attrResults != null) { final Attributes attrs = attrResults.getAttributes(); if (attrs != null) { final NamingEnumeration<? extends Attribute> ae = attrs.getAll(); if (ae != null) { try { while (ae.hasMore()) { entryAttributes.put(ae.next()); } } catch (NamingException e) { if (LOG.isDebugEnabled()) { LOG.debug("Could not read attribute in SearchResult from parent"); } } } } } return new SearchResult(name, null, entryAttributes); }
From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java
public Attributes getLDAPUserAttributes(long ldapServerId, User user, Properties userMappings) throws SystemException { Attributes attributes = new BasicAttributes(true); Attribute objectClass = new BasicAttribute(_OBJECT_CLASS); String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String[] defaultObjectClasses = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.LDAP_USER_DEFAULT_OBJECT_CLASSES + postfix, StringPool.COMMA); for (int i = 0; i < defaultObjectClasses.length; i++) { objectClass.add(defaultObjectClasses[i]); }/*from www . ja va 2 s .co m*/ attributes.put(objectClass); addAttributeMapping(userMappings.getProperty(UserConverterKeys.SCREEN_NAME), user.getScreenName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.PASSWORD), user.getPasswordUnencrypted(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.EMAIL_ADDRESS), user.getEmailAddress(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.FULL_NAME), user.getFullName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.FIRST_NAME), user.getFirstName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.MIDDLE_NAME), user.getMiddleName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.LAST_NAME), user.getLastName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.JOB_TITLE), user.getJobTitle(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.PORTRAIT), getUserPortrait(user), attributes); return attributes; }
From source file:org.springframework.ldap.core.DirContextAdapter.java
/** * Create a new adapter from the supplied attributes, dn, base, and referral * url./*from ww w . jav a2 s. c om*/ * @param attrs the attributes. * @param dn the dn. * @param base the base. * @param referralUrl the referral url (if this instance results from a * referral). */ public DirContextAdapter(Attributes attrs, Name dn, Name base, String referralUrl) { if (attrs != null) { this.originalAttrs = attrs; } else { this.originalAttrs = new BasicAttributes(true); } if (dn != null) { this.dn = new DistinguishedName(dn); } else { this.dn = new DistinguishedName(); } if (base != null) { this.base = new DistinguishedName(base); } else { this.base = new DistinguishedName(); } if (referralUrl != null) { this.referralUrl = referralUrl; } else { this.referralUrl = EMPTY_STRING; } }
From source file:org.apache.archiva.redback.common.ldap.role.TestLdapRoleMapper.java
private void bindUserObject(DirContext context, String cn, String dn) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("inetOrgPerson"); objectClass.add("person"); objectClass.add("organizationalperson"); attributes.put(objectClass);//from w w w. j a v a2s . c om attributes.put("cn", cn); attributes.put("sn", "foo"); attributes.put("mail", cn + "@apache.org"); attributes.put("userPassword", passwordEncoder.encodePassword("foo")); attributes.put("givenName", "foo"); context.createSubcontext(dn, attributes); }
From source file:CreateCorbaSchema.java
protected void updateObjectClasses(DirContext ocRoot, String[] ocIDs) throws NamingException { /* Get rid of old OCs - reverse order */ for (int i = ocIDs.length - 1; i >= 0; i--) { ocRoot.destroySubcontext(ocIDs[i]); }/*from ww w. j a va 2 s. co m*/ // corbaObject Attributes attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.9"); attrs.put("NAME", "corbaObject"); attrs.put("DESC", "CORBA object representation"); attrs.put("SUP", "top"); attrs.put("ABSTRACT", "true"); Attribute optional = new BasicAttribute("MAY", "corbaRepositoryId"); optional.add("description"); attrs.put(optional); ocRoot.createSubcontext("corbaObject", attrs); System.out.println("Created corbaObject object class"); // corbaObjectReference attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.11"); attrs.put("NAME", "corbaObjectReference"); attrs.put("DESC", "CORBA interoperable object reference"); attrs.put("SUP", "corbaObject"); attrs.put("AUXILIARY", "true"); Attribute corMust = new BasicAttribute("MUST", "corbaIor"); if (netscape41bug) { corMust.add("objectclass"); } if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put(optional); } attrs.put(corMust); ocRoot.createSubcontext("corbaObjectReference", attrs); System.out.println("Created corbaObjectReference object class"); // corbaContainer attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.10"); attrs.put("NAME", "corbaContainer"); attrs.put("DESC", "Container for a CORBA object"); attrs.put("SUP", "top"); attrs.put("STRUCTURAL", "true"); Attribute ccMust = new BasicAttribute("MUST", "cn"); if (netscape41bug) { ccMust.add("objectclass"); } attrs.put(ccMust); ocRoot.createSubcontext("corbaContainer", attrs); System.out.println("Created corbaContainer object class"); }