Package javax.naming.directory

Examples of javax.naming.directory.Attributes


                SearchResult sr = entries.next();
                LdapDN oldLdapDn = JNDIUtils.getDn( sr );
                Rdn oldRdn = oldLdapDn.getRdn();

                // reuse attributes of the entry to copy
                Attributes newAttributes = sr.getAttributes();

                // compose new DN
                Rdn newRdn = oldLdapDn.getRdn();
                if ( forceNewRdn != null )
                {
                    newRdn = forceNewRdn;
                }
                LdapDN newLdapDn = DnUtils.composeDn( newRdn, parentDn );

                // apply new RDN to the attributes
                applyNewRdn( newAttributes, oldRdn, newRdn );

                // ManageDsaIT control
                Control[] controls = null;
                if ( newAttributes.get( SchemaConstants.OBJECT_CLASS_AT ) != null
                    && newAttributes.get( SchemaConstants.OBJECT_CLASS_AT ).contains( SchemaConstants.REFERRAL_OC ) )
                {
                    controls = new Control[]
                        { new ManageReferralControl( false ) };
                }

                // create entry
                targetBrowserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newLdapDn.getUpName(),
                    newAttributes, controls, dummyMonitor, null );

                while ( dummyMonitor.errorsReported() )
                {
                    if ( dialog != null && dummyMonitor.getException() instanceof NameAlreadyBoundException )
                    {
                        // open dialog
                        dialog.setExistingEntry( targetBrowserConnection, newLdapDn );
                        dialog.open();
                        EntryExistsCopyStrategy strategy = dialog.getStrategy();
                        //                        boolean rememberSelection = dialog.isRememberSelection();
                        if ( strategy != null )
                        {
                            dummyMonitor.reset();

                            switch ( strategy )
                            {
                                case BREAK:
                                    monitor.setCanceled( true );
                                    break;

                                case IGNORE_AND_CONTINUE:
                                    break;

                                case OVERWRITE_AND_CONTINUE:
                                    // create modification items
                                    List<ModificationItem> mis = new ArrayList<ModificationItem>();
                                    NamingEnumeration<? extends Attribute> all = newAttributes.getAll();
                                    while ( all.hasMore() )
                                    {
                                        Attribute attribute = all.next();
                                        ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
                                            attribute );
View Full Code Here


        propertyElement.addAttribute( "name", "contextEntry" ); //$NON-NLS-1$ //$NON-NLS-2$
        if ( partition.getContextEntry() != null )
        {
            Element valueElement = propertyElement.addElement( "value" ); //$NON-NLS-1$

            Attributes contextEntry = partition.getContextEntry();
            StringBuffer sb = new StringBuffer();
            NamingEnumeration<? extends Attribute> ne = contextEntry.getAll();
            while ( ne.hasMoreElements() )
            {
                Attribute attribute = ( Attribute ) ne.nextElement();
                try
                {
View Full Code Here

                    monitor.reportError( e );
                    return;
                }
            }

            Attributes jndiAttributes = new BasicAttributes();
            for ( LdifAttrValLine attrVal : attrVals )
            {
                String attributeName = attrVal.getUnfoldedAttributeDescription();
                Object realValue = attrVal.getValueAsObject();

                if ( jndiAttributes.get( attributeName ) != null )
                {
                    jndiAttributes.get( attributeName ).add( realValue );
                }
                else
                {
                    jndiAttributes.put( attributeName, realValue );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
                getControls( record ), monitor, null );
View Full Code Here

    {
        // dn
        String dn = entryToCreate.getDn().getUpName();

        // attributes
        Attributes jndiAttributes = new BasicAttributes();
        IAttribute[] attributes = entryToCreate.getAttributes();
        for ( int i = 0; i < attributes.length; i++ )
        {
            String description = attributes[i].getDescription();
            IValue[] values = attributes[i].getValues();
            for ( int ii = 0; ii < values.length; ii++ )
            {
                IValue value = values[ii];
                Object rawValue = value.getRawValue();
                if ( jndiAttributes.get( description ) != null )
                {
                    jndiAttributes.get( description ).add( rawValue );
                }
                else
                {
                    jndiAttributes.put( description, rawValue );
                }
            }
        }

        // ManageDsaIT control
View Full Code Here

            Name entryName = parser.parse(result.getName());
            Name name = contextName.addAll(baseName);
            name = name.addAll(entryName);
            String dn = name.toString();

            Attributes attrs = result.getAttributes();
            if (attrs == null) {
                return false;
            }
            ArrayList roles = null;
            if (userRoleName != null) {
View Full Code Here

        }
        NamingEnumeration results =
                context.search(roleBase, filter, constraints);
        while (results.hasMore()) {
            SearchResult result = (SearchResult) results.next();
            Attributes attrs = result.getAttributes();
            if (attrs == null) {
                continue;
            }
            list = addAttributeValues(roleName, attrs, list);
        }
View Full Code Here

        return buf.toString();
    }

    protected boolean bindUser(DirContext context, String dn, String password) throws NamingException {
        boolean isValid = false;
        Attributes attr;

        context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
        context.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
        try {
            attr = context.getAttributes("", null);
View Full Code Here

          userDN.addAll(parser.parse(sr.getName()));
          user.put("userDN", userDN.toString());
                   
              // Get all available attribute types and their associated values.
          // we can build a user object to return.
              Attributes attributes = sr.getAttributes();

              Attribute attr;
              NamingEnumeration<?> ne;

              // Iterate through the attributes.
              //String json = "{";
              for (NamingEnumeration<?> a = attributes.getAll(); a.hasMore();) {
                  attr = (Attribute)a.next();
                 
                  //json = json + attr.getID() + ": { ";
                  String json = "";
                  ne = attr.getAll();
View Full Code Here

         //
         LdapContext ctx = (LdapContext)ldapContext.lookup(getContainerDN());

         //We store new entry using set of attributes. This should give more flexibility then
         //extending user object from ContextDir - configure what objectClass place there
         Attributes attrs = new BasicAttributes(true);

         //create attribute using provided configuration
         Map attributesToAdd = getAttributesToAdd();

         //attributes
         for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
         {
            String attributeName = (String)it1.next();
            if (getUidAttributeID().equals(attributeName))
            {
               continue;
            }
            log.debug("adding attribute: " + attributeName);
            Attribute attr = new BasicAttribute(attributeName);
            Set attributeValues = (Set)attributesToAdd.get(attributeName);

            //values
            for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
            {
               String attrValue = (String)it2.next();
               log.debug("adding attribute value: " + attrValue);
               attr.add(attrValue);
            }
            attrs.put(attr);
         }

         if (!isSetPasswordAfterUserCreate())
         {
            attrs.put(getPasswordAttributeId(), password);
         }

         String validUserName = LDAPTools.encodeRfc2253Name(userName);

         String dn = getUidAttributeID().concat("=").concat(validUserName);
View Full Code Here

    private String[] getSMTPServerByJNDI(String to) throws Exception
      String host=getDomainFromAddress(to);
        Properties jndiEnvironmentProperties = new Properties()
        jndiEnvironmentProperties.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory")
        InitialDirContext initialDirContext = new InitialDirContext(jndiEnvironmentProperties)
        Attributes attributes = initialDirContext.getAttributes(host, new String[] {"MX"})
       
        Attribute attribute = attributes.get("MX")
        String[] servers = new String[attribute.size()]
        for (int i = 0; i < attribute.size(); i++) { 
            servers[i] = attribute.get(i).toString()
            servers[i]=servers[i].substring(servers[i].indexOf(" ") + 1, servers[i].length() -1)
           
View Full Code Here

TOP

Related Classes of javax.naming.directory.Attributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.