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

See also:
org.identityconnectors.ldap.LdapConnector
 
 @ConnectorClass(configurationClass = ADConfiguration.class,
         displayNameKey = "ADConnector")
 public class ADConnector extends LdapConnector {
 
     private static final Log LOG = Log.getLog(ADConnector.class);
 
     public static final String OBJECTGUID = "objectGUID";
     
     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);
        if (oclass.is(.)) {
            final Attribute ldapGroups = AttributeUtil.find(.attributes);
            final Set<StringldapGroupsToBeAdded = new HashSet<String>();
            if (ldapGroups != null) {
                attributes.remove(ldapGroups);
                ldapGroupsToBeAdded.addAll(ldapGroups.getValue() == null
                        ? Collections.<String>emptyList()
                        : Arrays.asList(ldapGroups.getValue().toArray(new String[ldapGroups.getValue().size()])));
            }
            ldapGroupsToBeAdded.addAll(.getMemberships() == null
                    ? Collections.<String>emptyList() : 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,
            final 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);
            if (ldapGroups != null && oclass.is(.)) {
                attributes.remove(ldapGroups);
                final Set<StringldapGroupsToBeAdded = new HashSet<String>(
                        ldapGroups.getValue() == null
                        ? Collections.<String>emptyList()
                        : Arrays.asList(ldapGroups.getValue().toArray(new String[ldapGroups.getValue().size()])));
                ldapGroupsToBeAdded.addAll(.getMemberships() == null
                        ? Collections.<String>emptyList() : Arrays.asList(.getMemberships()));
                // add groups
                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