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;
 
 import java.util.Set;
All-java, agent-less Active Directory connector, extending LDAP connector.

 
 @ConnectorClass(configurationClass = ADConfiguration.class,
         displayNameKey = "ADConnector")
 public class ADConnector extends LdapConnector {
 
     private static final Log LOG = Log.getLog(ADConnector.class);
 
     public static final String UACCONTROL_ATTR = "userAccountControl";
 
     //some useful constants from lmaccess.h
     public static final int UF_ACCOUNTDISABLE = 0x0002;
 
     public static final int UF_PASSWD_NOTREQD = 0x0020;
 
     public static final int UF_PASSWD_CANT_CHANGE = 0x0040;
 
     public static final int UF_NORMAL_ACCOUNT = 0x0200;
 
     public static final int UF_DONT_EXPIRE_PASSWD = 0x10000;
 
     public static final int UF_PASSWORD_EXPIRED = 0x800000;

    
The configuration for this connector instance.
 
     private transient ADConfiguration config;

    
The relative DirSyncSyncStrategy instance which sync-related operations are delegated to.
 
     private transient ADSyncStrategy syncStrategy;

    
The connection to the AD server.
 
     private transient ADConnection conn;
 
     @Override
     public Configuration getConfiguration() {
         return ;
     }
 
    @Override
    public void init(final Configuration cfg) {
         = (ADConfigurationcfg;
        // TODO: easier and more efficient if conn was protected in superclass
         = new ADConnection();
         = new ADSyncStrategy();
        super.init(cfg);
    }
    @Override
    public void dispose() {
        .close();
        super.dispose();
    }
    @Override
    public void executeQuery(
            final ObjectClass oclass,
            final LdapFilter query,
            final ResultsHandler handler,
            final OperationOptions options) {
        new ADSearch(oclassqueryoptions).executeADQuery(handler);
    }
    @Override
    public SyncToken getLatestSyncToken(final ObjectClass oclass) {
        return .getLatestSyncToken();
    }
    @Override
    public void sync(final ObjectClass oclassfinal SyncToken token,
            final SyncResultsHandler handlerfinal OperationOptions options) {
        .sync(tokenhandleroptionsoclass);
    }
    @Override
    public Uid create(
            final ObjectClass oclass,
            final Set<Attributeattrs,
            final OperationOptions options) {
        if (ADConfiguration.class.cast(.getConfiguration()).isPwdUpdateOnly()) {
            throw new IllegalStateException("Create operation not permitted");
        }
        final Set<Attributeattributes = new HashSet<Attribute>(attrs);
        final Attribute ldapGroups = AttributeUtil.find(.attributes);
        final Set<StringldapGroupsToBeAdded = new HashSet<String>();
        if (ldapGroups != null) {
            attributes.remove(ldapGroups);
            ldapGroupsToBeAdded.addAll(ldapGroups.getValue() == null ? . : ldapGroups.getValue());
        }
        ldapGroupsToBeAdded.addAll(
                .getMemberships() == null ? . : Arrays.asList(.getMemberships()));
        // add groups
        attributes.add(AttributeBuilder.build("ldapGroups"ldapGroupsToBeAdded));
        return new ADCreate(oclassattributesoptions).create();
    }
    @Override
    public Uid update(
            final ObjectClass oclass,
            final Uid uid,
            Set<Attributeattrs,
            final OperationOptions options) {
        final Set<Attributeattributes = new HashSet<Attribute>();
        if (ADConfiguration.class.cast(.getConfiguration()).isPwdUpdateOnly()) {
            final Attribute pwd = AttributeUtil.find(.attrs);
            if (pwd != null) {
                attributes.add(pwd);
            }
        } else {
            attributes.addAll(attrs);
            final Attribute ldapGroups = AttributeUtil.find(.attributes);
            final Set<StringldapGroupsToBeAdded = new HashSet<String>();
            if (ldapGroups != null && oclass.is(.)) {
                attributes.remove(ldapGroups);
                ldapGroupsToBeAdded.addAll(ldapGroups.getValue() == null ? . : ldapGroups.
                        getValue());
                ldapGroupsToBeAdded.addAll(
                        .getMemberships() == null ? . : Arrays.
                        asList(.getMemberships()));
                attributes.add(AttributeBuilder.build("ldapGroups"ldapGroupsToBeAdded));
            }
        }
        return new ADUpdate(oclassuid).update(attributes);
    }
    @Override
    public void delete(
            final ObjectClass oclass,
            final Uid uid,
            final OperationOptions options) {
        if (ADConfiguration.class.cast(.getConfiguration()).isPwdUpdateOnly()) {
            throw new IllegalStateException("Delete operation not permitted");
        }
        new ADDelete(oclassuid).delete();
    }
    @Override
    public Schema schema() {
        return .getADSchema().getSchema();
    }
    @Override
    public Uid authenticate(
            final ObjectClass objectClass,
            final String username,
            final GuardedString password,
            final OperationOptions options) {
        return new ADAuthenticate(objectClassusernameoptions).authenticate(password);
    }
    @Override
    public Uid resolveUsername(
            final ObjectClass objectClass,
            final String username,
            final OperationOptions options) {
        return new ADAuthenticate(objectClassusernameoptions).resolveUsername();
    }
    @Override
    public void test() {
        .test();
    }
    @Override
    public void checkAlive() {
        .checkAlive();
    }
New to GrepCode? Check out our FAQ X