Skip to content

Commit

Permalink
Changes in Casa core for #34 plus refactoring
Browse files Browse the repository at this point in the history
jgomer2001 committed Mar 11, 2019
1 parent b188c56 commit 11f6ad8
Showing 60 changed files with 1,441 additions and 1,450 deletions.
41 changes: 34 additions & 7 deletions app/src/main/java/org/gluu/casa/conf/LdapSettings.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* cred-manager is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2018, Gluu
*/
package org.gluu.casa.conf;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -14,26 +9,58 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class LdapSettings {

public enum BACKEND {
LDAP, COUCHBASE;

public String getValue() {
return toString().toLowerCase();
}

}

@JsonProperty("salt")
private String saltLocation;

@JsonProperty("backend_type")
private String type;

@JsonProperty("config_file")
private String configurationFile;

//This will be unused after MainSettingsProduces migrates data
@JsonProperty("ox-ldap_location")
private String oxLdapLocation;

public String getSaltLocation() {
return saltLocation;
}

public void setSaltLocation(String saltLocation) {
this.saltLocation = saltLocation;
public String getType() {
return type;
}

public String getConfigurationFile() {
return configurationFile;
}

public String getOxLdapLocation() {
return oxLdapLocation;
}

public void setSaltLocation(String saltLocation) {
this.saltLocation = saltLocation;
}

public void setOxLdapLocation(String oxLdapLocation) {
this.oxLdapLocation = oxLdapLocation;
}

public void setConfigurationFile(String configurationFile) {
this.configurationFile = configurationFile;
}

public void setType(String type) {
this.type = type;
}

}
12 changes: 7 additions & 5 deletions app/src/main/java/org/gluu/casa/conf/MainSettingsProducer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* cred-manager is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2018, Gluu
*/
package org.gluu.casa.conf;

import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -111,6 +106,13 @@ public MainSettings instance() {
//Dismiss "branding_path" contents regardless of success
settings.setBrandingPath(null);
}

LdapSettings ldapSettings = settings.getLdapSettings();
if (Utils.isNotEmpty(ldapSettings.getOxLdapLocation())) {
ldapSettings.setType(LdapSettings.BACKEND.LDAP.getValue());
ldapSettings.setConfigurationFile(ldapSettings.getOxLdapLocation());
ldapSettings.setOxLdapLocation(null);
}
} catch (Exception e) {
logger.error("Error parsing configuration file {}", CONF_FILE_RELATIVE_PATH);
logger.error(e.getMessage(), e);
15 changes: 5 additions & 10 deletions app/src/main/java/org/gluu/casa/core/ConfigurationHandler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* cred-manager is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2018, Gluu
*/
package org.gluu.casa.core;

import com.fasterxml.jackson.databind.JsonNode;
@@ -48,7 +43,7 @@ public class ConfigurationHandler extends JobListenerSupport {
private MainSettings settings;

@Inject
private LdapService ldapService;
private PersistenceService persistenceService;

@Inject
private OxdService oxdService;
@@ -93,7 +88,7 @@ void init() {
//Update log level
computeLoggingLevel();
//Check LDAP access to proceed with acr timer
if (ldapService.initialize()) {
if (persistenceService.initialize()) {
setAppState(AppStateEnum.LOADING);

//This is a trick so the timer event logic can be coded inside this managed bean
@@ -186,7 +181,7 @@ public Map<String, Integer> getAcrLevelMapping() {

Map<String, Integer> map = new HashMap<>();
try {
String oidcEndpointURL = ldapService.getOIDCEndpoint();
String oidcEndpointURL = persistenceService.getOIDCEndpoint();
JsonNode levels = mapper.readTree(new URL(oidcEndpointURL)).get("auth_level_mapping");
Iterator<Map.Entry<String, JsonNode>> it = levels.fields();

@@ -216,7 +211,7 @@ public Map<String, Integer> getAcrLevelMapping() {
public Set<String> retrieveAcrs() {

try {
String oidcEndpointURL = ldapService.getOIDCEndpoint();
String oidcEndpointURL = persistenceService.getOIDCEndpoint();
//too noisy log statement
//logger.trace("Obtaining \"acr_values_supported\" from server {}", oidcEndpointURL);
JsonNode values = mapper.readTree(new URL(oidcEndpointURL)).get("acr_values_supported");
@@ -267,7 +262,7 @@ private void computeMinCredsForStrongAuth() {

private void computePassResetable() {

if (settings.isEnablePassReset() && ldapService.isBackendLdapEnabled()) {
if (settings.isEnablePassReset() && persistenceService.isBackendLdapEnabled()) {
logger.error("Pass reset set automatically to false. Check if you are using a backend LDAP");
settings.setEnablePassReset(false);
}
4 changes: 2 additions & 2 deletions app/src/main/java/org/gluu/casa/core/ExtensionsManager.java
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ void scan() {
plugExtensionMap.put(null, scanInnerAuthnMechanisms());

if (pluginsRoot != null) {
List<PluginInfo> pls = Optional.ofNullable(mainSettings.getKnownPlugins()).orElse(Collections.emptyList());
List<PluginInfo> pls = Utils.nonNullList(mainSettings.getKnownPlugins());

if (pls.size() > 0) {
logger.info("Loading external plugins...");
@@ -362,7 +362,7 @@ private void purgePluginsPath() {
//Deletes all files in path directory as a consequence of https://github.com/pf4j/pf4j/issues/217
//Also prevents cheating...
try {
List<PluginInfo> pls = Optional.ofNullable(mainSettings.getKnownPlugins()).orElse(Collections.emptyList());
List<PluginInfo> pls = Utils.nonNullList(mainSettings.getKnownPlugins());
List<String> validFileNames = pls.stream().map(PluginInfo::getRelativePath).collect(Collectors.toList());

Files.list(pluginsRoot).forEach(p -> {
Loading

0 comments on commit 11f6ad8

Please sign in to comment.