Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
==================== DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. Copyright 2011-2013 Tirasa. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at https://oss.oracle.com/licenses/CDDL See the License for the specific language governing permissions and limitations under the License. When distributing the Covered Code, include this CDDL Header Notice in each file and include the License file at https://oss.oracle.com/licenses/CDDL. If applicable, add the following below this CDDL Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyrighted [year] [name of copyright owner]" ====================
 
 package org.connid.bundles.ad.crud;
 
 import static org.connid.bundles.ad.ADConnector.UACCONTROL_ATTR;
 import static org.connid.bundles.ad.ADConnector.UF_ACCOUNTDISABLE;
 import static org.connid.bundles.ad.ADConnector.UF_NORMAL_ACCOUNT;
 import static org.connid.bundles.ldap.commons.LdapUtil.checkedListByFilter;
 import static org.identityconnectors.common.CollectionUtil.isEmpty;
 import static org.identityconnectors.common.CollectionUtil.nullAsEmpty;
 
 import java.util.List;
 import java.util.Set;
 
 public class ADCreate extends LdapModifyOperation {
 
     private static final Log LOG = Log.getLog(ADConnection.class);
 
     private final ObjectClass oclass;
 
     private final Set<Attributeattrs;
 
     @SuppressWarnings("FieldNameHidesFieldInSuperclass")
     private final ADConnection conn;
 
     public ADCreate(
             final ADConnection conn,
             final ObjectClass oclass,
             final Set<Attributeattrs,
             final OperationOptions options) {
         super(conn);
 
         this. = oclass;
         this. = attrs;
         this. = conn;
     }
 
     public Uid create() {
         try {
             return executeImpl();
         } catch (NamingException e) {
             throw new ConnectorException(e);
         }
     }
 
     private Uid executeImpl() throws NamingException {
 
         // -------------------------------------------------
         // Retrieve DN
         // -------------------------------------------------
         final Name nameAttr = AttributeUtil.getNameFromAttributes();
 
         if (nameAttr == null) {
             throw new IllegalArgumentException("No Name attribute provided in the attributes");
         }
 
         final Attribute cnAttr = AttributeUtil.find(.);
         if (cnAttr != null) {
             .remove(cnAttr);
        }
        final ADUtilities utils = new ADUtilities();
        Name name;
        if (utils.isDN(nameAttr.getNameValue())) {
            name = nameAttr;
        } else {
            Uid uidAttr = AttributeUtil.getUidAttribute();
            if (uidAttr == null && StringUtil.isNotBlank(nameAttr.getNameValue())) {
                uidAttr = new Uid(nameAttr.getNameValue());
                .add(uidAttr);
            }
            name = new Name(utils.getDN(nameAttrcnAttr));
        }
        // -------------------------------------------------
        List<StringldapGroups = null;
        ADGuardedPasswordAttribute pwdAttr = null;
        final BasicAttributes adAttrs = new BasicAttributes(true);
        int uacValue = -1;
        for (Attribute attr : ) {
            if (attr.is(.)) {
                // Handled already.
            } else if (attr.is(.)) {
                final List<Objectvalue = attr.getValue();
                if (value != null && !value.isEmpty() && (Booleanvalue.get(0)) {
                    adAttrs.put(
                            new BasicAttribute(..));
                }
            } else if (attr.is(.)) {
                final List<Objectvalue = attr.getValue();
                if (value != null && !value.isEmpty() && (Booleanvalue.get(0)) {
                    adAttrs.put(
                            new BasicAttribute(..));
                }
            } else if (LdapConstants.isLdapGroups(attr.getName())) {
                ldapGroups = checkedListByFilter(nullAsEmpty(attr.getValue()), String.class);
            } else if (attr.is(.)) {
                pwdAttr = ADGuardedPasswordAttribute.create(.getConfiguration().getPasswordAttribute(), attr);
            } else if (attr.is() && .is(.)) {
                uacValue = attr.getValue() == null || attr.getValue().isEmpty()
                        ? -1
                        : Integer.parseInt(attr.getValue().get(0).toString());
            } else if (attr.is(.)
                    && .is(.)
                    && uacValue == -1) {
                if (attr.getValue() == null
                        || attr.getValue().isEmpty()
                        || Boolean.parseBoolean(attr.getValue().get(0).toString())) {
                    uacValue = ;
                } else {
                    uacValue =  + ;
                }
            } else {
                javax.naming.directory.Attribute ldapAttr = .getSchemaMapping().encodeAttribute(attr);
                // Do not send empty attributes. 
                if (ldapAttr != null && ldapAttr.size() > 0) {
                    adAttrs.put(ldapAttr);
                }
            }
        }
        final String[] entryDN = new String[1];
        final String pwdAttrName = .getConfiguration().getPasswordAttribute();
        if (.is(.)) {
            if (pwdAttr != null) {
                pwdAttr.access(new Accessor() {
                    @Override
                    public void access(BasicAttribute attr) {
                        try {
                            if (attr.get() != null && !attr.get().toString().isEmpty()) {
                                adAttrs.put(attr);
                            }
                        } catch (NamingException e) {
                            .error(e"Error retrieving password value");
                        }
                    }
                });
            }
            if (adAttrs.get(pwdAttrName) != null) {
                adAttrs.put("userAccountControl", Integer.toString(uacValue));
            } else {
                adAttrs.put("userAccountControl", Integer.toString( + ));
            }
        }
        entryDN[0] = .getSchemaMapping().create(nameadAttrs);
        if (!isEmpty(ldapGroups)) {
            .addLdapGroupMemberships(entryDN[0], ldapGroups);
        }
        return .getSchemaMapping().createUid(entryDN[0]);
    }
New to GrepCode? Check out our FAQ X