use of org.codice.ddf.configuration.PropertyResolver in project ddf by codice.
the class RestReplicatorPlugin method setParentAddress.
public void setParentAddress(String endpointAddress) {
if (endpointAddress == null) {
this.parentAddress = new PropertyResolver(null);
client = null;
} else if (this.parentAddress == null || !endpointAddress.equals(this.parentAddress.getResolvedString())) {
PropertyResolver previous = this.parentAddress;
this.parentAddress = new PropertyResolver(endpointAddress);
client = WebClient.create(this.parentAddress.getResolvedString(), true);
LOGGER.debug("Changed the parent address property from [{}] to [{}]", previous, this.parentAddress);
}
}
use of org.codice.ddf.configuration.PropertyResolver in project ddf by codice.
the class MetadataConfigurationParser method buildEntityDescriptor.
private void buildEntityDescriptor(String entityDescription) throws IOException {
EntityDescriptor entityDescriptor = null;
entityDescription = entityDescription.trim();
if (entityDescription.startsWith(HTTPS) || entityDescription.startsWith(HTTP)) {
if (entityDescription.startsWith(HTTP)) {
LOGGER.warn("Retrieving metadata via HTTP instead of HTTPS. The metadata configuration is unsafe!!!");
}
PropertyResolver propertyResolver = new PropertyResolver(entityDescription);
HttpTransport httpTransport = new NetHttpTransport();
HttpRequest httpRequest = httpTransport.createRequestFactory().buildGetRequest(new GenericUrl(propertyResolver.getResolvedString()));
httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()).setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS));
httpRequest.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
ListenableFuture<HttpResponse> httpResponseFuture = service.submit(httpRequest::execute);
Futures.addCallback(httpResponseFuture, new FutureCallback<HttpResponse>() {
@Override
public void onSuccess(HttpResponse httpResponse) {
if (httpResponse != null) {
try {
String parsedResponse = httpResponse.parseAsString();
buildEntityDescriptor(parsedResponse);
} catch (IOException e) {
LOGGER.info("Unable to parse metadata from: {}", httpResponse.getRequest().getUrl().toString(), e);
}
}
}
@Override
public void onFailure(Throwable throwable) {
LOGGER.info("Unable to retrieve metadata.", throwable);
}
});
service.shutdown();
} else if (entityDescription.startsWith(FILE + System.getProperty("ddf.home"))) {
String pathStr = StringUtils.substringAfter(entityDescription, FILE);
Path path = Paths.get(pathStr);
if (Files.isReadable(path)) {
try (InputStream fileInputStream = Files.newInputStream(path)) {
entityDescriptor = readEntityDescriptor(new InputStreamReader(fileInputStream, "UTF-8"));
}
}
} else if (entityDescription.startsWith("<") && entityDescription.endsWith(">")) {
entityDescriptor = readEntityDescriptor(new StringReader(entityDescription));
} else {
LOGGER.info("Skipping unknown metadata configuration value: {}", entityDescription);
}
if (entityDescriptor != null) {
entityDescriptorMap.put(entityDescriptor.getEntityID(), entityDescriptor);
if (updateCallback != null) {
updateCallback.accept(entityDescriptor);
}
}
}
use of org.codice.ddf.configuration.PropertyResolver in project ddf by codice.
the class ClaimsHandlerManager method update.
/**
* Callback method that is called when configuration is updated. Also called by the
* blueprint init-method when all properties have been set.
*
* @param props Map of properties.
*/
public void update(Map<String, Object> props) {
if (props == null) {
return;
}
LOGGER.debug("Received an updated set of configurations for the LDAP/Role Claims Handlers.");
String url = new PropertyResolver((String) props.get(ClaimsHandlerManager.URL)).toString();
Boolean startTls;
if (props.get(ClaimsHandlerManager.START_TLS) instanceof String) {
startTls = Boolean.valueOf((String) props.get(ClaimsHandlerManager.START_TLS));
} else {
startTls = (Boolean) props.get(ClaimsHandlerManager.START_TLS);
}
String userDn = (String) props.get(ClaimsHandlerManager.LDAP_BIND_USER_DN);
String password = (String) props.get(ClaimsHandlerManager.PASSWORD);
String userBaseDn = (String) props.get(ClaimsHandlerManager.USER_BASE_DN);
String objectClass = (String) props.get(ClaimsHandlerManager.OBJECT_CLASS);
String memberNameAttribute = (String) props.get(ClaimsHandlerManager.MEMBER_NAME_ATTRIBUTE);
String groupBaseDn = (String) props.get(ClaimsHandlerManager.GROUP_BASE_DN);
String loginUserAttribute = (String) props.get(ClaimsHandlerManager.LOGIN_USER_ATTRIBUTE);
String membershipUserAttribute = (String) props.get(ClaimsHandlerManager.MEMBER_USER_ATTRIBUTE);
String propertyFileLocation = (String) props.get(ClaimsHandlerManager.PROPERTY_FILE_LOCATION);
String bindMethod = (String) props.get(ClaimsHandlerManager.BIND_METHOD);
String realm = (props.get(ClaimsHandlerManager.REALM) != null) ? (String) props.get(ClaimsHandlerManager.REALM) : "";
String kdcAddress = (props.get(ClaimsHandlerManager.KDC_ADDRESS) != null) ? (String) props.get(ClaimsHandlerManager.KDC_ADDRESS) : "";
if ("GSSAPI SASL".equals(bindMethod) && (StringUtils.isEmpty(realm) || StringUtils.isEmpty(kdcAddress))) {
LOGGER.warn("LDAP connection will fail. GSSAPI SASL connection requires Kerberos Realm and KDC Address.");
}
Boolean overrideCertDn;
if (props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN) instanceof String) {
overrideCertDn = Boolean.valueOf((String) props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN));
} else {
overrideCertDn = (Boolean) props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN);
}
if (startTls == null) {
startTls = false;
}
if (overrideCertDn == null) {
overrideCertDn = false;
}
try {
if (encryptService != null) {
password = encryptService.decryptValue(password);
}
LDAPConnectionFactory connection1 = createLdapConnectionFactory(url, startTls);
LDAPConnectionFactory connection2 = createLdapConnectionFactory(url, startTls);
registerRoleClaimsHandler(connection1, propertyFileLocation, userBaseDn, loginUserAttribute, membershipUserAttribute, objectClass, memberNameAttribute, groupBaseDn, userDn, password, overrideCertDn, bindMethod, realm, kdcAddress);
registerLdapClaimsHandler(connection2, propertyFileLocation, userBaseDn, loginUserAttribute, userDn, password, overrideCertDn, bindMethod, realm, kdcAddress);
} catch (Exception e) {
LOGGER.warn("Experienced error while configuring claims handlers. Handlers are NOT configured and claim retrieval will not work. Check LDAP configuration.", e);
}
}
use of org.codice.ddf.configuration.PropertyResolver in project ddf by codice.
the class FtpServerStarter method updateConfiguration.
/**
* Callback for when the FTP Endpoint configuration is updated through the Admin UI
*
* @param properties map of configurable properties
*/
public void updateConfiguration(Map<String, Object> properties) {
if (MapUtils.isEmpty(properties)) {
LOGGER.warn("Received null or empty FTP Endpoint configuration. Check the 'FTP Endpoint' configuration.");
return;
}
LOGGER.debug("Updating FTP Endpoint configuration");
Boolean restart = false;
if (properties.get(PORT) instanceof String) {
//using PropertyResolver in case properties.get("port") is ${org.codice.ddf.catalog.ftp.port}
PropertyResolver propertyResolver = new PropertyResolver((String) properties.get("port"));
int port = Integer.parseInt(propertyResolver.getResolvedString());
if (this.port != port) {
setPort(port);
restart = true;
}
}
if (properties.get(CLIENT_AUTH) instanceof String) {
String clientAuth = ((String) properties.get("clientAuth")).toLowerCase();
if (!this.clientAuth.toString().equalsIgnoreCase(clientAuth)) {
setClientAuth(clientAuth);
restart = true;
}
}
if (restart) {
restartDefaultListener();
}
}
use of org.codice.ddf.configuration.PropertyResolver in project ddf by codice.
the class SecureCxfClientFactoryTest method testHttpsClientWithSystemProperty.
@Test
public void testHttpsClientWithSystemProperty() {
PropertyResolver mockPropertyResolver = mock(PropertyResolver.class);
when(mockPropertyResolver.getResolvedString()).thenReturn(SECURE_ENDPOINT);
// positive case
SecureCxfClientFactory<IDummy> secureCxfClientFactory = new SecureCxfClientFactory<>(SECURE_ENDPOINT, IDummy.class, null, null, false, false, mockPropertyResolver);
Client unsecuredClient = WebClient.client(secureCxfClientFactory.getClient());
assertThat(unsecuredClient.getBaseURI().toASCIIString(), is(SECURE_ENDPOINT));
verify(mockPropertyResolver).getResolvedString();
// negative cases
IDummy result;
result = secureCxfClientFactory.getClientForSubject(getSubject());
assertThat(result, notNullValue());
result = secureCxfClientFactory.getClient();
assertThat(result, notNullValue());
secureCxfClientFactory.getClient();
assertThat(result, notNullValue());
}
Aggregations