Skip to content

Commit

Permalink
fix(jans-config-api): LDAP test endpoint fix (#1320)
Browse files Browse the repository at this point in the history
* feat(jans-config-api): fixed LDAP test endpoint

* feat(jans-config-api): ldap test endpoint fix
  • Loading branch information
pujavs authored May 11, 2022
1 parent 80f33a2 commit fb0e132
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
16 changes: 4 additions & 12 deletions jans-config-api/profiles/local/test.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#LOCAL
test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/config/acrs.write https://jans.io/oauth/config/attributes.readonly https://jans.io/oauth/config/attributes.write https://jans.io/oauth/config/attributes.delete https://jans.io/oauth/config/cache.readonly https://jans.io/oauth/config/cache.write https://jans.io/oauth/config/openid/clients.readonly https://jans.io/oauth/config/openid/clients.write https://jans.io/oauth/config/openid/clients.delete https://jans.io/oauth/jans-auth-server/config/properties.readonly https://jans.io/oauth/jans-auth-server/config/properties.write https://jans.io/oauth/config/smtp.readonly https://jans.io/oauth/config/smtp.write https://jans.io/oauth/config/smtp.delete https://jans.io/oauth/config/database/couchbase.readonly https://jans.io/oauth/config/database/couchbase.write https://jans.io/oauth/config/database/couchbase.delete https://jans.io/oauth/config/scripts.readonly https://jans.io/oauth/config/scripts.write https://jans.io/oauth/config/scripts.delete https://jans.io/oauth/config/fido2.readonly https://jans.io/oauth/config/fido2.write https://jans.io/oauth/config/jwks.readonly https://jans.io/oauth/config/jwks.write https://jans.io/oauth/config/database/ldap.readonly https://jans.io/oauth/config/database/ldap.write https://jans.io/oauth/config/database/ldap.delete https://jans.io/oauth/config/logging.readonly https://jans.io/oauth/config/logging.write https://jans.io/oauth/config/scopes.readonly https://jans.io/oauth/config/scopes.write https://jans.io/oauth/config/scopes.delete https://jans.io/oauth/config/uma/resources.readonly https://jans.io/oauth/config/uma/resources.write https://jans.io/oauth/config/uma/resources.delete https://jans.io/oauth/config/database/sql.readonly https://jans.io/oauth/config/database/sql.write https://jans.io/oauth/config/database/sql.delete https://jans.io/oauth/config/stats.readonly jans_stat https://jans.io/scim/users.read https://jans.io/scim/users.write https://jans.io/oauth/config/scim/users.read https://jans.io/oauth/config/scim/users.write https://jans.io/scim/config.readonly https://jans.io/scim/config.write https://jans.io/oauth/config/organization.readonly https://jans.io/oauth/config/organization.write https://jans.io/oauth/config/user.readonly https://jans.io/oauth/config/user.write https://jans.io/oauth/config/user.delete

# Test env Setting
#token.endpoint=https://jenkins-config-api.gluu.org/jans-auth/restv1/token
#token.grant.type=client_credentials
#test.client.id=1801.f35446a2-b9cb-40af-a26e-c1221f3ca0cb
#test.client.secret=lye8TNJmNpze
#test.issuer=https://jenkins-config-api.gluu.org

# Local Setting
# jans.server
token.endpoint=https://jans.server1/jans-auth/restv1/token
token.endpoint=https://jans.server2/jans-auth/restv1/token
token.grant.type=client_credentials
test.client.id=1800.8af1e2d8-f3be-4905-9f3f-710867fb1ed1
test.client.secret=7JPDywnYrEhN
test.issuer=https://jans.server1
test.client.id=1800.d254faba-2788-4cfa-8ecb-f4f9b9d7b143
test.client.secret=mKYRKfZQHL6R
test.issuer=https://jans.server2
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
@Consumes(MediaType.APPLICATION_JSON)
public class LdapConfigurationResource extends ConfigBaseResource {

@Inject
Logger log;

@Inject
LdapConfigurationService ldapConfigurationService;

Expand All @@ -58,11 +55,12 @@ public Response getLdapConfigurationByName(@PathParam(ApiConstants.NAME) String
@POST
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_LDAP_WRITE_ACCESS })
public Response addLdapConfiguration(@Valid @NotNull GluuLdapConfiguration ldapConfiguration) {
log.debug("LDAP configuration to be added - ldapConfiguration = " + ldapConfiguration);
logger.debug("LDAP configuration to be added - ldapConfiguration:{} ", ldapConfiguration);
// Ensure that an LDAP server with same name does not exists.
try {
ldapConfiguration = findLdapConfigurationByName(ldapConfiguration.getConfigId());
log.error("Ldap Configuration with same name '" + ldapConfiguration.getConfigId() + "' already exists!");
logger.error("Ldap Configuration with same name:{} already exists!", ldapConfiguration.getConfigId());

throw new NotAcceptableException(getNotAcceptableException(
"Ldap Configuration with same name - '" + ldapConfiguration.getConfigId() + "' already exists!"));
} catch (NotFoundException ne) {
Expand All @@ -75,7 +73,7 @@ public Response addLdapConfiguration(@Valid @NotNull GluuLdapConfiguration ldapC
@PUT
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_LDAP_WRITE_ACCESS })
public Response updateLdapConfiguration(@Valid @NotNull GluuLdapConfiguration ldapConfiguration) {
log.debug("LDAP configuration to be updated - ldapConfiguration = " + ldapConfiguration);
logger.debug("LDAP configuration to be updated - ldapConfiguration:{}", ldapConfiguration);
findLdapConfigurationByName(ldapConfiguration.getConfigId());
this.ldapConfigurationService.update(ldapConfiguration);
return Response.ok(ldapConfiguration).build();
Expand All @@ -85,9 +83,10 @@ public Response updateLdapConfiguration(@Valid @NotNull GluuLdapConfiguration ld
@Path(ApiConstants.NAME_PARAM_PATH)
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_LDAP_DELETE_ACCESS })
public Response deleteLdapConfigurationByName(@PathParam(ApiConstants.NAME) String name) {
log.debug("LDAP configuration to be deleted - name = " + name);
logger.debug("LDAP configuration to be deleted - name:{}",name);
findLdapConfigurationByName(name);
log.info("Delete Ldap Configuration by name " + name);

logger.info("Deleting Ldap Configuration by name:{}",name);
this.ldapConfigurationService.remove(name);
return Response.noContent().build();
}
Expand All @@ -98,9 +97,10 @@ public Response deleteLdapConfigurationByName(@PathParam(ApiConstants.NAME) Stri
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_LDAP_WRITE_ACCESS })
public Response patchLdapConfigurationByName(@PathParam(ApiConstants.NAME) String name,
@NotNull String requestString) throws JsonPatchException, IOException {
log.debug("LDAP configuration to be patched - name = " + name + " , requestString = " + requestString);
logger.debug("LDAP configuration to be patched - name:{}, requestString:{} ", name , requestString);
GluuLdapConfiguration ldapConfiguration = findLdapConfigurationByName(name);
log.info("Patch Ldap Configuration by name " + name);

logger.info("Patch Ldap Configuration by name:{} ",name);
ldapConfiguration = Jackson.applyPatch(requestString, ldapConfiguration);
this.ldapConfigurationService.update(ldapConfiguration);
return Response.ok(ldapConfiguration).build();
Expand All @@ -110,18 +110,18 @@ public Response patchLdapConfigurationByName(@PathParam(ApiConstants.NAME) Strin
@Path(ApiConstants.TEST)
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_LDAP_READ_ACCESS })
public Response testLdapConfigurationByName(@Valid @NotNull GluuLdapConfiguration ldapConfiguration) {
log.debug("LDAP configuration to be tested - ldapConfiguration = " + ldapConfiguration);
log.info("Test ldapConfiguration " + ldapConfiguration);
logger.debug("LDAP configuration to be tested - ldapConfiguration:{}", ldapConfiguration);

boolean status = connectionStatus.isUp(ldapConfiguration);
log.info("\n\n\n LdapConfigurationResource:::testLdapConfigurationByName() - status = " + status + "\n\n\n");
return Response.ok(status).build();
logger.info("\n\n\n LdapConfigurationResource:::testLdapConfigurationByName() - status:{}" ,status);
return Response.ok(status).build();
}

private GluuLdapConfiguration findLdapConfigurationByName(String name) {
try {
return this.ldapConfigurationService.findByName(name);
} catch (NoSuchElementException ex) {
log.error("Could not find Ldap Configuration by name '" + name + "'", ex);
logger.error("Could not find Ldap Configuration by name '" + name + "'", ex);
throw new NotFoundException(getNotFoundError("Ldap Configuration - '" + name + "'"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,37 @@ public class ConnectionStatus {
ConfigurationFactory configurationFactory;

public boolean isUp(GluuLdapConfiguration ldapConfiguration) {

FileConfiguration configuration = loadFileConfiguration();
logger.debug(
" configuration:{}, ldapConfiguration:{}, ldapConfiguration.getBindDN():{}, ldapConfiguration.getBindPassword()):{}, ldapConfiguration.isUseSSL():{} ",
configuration, ldapConfiguration, ldapConfiguration.getBindDN(), ldapConfiguration.getBindPassword(),
ldapConfiguration.isUseSSL());

Properties properties = configuration.getProperties();
properties.setProperty("bindDN", ldapConfiguration.getBindDN());
properties.setProperty("bindPassword", ldapConfiguration.getBindPassword());
properties.setProperty("servers", buildServersString(getServers(ldapConfiguration)));
properties.setProperty("useSSL", Boolean.toString(ldapConfiguration.isUseSSL()));

Properties ldapDecryptedProperties = PropertiesDecrypter.decryptProperties(properties,
configurationFactory.getCryptoConfigurationSalt());

logger.trace("Attempting to create LDAP connection with properties: {}", ldapDecryptedProperties);

LdapConnectionProvider connectionProvider = new LdapConnectionProvider(
PropertiesDecrypter.decryptProperties(properties, configurationFactory.getCryptoConfigurationSalt()));

if (connectionProvider.getConnectionPool() != null) {
boolean isConnected = connectionProvider.isConnected();
logger.trace("connectionProvider: {}", connectionProvider);
connectionProvider.create(ldapDecryptedProperties);

logger.debug("Connection status connectionProvider.isConnected(): {}", connectionProvider.isConnected());

if (connectionProvider.isConnected()) {
logger.trace("Connect to LDAP");
connectionProvider.closeConnectionPool();
return isConnected;
return true;
}

return false;
}

Expand Down

0 comments on commit fb0e132

Please sign in to comment.