Skip to content

Commit

Permalink
Updating ConnId Base
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed May 2, 2022
1 parent 4bd87ad commit 206663a
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 285 deletions.
19 changes: 11 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>net.tirasa.connid</groupId>
<artifactId>connid</artifactId>
<version>1.4.5.1</version>
<version>1.5.1.0</version>
</parent>

<groupId>net.tirasa.connid.bundles</groupId>
Expand Down Expand Up @@ -76,8 +76,8 @@
</mailingLists>

<properties>
<connid.version>1.4.5.1</connid.version>
<connid.ldap.version>1.5.4</connid.ldap.version>
<connid.version>1.5.1.0</connid.version>
<connid.ldap.version>1.5.5</connid.ldap.version>
<adsddl.verson>1.9</adsddl.verson>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -117,8 +117,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -230,9 +231,11 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<descriptor>src/assemble/connector.xml</descriptor>
</descriptors>
Expand All @@ -243,8 +246,8 @@
<ConnectorBundle-Name>${project.artifactId}</ConnectorBundle-Name>
<ConnectorBundle-Version>${project.version}</ConnectorBundle-Version>
</manifestEntries>
</archive>
</configuration>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
Expand Down
42 changes: 18 additions & 24 deletions src/assemble/connector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
limitations under the License.
-->
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
http://maven.apache.org/xsd/assembly-1.1.0.xsd">
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>connector</id>
<id>bundle</id>

<formats>
<format>jar</format>
Expand All @@ -31,27 +31,21 @@

<fileSets>
<fileSet>
<directory>target/classes</directory>
<directory>${project.build.directory}/classes</directory>
<outputDirectory></outputDirectory>
</fileSet>

<fileSet>
<directory>${basedir}</directory>
<includes>
<include>LICENSE</include>
</includes>
<outputDirectory>META-INF</outputDirectory>
</fileSet>
</fileSets>

<dependencySets>
<dependencySet>
<includes>
<include>net.tirasa.connid.bundles:net.tirasa.connid.bundles.ldap</include>
<include>net.tirasa:adsddl</include>
</includes>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>


