aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src
diff options
context:
space:
mode:
authorChristian Wagner <c.wagner@datentechnik-innovation.com>2015-01-22 15:39:20 +0100
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:09:20 +0200
commite27e11fbf9003cc4cfb04b52b1acd18253ee5b93 (patch)
treec8dffe8fcc941ef4cc19f381cc3794c85631d16a /id/server/idserverlib/src
parentcc7e339de3a905892be3afbd624509f3dd45b19e (diff)
downloadmoa-id-spss-e27e11fbf9003cc4cfb04b52b1acd18253ee5b93.tar.gz
moa-id-spss-e27e11fbf9003cc4cfb04b52b1acd18253ee5b93.tar.bz2
moa-id-spss-e27e11fbf9003cc4cfb04b52b1acd18253ee5b93.zip
add missing getter-methods.
- add methods to get 'OnlineApplication' from DB. - add getter-methods which override the getter-methods in 'ConfigurationProvider'.
Diffstat (limited to 'id/server/idserverlib/src')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java175
1 files changed, 171 insertions, 4 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java
index 0ee143a1a..a667ff355 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java
@@ -6,6 +6,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -13,8 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants;
import at.gv.egovernment.moa.id.commons.db.MOAIDConfigurationConstants;
-import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead;
import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral;
+import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes;
import at.gv.egovernment.moa.id.commons.db.dao.config.ConnectionParameterClientAuthType;
import at.gv.egovernment.moa.id.commons.db.dao.config.Contact;
import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs;
@@ -54,13 +56,22 @@ import com.datentechnik.moa.id.conf.persistence.Configuration;
*/
public class NewAuthConfigurationProvider extends ConfigurationProvider implements AuthConfiguration {
+
+ private static final boolean TRUST_MANAGER_REVOCATION_CHECKING_DEFAULT = true;
+
private Configuration configuration;
private final Properties properties = new Properties();
-
+
public NewAuthConfigurationProvider() {
}
+ /**
+ * The constructor with path to a properties file as argument.
+ *
+ * @param fileName the path to the properties file
+ * @throws ConfigurationException if an error occurs during loading the properties file.
+ */
public NewAuthConfigurationProvider(String fileName) throws ConfigurationException {
File propertiesFile = new File(fileName);
rootConfigFileDir = propertiesFile.getParent();
@@ -73,17 +84,39 @@ public class NewAuthConfigurationProvider extends ConfigurationProvider implemen
throw new ConfigurationException("config.03", null, e);
}
}
-
+
+ /**
+ * Set the {@link Configuration} for this class.
+ * @param configuration the configuration
+ */
@Autowired
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
+ /**
+ * Get the properties.
+ * @return the properties
+ */
private Properties getProperties() {
return properties;
}
/**
+ * Method that avoids iterating over a {@link Collection} of type {@code T} which is actual {@code null}.
+ * @param item the collection
+ * @return the given {@link Collection} {@code item} if it is not {@code null}, or an empty {@link List} otherwise.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Iterable<?>> T nullGuard(T item) {
+ if (item == null) {
+ return (T) Collections.emptyList();
+ } else {
+ return item;
+ }
+ }
+
+ /**
* Returns the general pvp2 properties config. NOTE: may be empty but never {@code null}.
* @return the general pvp2 properties config.
*/
@@ -284,7 +317,7 @@ public class NewAuthConfigurationProvider extends ConfigurationProvider implemen
*/
public OAAuthParameter getOnlineApplicationParameter(String oaURL) {
- OnlineApplication oa = NewConfigurationDBRead.getActiveOnlineApplication(oaURL);
+ OnlineApplication oa = getActiveOnlineApplication(oaURL);
if (oa == null) {
Logger.warn("Online application with identifier " + oaURL + " is not found.");
return null;
@@ -803,4 +836,138 @@ public class NewAuthConfigurationProvider extends ConfigurationProvider implemen
return configProp;
}
+ /**
+ * Returns whether the trust-manager revocation checking is enabled or not.
+ *
+ * @return {@code true} if enable, {@code false} if disabled
+ */
+ @Override
+ public boolean isTrustmanagerrevoationchecking() {
+
+ try {
+ AuthComponentGeneral authComponentGeneral = getAuthComponentGeneral();
+ GeneralConfiguration generalConfiguration = authComponentGeneral.getGeneralConfiguration();
+ if (generalConfiguration != null && generalConfiguration.isTrustManagerRevocationChecking() != null) {
+
+ return generalConfiguration.isTrustManagerRevocationChecking();
+
+ } else {
+ Logger.warn("No TrustMangerRevoationChecking defined. Use default value = "
+ + String.valueOf(TRUST_MANAGER_REVOCATION_CHECKING_DEFAULT).toUpperCase());
+ return TRUST_MANAGER_REVOCATION_CHECKING_DEFAULT;
+ }
+
+ } catch (ConfigurationException e) {
+ return TRUST_MANAGER_REVOCATION_CHECKING_DEFAULT;
+ }
+ }
+
+ /**
+ * Returns the path to the certificate-store directory or {@code null} if there is no certificate-store directory defined.
+ *
+ * @return the path to the certstore directory or {@code null}
+ */
+ @Override
+ public String getCertstoreDirectory() {
+
+ try {
+ AuthComponentGeneral authComponentGeneral = getAuthComponentGeneral();
+ GeneralConfiguration generalConfiguration = authComponentGeneral.getGeneralConfiguration();
+ if (generalConfiguration != null) {
+ return (rootConfigFileDir + generalConfiguration.getCertStoreDirectory());
+ } else {
+ Logger.warn("Error in MOA-ID Configuration. No CertStoreDirectory defined.");
+ return null;
+ }
+
+ } catch (ConfigurationException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public String getTrustedCACertificates() {
+ return (String) configuration.get(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, String.class);
+ }
+
+ /**
+ * Returns the default chaining mode or {@code null} if there is no chaining mode defined.
+ *
+ * @return the default chaining mode or {@code null}
+ */
+ @Override
+ public String getDefaultChainingMode() {
+
+ ChainingModes chainingModes = (ChainingModes) configuration.get(MOAIDConfigurationConstants.CHAINING_MODES_KEY, ChainingModes.class);
+ if (chainingModes != null) {
+ return chainingModes.getSystemDefaultMode().value();
+ }
+
+ Logger.warn("Error in MOA-ID Configuration. No ChainingMode configuration found.");
+ return null;
+ }
+
+ /**
+ * Returns a list of all {@link OnlineApplication}.
+ *
+ * @return list of all OnlineApplications
+ */
+ public List<OnlineApplication> getAllOnlineApplications() {
+ Logger.trace("Get all OnlineApplications from database.");
+
+ return configuration.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class);
+ }
+
+ /**
+ * Returns a list of all active {@link OnlineApplication} or {@code null} if no active online application was found.
+ *
+ * @return list of all active OnlineApplications or {@code null}.
+ */
+ public List<OnlineApplication> getAllActiveOnlineApplications() {
+ Logger.debug("Get all new OnlineApplications from database.");
+
+ List<OnlineApplication> result = new ArrayList<OnlineApplication>();
+ List<OnlineApplication> allOAs = getAllOnlineApplications();
+
+ for (OnlineApplication oa : nullGuard(allOAs)) {
+ if (oa.isIsActive()) {
+ result.add(oa);
+ }
+ }
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return result;
+ }
+
+ /**
+ * Returns the active {@link OnlineApplication} with the given ID or {@code null} if either no matching online application is found or if the {@code id}
+ * matches more than one entry.
+ *
+ * @param id the id of the requested online application
+ * @return the requested online application or {@code null}
+ */
+ public OnlineApplication getActiveOnlineApplication(String id) {
+ Logger.trace("Get active OnlineApplication with ID " + id + " from database.");
+
+ OnlineApplication result = null;
+ List<OnlineApplication> allActiveOAs = getAllActiveOnlineApplications();
+
+ for (OnlineApplication oa : nullGuard(allActiveOAs)) {
+ String publicUrlPrefix = oa.getPublicURLPrefix();
+ if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) {
+ if ((id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix))) {
+ if (result != null) {
+ Logger.warn("OAIdentifier matches more than one DB-entry!");
+ return null;
+ } else {
+ result = oa;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
}