Skip to content

Commit

Permalink
SHIBUI-836: work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Sep 11, 2018
1 parent 03b2f50 commit 0cd4254
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
Expand Down Expand Up @@ -36,10 +37,15 @@ public static class MetadataResolversResourceIdEmitter {
@Autowired
MetadataResolverRepository metadataResolverRepository;

@Value("${idp.home}")
String idpHome;

@EventListener
void showMetadataResolversResourceIds(ApplicationStartedEvent e) {
metadataResolverRepository.findAll()
.forEach(it -> System.out.println(String.format("MetadataResolver [%s: %s]", it.getName(), it.getResourceId())));

System.out.println("IDP HOME: " + idpHome);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.internet2.tier.shibboleth.admin.ui.configuration.postprocessors;

import lombok.extern.log4j.Log4j2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

/**
* Spring Boot Environment Post Processor setting the value for idp.home property to an abstract temp directory.
*
* @author Dmitriy Kopylenko
*/
public class IdpHomeValueSettingEnvironmentPostProcessor implements EnvironmentPostProcessor {

private static final String IDP_HOME_PROP = "idp.home";

private static final String METADATA_DIR = "metadata";

private static final Logger LOGGER = LoggerFactory.getLogger(IdpHomeValueSettingEnvironmentPostProcessor.class);

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
String existingIdpHome = environment.getProperty(IDP_HOME_PROP);
Path metadataSubDir = Paths.get(existingIdpHome, METADATA_DIR);
if (existingIdpHome != null) {
if (!Files.exists(metadataSubDir)) {
try {
Files.createDirectories(metadataSubDir);
} catch (IOException e) {
LOGGER.error(e.getMessage());
throw new RuntimeException(e);
}
}
return;
}

Map<String, Object> map = new HashMap<>(1);
try {
map.put(IDP_HOME_PROP, Files.createTempDirectory(null).toAbsolutePath().toString());
} catch (IOException e) {
LOGGER.error(e.getMessage());
throw new RuntimeException(e);
}
environment.getPropertySources().addLast(new MapPropertySource("idp.home.propertysource", map));
}
}
2 changes: 2 additions & 0 deletions backend/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
edu.internet2.tier.shibboleth.admin.ui.configuration.postprocessors.IdpHomeValueSettingEnvironmentPostProcessor

0 comments on commit 0cd4254

Please sign in to comment.