<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
<excludes>
<exclude>net.tirasa.connid:connector-framework</exclude>
<exclude>net.tirasa.connid:connector-framework-internal</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
44 changes: 16 additions & 28 deletions src/main/java/net/tirasa/connid/bundles/ad/ADConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.sun.jndi.ldap.ctl.PasswordExpiredResponseControl;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import javax.naming.AuthenticationException;
import javax.naming.Context;
Expand Down Expand Up @@ -65,7 +66,6 @@ public ADConnection(ADConfiguration config) {

@Override
public AuthenticationResult authenticate(final String entryDN, final GuardedString password) {

assert entryDN != null;

if (LOG.isOk()) {
Expand Down Expand Up @@ -109,12 +109,11 @@ private LdapContext cloneContext(final Control[] control) {
LdapContext ctx = null;

try {
@SuppressWarnings({ "UseOfObsoleteCollectionType", "rawtypes", "unchecked" })
final java.util.Hashtable env = new java.util.Hashtable(getInitialContext().getEnvironment());
@SuppressWarnings("UseOfObsoleteCollectionType")
final Hashtable<Object, Object> env = new Hashtable<>();

ctx = new InitialLdapContext(env, null);
ctx.setRequestControls(control);

} catch (NamingException e) {
LOG.error(e, "Context initialization failed");
}
Expand Down Expand Up @@ -167,11 +166,10 @@ private LdapContext connect(String principal, GuardedString credentials) {
private Pair<AuthenticationResult, LdapContext> createContext(
final String principal, final GuardedString credentials) {

final List<Pair<AuthenticationResult, LdapContext>> result
= new ArrayList<Pair<AuthenticationResult, LdapContext>>(1);
final List<Pair<AuthenticationResult, LdapContext>> result = new ArrayList<>(1);

@SuppressWarnings("UseOfObsoleteCollectionType")
final java.util.Hashtable<Object, Object> env = new java.util.Hashtable<Object, Object>();
final Hashtable<Object, Object> env = new Hashtable<>();

env.put(Context.INITIAL_CONTEXT_FACTORY, LDAP_CTX_FACTORY);
env.put(Context.PROVIDER_URL, getLdapUrls());
Expand Down Expand Up @@ -201,15 +199,11 @@ private Pair<AuthenticationResult, LdapContext> createContext(
env.put(Context.SECURITY_PRINCIPAL, principal);

if (credentials != null) {
credentials.access(new Accessor() {

@Override
public void access(char[] clearChars) {
if(clearChars == null || clearChars.length == 0){
throw new InvalidCredentialException("Password is blank");
}
env.put(Context.SECURITY_CREDENTIALS, new String(clearChars));
credentials.access(clearChars -> {
if (clearChars == null || clearChars.length == 0) {
throw new InvalidCredentialException("Password is blank");
}
env.put(Context.SECURITY_CREDENTIALS, new String(clearChars));
});
}
}
Expand All @@ -221,7 +215,7 @@ public void access(char[] clearChars) {

private Pair<AuthenticationResult, LdapContext> createContext(
@SuppressWarnings("UseOfObsoleteCollectionType")
final java.util.Hashtable<?, ?> env) {
final Hashtable<?, ?> env) {

AuthenticationResult authnResult = null;
InitialLdapContext context = null;
Expand All @@ -235,34 +229,28 @@ private Pair<AuthenticationResult, LdapContext> createContext(
AuthenticationResultType.PASSWORD_EXPIRED);
}
}

} catch (AuthenticationException e) {
// TODO: check AD response
String message = e.getMessage().toLowerCase();
if (message.contains("password expired")) { // Sun DS.
authnResult = new AuthenticationResult(
AuthenticationResultType.PASSWORD_EXPIRED, e);
authnResult = new AuthenticationResult(AuthenticationResultType.PASSWORD_EXPIRED, e);
} else if (message.contains("password has expired")) { // RACF.
authnResult = new AuthenticationResult(
AuthenticationResultType.PASSWORD_EXPIRED, e);
authnResult = new AuthenticationResult(AuthenticationResultType.PASSWORD_EXPIRED, e);
} else {
authnResult = new AuthenticationResult(
AuthenticationResultType.FAILED, e);
authnResult = new AuthenticationResult(AuthenticationResultType.FAILED, e);
}

} catch (NamingException e) {
authnResult = new AuthenticationResult(
AuthenticationResultType.FAILED, e);
authnResult = new AuthenticationResult(AuthenticationResultType.FAILED, e);
}

if (authnResult == null) {
assert context != null;

authnResult = new AuthenticationResult(
AuthenticationResultType.SUCCESS);
authnResult = new AuthenticationResult(AuthenticationResultType.SUCCESS);
}

return new Pair<AuthenticationResult, LdapContext>(authnResult, context);
return new Pair<>(authnResult, context);
}

private static boolean hasPasswordExpiredControl(final Control[] controls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
Expand All @@ -31,7 +32,6 @@
import javax.naming.ldap.SortControl;
import net.tirasa.connid.bundles.ldap.search.LdapSearchResultsHandler;
import net.tirasa.connid.bundles.ldap.search.PagedSearchStrategy;
import org.identityconnectors.common.Base64;
import org.identityconnectors.common.StringUtil;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.framework.common.exceptions.ConnectorException;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void doSearch(
// bit of sanity check...
if (split.length == 2) {
try {
cookie = Base64.decode(split[0]);
cookie = Base64.getDecoder().decode(split[0]);
} catch (RuntimeException e) {
throw new ConnectorException("PagedResultsCookie is not properly encoded", e);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public void doSearch(

String returnedCookie = null;
if (cookie != null) {
returnedCookie = Base64.encode(cookie).concat(":" + context);
returnedCookie = Base64.getEncoder().encodeToString(cookie).concat(":" + context);
}

if (searchResultHandler != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.tirasa.connid.bundles.ad.util;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import java.util.List;
import javax.naming.directory.BasicAttribute;
Expand Down Expand Up @@ -73,25 +74,12 @@ private Simple(String attrName, GuardedString password) {

@Override
public void access(final Accessor accessor) {
password.access(new GuardedString.Accessor() {
password.access(clearChars -> {
final String quotedPwd = "\"" + new String(clearChars) + "\"";

@Override
public void access(char[] clearChars) {
final String quotedPwd = "\"" + new String(clearChars) + "\"";

try {

byte[] unicodePwd = quotedPwd.getBytes("UTF-16LE");

final BasicAttribute attr =
new BasicAttribute(attrName, unicodePwd);

accessor.access(attr);

} catch (UnsupportedEncodingException e) {
LOG.error(e, "Error encoding password");
}
}
byte[] unicodePwd = quotedPwd.getBytes(Charset.forName("UTF-16LE"));
final BasicAttribute attr = new BasicAttribute(attrName, unicodePwd);
accessor.access(attr);
});
}
}
Expand All @@ -109,4 +97,4 @@ public void access(Accessor accessor) {
accessor.access(new BasicAttribute(attrName));
}
}
}
}
8 changes: 5 additions & 3 deletions src/test/java/net/tirasa/connid/bundles/ad/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package net.tirasa.connid.bundles.ad;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -188,9 +190,9 @@ public static class TestSyncResultsHandler implements SyncResultsHandler {

SyncToken latestReceivedToken = null;

final List<SyncDelta> updated = new ArrayList<SyncDelta>();
final List<SyncDelta> updated = new ArrayList<>();

final List<SyncDelta> deleted = new ArrayList<SyncDelta>();
final List<SyncDelta> deleted = new ArrayList<>();

@Override
public boolean handle(final SyncDelta sd) {
Expand Down
18 changes: 7 additions & 11 deletions src/test/java/net/tirasa/connid/bundles/ad/BasicFeaturesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@
*/
package net.tirasa.connid.bundles.ad;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import net.tirasa.connid.bundles.ad.util.ADUtilities;
import net.tirasa.connid.bundles.ad.util.DirSyncUtils;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.common.security.GuardedString;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class BasicFeaturesTest {

/**
* Setup logging for the {@link DatabaseTableConnector}.
*/
private static final Log LOG = Log.getLog(BasicFeaturesTest.class);

private static ADConnector connector;

@BeforeClass
@BeforeAll
public static void init() {

final ADConfiguration conf = new ADConfiguration();
conf.setObjectClassesToSynchronize("user");
conf.setAccountSearchFilter("");
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/net/tirasa/connid/bundles/ad/GroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
package net.tirasa.connid.bundles.ad;

import org.identityconnectors.framework.common.objects.ObjectClass;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

public class GroupTest extends AbstractTest {

protected static TestUtil util;

@BeforeClass
@BeforeAll
public static void init() {
AbstractTest.init();
util = new TestUtil(connector, conf, ObjectClass.GROUP, BASE_CONTEXT);
AbstractTest.baseSetup(util);
}

@AfterClass
@AfterAll
public static void cleanup() {
AbstractTest.cleanup(util);
}
Expand Down
Loading

0 comments on commit 206663a

Please sign in to comment.