Search in sources :

Example 1 with PropertyResolver

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);
    }
}
Also used : PropertyResolver(org.codice.ddf.configuration.PropertyResolver)

Example 2 with PropertyResolver

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);
        }
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) Path(java.nio.file.Path) HttpBackOffIOExceptionHandler(com.google.api.client.http.HttpBackOffIOExceptionHandler) HttpBackOffUnsuccessfulResponseHandler(com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) PropertyResolver(org.codice.ddf.configuration.PropertyResolver) ExponentialBackOff(com.google.api.client.util.ExponentialBackOff) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) StringReader(java.io.StringReader) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService)

Example 3 with PropertyResolver

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);
    }
}
Also used : LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) PropertyResolver(org.codice.ddf.configuration.PropertyResolver) LdapException(org.forgerock.opendj.ldap.LdapException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with PropertyResolver

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();
    }
}
Also used : PropertyResolver(org.codice.ddf.configuration.PropertyResolver)

Example 5 with PropertyResolver

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());
}
Also used : PropertyResolver(org.codice.ddf.configuration.PropertyResolver) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(org.apache.cxf.jaxrs.client.Client) Test(org.junit.Test)

Aggregations

PropertyResolver (org.codice.ddf.configuration.PropertyResolver)7 IOException (java.io.IOException)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Test (org.junit.Test)2 GenericUrl (com.google.api.client.http.GenericUrl)1 HttpBackOffIOExceptionHandler (com.google.api.client.http.HttpBackOffIOExceptionHandler)1 HttpBackOffUnsuccessfulResponseHandler (com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpResponse (com.google.api.client.http.HttpResponse)1 HttpTransport (com.google.api.client.http.HttpTransport)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 ExponentialBackOff (com.google.api.client.util.ExponentialBackOff)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1