Skip to content

Commit

Permalink
Add support for NetIQ as a LDAP backend (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Dor authored Mar 2, 2018
1 parent ea08a80 commit a278580
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 307 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ dependencies {
compile 'commons-io:commons-io:2.5'

// Spring Boot - standalone app
compile 'org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:1.5.10.RELEASE'

// Thymeleaf for HTML templates
compile "org.springframework.boot:spring-boot-starter-thymeleaf:1.5.3.RELEASE"
compile "org.springframework.boot:spring-boot-starter-thymeleaf:1.5.10.RELEASE"

// Matrix Java SDK
compile 'io.kamax:matrix-java-sdk:0.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
import io.kamax.mxisd.auth.provider.BackendAuthResult;
import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.LdapConfig;
import io.kamax.mxisd.config.ldap.generic.GenericLdapConfig;
import io.kamax.mxisd.util.GsonUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.directory.api.ldap.model.cursor.CursorException;
Expand All @@ -52,14 +52,14 @@
import java.util.Set;

@Component
public class LdapAuthProvider extends LdapGenericBackend implements AuthenticatorProvider {
public class LdapAuthProvider extends LdapBackend implements AuthenticatorProvider {

private Logger log = LoggerFactory.getLogger(LdapAuthProvider.class);

private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

@Autowired
public LdapAuthProvider(LdapConfig cfg, MatrixConfig mxCfg) {
public LdapAuthProvider(GenericLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public BackendAuthResult authenticate(_MatrixID mxid, String password) {
bind(conn);

String uidType = getAt().getUid().getType();
String userFilterValue = StringUtils.equals(LdapGenericBackend.UID, uidType) ? mxid.getLocalPart() : mxid.getId();
String userFilterValue = StringUtils.equals(LdapBackend.UID, uidType) ? mxid.getLocalPart() : mxid.getId();
if (StringUtils.isBlank(userFilterValue)) {
log.warn("Username is empty, failing auth");
return BackendAuthResult.failure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package io.kamax.mxisd.backend.ldap;

import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.LdapAttributeConfig;
import io.kamax.mxisd.config.ldap.LdapConfig;
import org.apache.commons.lang.StringUtils;
import org.apache.directory.api.ldap.model.entry.Attribute;
Expand All @@ -40,17 +39,17 @@
import java.util.List;
import java.util.Optional;

public abstract class LdapGenericBackend {
public abstract class LdapBackend {

public static final String UID = "uid";
public static final String MATRIX_ID = "mxid";

private Logger log = LoggerFactory.getLogger(LdapGenericBackend.class);
private Logger log = LoggerFactory.getLogger(LdapBackend.class);

private LdapConfig cfg;
private MatrixConfig mxCfg;

public LdapGenericBackend(LdapConfig cfg, MatrixConfig mxCfg) {
public LdapBackend(LdapConfig cfg, MatrixConfig mxCfg) {
this.cfg = cfg;
this.mxCfg = mxCfg;
}
Expand All @@ -60,10 +59,10 @@ protected LdapConfig getCfg() {
}

protected String getBaseDn() {
return cfg.getConn().getBaseDn();
return cfg.getConnection().getBaseDn();
}

protected LdapAttributeConfig getAt() {
protected LdapConfig.Attribute getAt() {
return cfg.getAttribute();
}

Expand All @@ -72,14 +71,14 @@ protected String getUidAtt() {
}

protected synchronized LdapConnection getConn() throws LdapException {
return new LdapNetworkConnection(cfg.getConn().getHost(), cfg.getConn().getPort(), cfg.getConn().isTls());
return new LdapNetworkConnection(cfg.getConnection().getHost(), cfg.getConnection().getPort(), cfg.getConnection().isTls());
}

protected void bind(LdapConnection conn) throws LdapException {
if (StringUtils.isBlank(cfg.getConn().getBindDn()) && StringUtils.isBlank(cfg.getConn().getBindPassword())) {
if (StringUtils.isBlank(cfg.getConnection().getBindDn()) && StringUtils.isBlank(cfg.getConnection().getBindPassword())) {
conn.anonymousBind();
} else {
conn.bind(cfg.getConn().getBindDn(), cfg.getConn().getBindPassword());
conn.bind(cfg.getConnection().getBindDn(), cfg.getConnection().getBindPassword());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package io.kamax.mxisd.backend.ldap;

import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.LdapAttributeConfig;
import io.kamax.mxisd.config.ldap.LdapConfig;
import io.kamax.mxisd.config.ldap.generic.GenericLdapConfig;
import io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult;
import io.kamax.mxisd.directory.IDirectoryProvider;
import io.kamax.mxisd.exception.InternalServerError;
Expand All @@ -44,12 +44,12 @@
import java.util.List;

@Component
public class LdapDirectoryProvider extends LdapGenericBackend implements IDirectoryProvider {
public class LdapDirectoryProvider extends LdapBackend implements IDirectoryProvider {

private Logger log = LoggerFactory.getLogger(LdapDirectoryProvider.class);

@Autowired
public LdapDirectoryProvider(LdapConfig cfg, MatrixConfig mxCfg) {
public LdapDirectoryProvider(GenericLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

Expand All @@ -65,7 +65,7 @@ protected UserDirectorySearchResult search(String query, List<String> attributes
try (LdapConnection conn = getConn()) {
bind(conn);

LdapAttributeConfig atCfg = getCfg().getAttribute();
LdapConfig.Attribute atCfg = getCfg().getAttribute();

attributes = new ArrayList<>(attributes);
attributes.add(getUidAtt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package io.kamax.mxisd.backend.ldap;

import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.LdapConfig;
import io.kamax.mxisd.config.ldap.generic.GenericLdapConfig;
import io.kamax.mxisd.exception.InternalServerError;
import io.kamax.mxisd.lookup.SingleLookupReply;
import io.kamax.mxisd.lookup.SingleLookupRequest;
Expand All @@ -45,11 +45,11 @@
import java.util.Optional;

@Component
public class LdapThreePidProvider extends LdapGenericBackend implements IThreePidProvider {
public class LdapThreePidProvider extends LdapBackend implements IThreePidProvider {

private Logger log = LoggerFactory.getLogger(LdapThreePidProvider.class);

public LdapThreePidProvider(LdapConfig cfg, MatrixConfig mxCfg) {
public LdapThreePidProvider(GenericLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2018 Kamax Sàrl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxisd.backend.ldap.netiq;

import io.kamax.mxisd.backend.ldap.LdapAuthProvider;
import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.netiq.NetIqLdapConfig;
import org.springframework.stereotype.Component;

@Component
public class NetIqLdapAuthProvider extends LdapAuthProvider {

public NetIqLdapAuthProvider(NetIqLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

// FIXME this is duplicated in the other NetIQ classes, due to the Matrix ID generation code that was not abstracted
@Override
public String buildMatrixIdFromUid(String uid) {
return super.buildMatrixIdFromUid(uid).toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2018 Kamax Sàrl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxisd.backend.ldap.netiq;

import io.kamax.mxisd.backend.ldap.LdapDirectoryProvider;
import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.netiq.NetIqLdapConfig;
import org.springframework.stereotype.Component;

@Component
public class NetIqLdapDirectoryProvider extends LdapDirectoryProvider {

public NetIqLdapDirectoryProvider(NetIqLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

// FIXME this is duplicated in the other NetIQ classes, due to the Matrix ID generation code that was not abstracted
@Override
public String buildMatrixIdFromUid(String uid) {
return super.buildMatrixIdFromUid(uid).toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2018 Kamax Sàrl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxisd.backend.ldap.netiq;

import io.kamax.mxisd.backend.ldap.LdapThreePidProvider;
import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ldap.netiq.NetIqLdapConfig;
import org.springframework.stereotype.Component;

@Component
public class NetIqLdapThreePidProvider extends LdapThreePidProvider {

public NetIqLdapThreePidProvider(NetIqLdapConfig cfg, MatrixConfig mxCfg) {
super(cfg, mxCfg);
}

// FIXME this is duplicated in the other NetIQ classes, due to the Matrix ID generation code that was not abstracted
@Override
public String buildMatrixIdFromUid(String uid) {
return super.buildMatrixIdFromUid(uid).toLowerCase();
}

}
62 changes: 0 additions & 62 deletions src/main/java/io/kamax/mxisd/config/ldap/LdapAttributeConfig.java

This file was deleted.

Loading

0 comments on commit a278580

Please sign in to comment.