Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 2011 Tirasa. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  */
 package org.connid.ad.util;
 
 import java.util.List;
 import java.util.Set;
 import static org.connid.ad.ADConnector.UACCONTROL_ATTR;
 import static org.connid.ad.ADConnector.UF_ACCOUNTDISABLE;
 
 public class ADUtilities {
 
     private final Log LOG = Log.getLog(ADUtilities.class);
 
     private ADConnection connection;
 
     private GroupHelper groupHelper;
 
     public ADUtilities(final ADConnection connection) {
         this. = connection;
          = new GroupHelper(connection);
     }
 
             final String baseDN,
             final Attributes profile,
             final ObjectClass oclass)
             throws NamingException {
 
         final LdapEntry entry = LdapEntry.create(baseDNprofile);
 
         final ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
         builder.setObjectClass(oclass);
 
         builder.setUid(.getSchemaMapping().createUid(oclassentry));
         builder.setName(.getSchemaMapping().createName(oclassentry));
 
         final NamingEnumeration<StringattributeNames = profile.getIDs();
 
         while (attributeNames.hasMoreElements()) {
             final String attributeName = attributeNames.next();
 
             Attribute attribute = null;
 
             if (LdapConstants.isLdapGroups(attributeName)) {
                 final List<StringldapGroups =
                         .getLdapGroups(entry.getDN().toString());
                 attribute = AttributeBuilder.build(
                         .ldapGroups);
             } else if (LdapConstants.isPosixGroups(attributeName)) {
                 final Set<StringposixRefAttrs =
                         LdapUtil.getStringAttrValues(entry.getAttributes(),
                         GroupHelper.getPosixRefAttribute());
                 final List<StringposixGroups =
                         .getPosixGroups(posixRefAttrs);
                 attribute = AttributeBuilder.build(
                         .posixGroups);
             } else if (..is(attributeName)) {
                // IMPORTANT!!! Return empty guarded string
                attribute = AttributeBuilder.build(
                        attributeNamenew GuardedString());
            } else if (.equals(attributeName)) {
                try {
                    final String status =
                            profile.get().get() != null
                            ? profile.get().get().
                            toString()
                            : null;
                    if (.isOk()) {
                        .ok("User Account Control: {0}"status);
                    }
                    // enabled if UF_ACCOUNTDISABLE is not included (0x00002)
                    if (status == null || Integer.parseInt(
                            profile.get().get().toString())
                            % 16 != ) {
                        attribute = AttributeBuilder.buildEnabled(true);
                    } else {
                        attribute = AttributeBuilder.buildEnabled(false);
                    }
                } catch (NamingException e) {
                    .error(e"While fetching " + );
                }
            } else {
                attribute = .getSchemaMapping().createAttribute(
                        oclassattributeNameentryfalse);
            }
            // Avoid attribute adding in case of attribute name not found
            if (attribute != null) {
                builder.addAttribute(attribute);
            }
        }
        return builder.build();
    }
            final String baseDN,
            final Uid uid,
            final Attributes profile,
            final ObjectClass oclass)
            throws NamingException {
        final LdapEntry entry = LdapEntry.create(baseDNprofile);
        final ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
        builder.setObjectClass(oclass);
        builder.setUid(uid);
        builder.setName("fake-dn");
        builder.addAttributes(.);
        return builder.build();
    }

    
Create a DN string starting from a set attributes and a default people container. This method has to be used if __NAME__ attribute is not provided or it it is not a DN.

Parameters:
attrs set of user attributes.
defaulContainer default people container.
Returns:
distinguished name string.
    public final String getDN(final Set<Attributeattrs) {
        String cn;
        final Attribute cnAttr = AttributeUtil.find("cn"attrs);
        if (cnAttr == null || cnAttr.getValue() == null
                || cnAttr.getValue().isEmpty()
                || StringUtil.isBlank(cnAttr.getValue().get(0).toString())) {
            // Get the name attribute and consider this as the principal name.
            // Use the principal name as the CN to generate DN.
            cn = AttributeUtil.getNameFromAttributes(attrs).getNameValue();
        } else {
            // Get the common name and use this to generate the DN.
            cn = cnAttr.getValue().get(0).toString();
        }
        return "cn=" + cn + ","
                + ((ADConfiguration) (.getConfiguration())).getDefaultPeopleContainer();
    }

    
Check if the String is an ldap DN.

Parameters:
dn string to be checked.
Returns:
TRUE if the value provided is a DN; FALSE otherwise.
    public final boolean isDN(final String dn) {
        try {
            return StringUtil.isNotBlank(dn) && new LdapName(dn) != null;
        } catch (InvalidNameException ex) {
            return false;
        }
    }
New to GrepCode? Check out our FAQ X