Skip to content

Commit

Permalink
[#11] provides dir sync control test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartelli committed Aug 23, 2018
1 parent 833459d commit e08ca59
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 69 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<slf4j.version>1.7.10</slf4j.version>
<log4j.version>2.1</log4j.version>
<disruptor.version>3.3.0</disruptor.version>
<commons-lang3.version>3.7</commons-lang3.version>
<commons.logging.version>1.2</commons.logging.version>
<commons.io.version>1.3.2</commons.io.version>
<xml.apis.version>1.4.01</xml.apis.version>
Expand Down Expand Up @@ -118,6 +119,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/net/tirasa/adsddl/ntsd/controls/DirSyncControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
*/
public class DirSyncControl extends BasicControl {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(DirSyncControl.class);

private static final long serialVersionUID = -930993758829518418L;

/**
Expand All @@ -54,8 +49,12 @@ public class DirSyncControl extends BasicControl {

/**
* LDAP_DIRSYNC_INCREMENTAL_VALUES | LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER | LDAP_DIRSYNC_OBJECT_SECURITY
* LDAP_DIRSYNC_OBJECT_SECURITY: 0x00000001
* LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER: 0x00000800
* LDAP_DIRSYNC_PUBLIC_DATA_ONLY: 0x00002000
* LDAP_DIRSYNC_INCREMENTAL_VALUES: 0x80000000
*/
private final int flags = 0x80000801;
private int flags = 0x80000801;

/**
* Constructor.
Expand Down Expand Up @@ -105,4 +104,9 @@ private byte[] berEncodedValue(byte[] cookie) {
}
return buff.array();
}

public DirSyncControl setFlags(final int flags) {
this.flags = flags;
return this;
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/tirasa/adsddl/ntsd/controls/NotifyControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2015 Tirasa ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.tirasa.adsddl.ntsd.controls;

import javax.naming.ldap.BasicControl;

/**
* The LDAP_SERVER_NOTIFICATION_OID control is used with an extended LDAP asynchronous search function to register the
* client to be notified when changes are made to an object in Active Directory.
*/
public class NotifyControl extends BasicControl {

private static final long serialVersionUID = -930993758829518420L;

/**
* LDAP_SERVER_NOTIFICATION_OID.
*/
public static final String OID = "1.2.840.113556.1.4.528";

/**
* Constructor.
*/
public NotifyControl() {
super(OID, true, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class SDFlagsControl extends BasicControl {
/**
* SD Flags Control:
* OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION.
* OWNER_SECURITY_INFORMATION: 0x00000001
* GROUP_SECURITY_INFORMATION: 0x00000002
* DACL_SECURITY_INFORMATION: 0x00000004
* SACL_SECURITY_INFORMATION: 0x00000008
*/
private final int flags;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 Tirasa ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.tirasa.adsddl.ntsd.controls;

import java.nio.ByteBuffer;
import javax.naming.ldap.BasicControl;
import net.tirasa.adsddl.ntsd.utils.NumberFacility;

/**
* Active Directory directory synchronization (DirSync) control is an LDAP server extension that enables an application
* to search an directory partition for objects that have changed since a previous state.
* When you perform a DirSync search, you pass in a provider-specific data element (cookie) that identifies the
* directory state at the time of the previous DirSync search. For the first search, you pass in a null cookie, and the
* search returns all objects that match the filter. The search also returns a valid cookie. Store the cookie in the
* same storage that you are synchronizing with the Active Directory server. On subsequent searches, get the cookie from
* storage and pass it with the search request. The search results now include only the objects and attributes that have
* changed since the previous state identified by the cookie. The search also returns a new cookie to store for the next
* search.
*/
public class SearchOptionsControl extends BasicControl {

private static final long serialVersionUID = -930993758829518418L;

/**
* LDAP_SERVER_SEARCH_OPTIONS_OID.
* Directory synchronization control.
*/
public static final String OID = "1.2.840.113556.1.4.1340";

/**
* LDAP_DIRSYNC_INCREMENTAL_VALUES | LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER | LDAP_DIRSYNC_OBJECT_SECURITY
* LDAP_DIRSYNC_OBJECT_SECURITY: 1
* LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER: 0x00000800
* LDAP_DIRSYNC_PUBLIC_DATA_ONLY: 0x00002000
* LDAP_DIRSYNC_INCREMENTAL_VALUES: 0x80000000
*/
private final int flags = 0x80000801;

/**
* Constructor.
*/
public SearchOptionsControl() {
super(OID, true, null);
this.value = berEncodedValue();
}

/**
* BER encode the flags.
*
* @return flags BER encoded.
*/
private byte[] berEncodedValue() {
final ByteBuffer buff = ByteBuffer.allocate(8);
buff.put((byte) 0x30); // (Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
buff.put((byte) 0x06); // size
buff.put((byte) 0x02); // 4bytes int tag
buff.put((byte) 0x04); // int size
buff.put(NumberFacility.leftTrim(NumberFacility.getBytes(flags))); // value
return buff.array();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2015 Tirasa ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.tirasa.adsddl.ntsd.controls;

import javax.naming.ldap.BasicControl;

/**
* The LDAP_SERVER_SHOW_DELETED_OID control is used with an extended LDAP search function to specify that the search
* results include any deleted objects that match the search filter.
*/
public class ShowDeletedControl extends BasicControl {

private static final long serialVersionUID = -930993758829518419L;

/**
* LDAP_SERVER_SHOW_DELETED_OID.
*/
public static final String OID = "1.2.840.113556.1.4.417";

/**
* Constructor.
*/
public ShowDeletedControl() {
super(OID, true, null);
}
}
36 changes: 20 additions & 16 deletions src/main/java/net/tirasa/adsddl/ntsd/data/AceRights.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,27 @@ public static enum ObjectRight {
* ADS_RIGHT_DS_CONTROL_ACCESS - The ObjectType GUID identifies an extended access right.
*/
CR(0x00000100),

/**
* ADS_RIGHT_DS_WRITE_PROP - The ObjectType GUID identifies a property set or property of the object.
* The ACE controls the trustee's right to write the property or property set.
*/
WP(0x00000020);
// FA(0x001F01FF),
// FX(0x001200A0),
// FW(0x00100116),
// FR(0x00120089),
// KA(0x00000019),
// KR(0x0000003F),
// KX(0x00000019),
// KW(0x00000006),
// LO(0x00000080),
// DT(0x00000040),
// RP(0x00000010),
// SW(0x00000008),
// LC(0x00000004),
// DC(0x00000002),
// CC(0x00000001);

// FA(0x001F01FF),
// FX(0x001200A0),
// FW(0x00100116),
// FR(0x00120089),
// KA(0x00000019),
// KR(0x0000003F),
// KX(0x00000019),
// KW(0x00000006),
// LO(0x00000080),
// DT(0x00000040),
// RP(0x00000010),
// SW(0x00000008),
// LC(0x00000004),
// DC(0x00000002),
// CC(0x00000001);

private final int value;

Expand Down
6 changes: 4 additions & 2 deletions src/test/java/net/tirasa/adsddl/it/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public abstract class AbstractTest extends net.tirasa.adsddl.unit.AbstractTest {

protected static String searchFilter;

protected static Properties prop;

@BeforeClass
@SuppressWarnings("unchecked")
public static void setUpConnection() throws IOException {
final Properties prop = new Properties();
prop = new Properties();
prop.load(AbstractTest.class.getResourceAsStream("/conf.properties"));

@SuppressWarnings({ "UseOfObsoleteCollectionType", "rawtypes" })
Expand All @@ -64,7 +66,7 @@ public static void setUpConnection() throws IOException {
// Create the initial directory context
ctx = new InitialLdapContext(env, null);
} catch (NamingException e) {
log.error("Error initializing test context", e);
LOG.error("Error initializing test context", e);
Assert.fail(e.getMessage());
}

Expand Down
Loading

0 comments on commit e08ca59

Please sign in to comment.