-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SHIBUI-812
- Loading branch information
Showing
15 changed files
with
269 additions
and
21 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...t2/tier/shibboleth/admin/ui/configuration/PlaceholderResolverComponentsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.configuration; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.service.TokenPlaceholderValueResolvingService; | ||
import edu.internet2.tier.shibboleth.admin.util.TokenPlaceholderResolvers; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
@Configuration | ||
public class PlaceholderResolverComponentsConfiguration { | ||
|
||
@Bean | ||
public TokenPlaceholderValueResolvingService tokenPlaceholderValueResolvingService(ConfigurableEnvironment env) { | ||
return TokenPlaceholderValueResolvingService.shibbolethPlaceholderPrefixAware(env.getPropertySources()); | ||
} | ||
|
||
@Bean | ||
public TokenPlaceholderResolvers tokenPlaceholderResolvers(TokenPlaceholderValueResolvingService service) { | ||
return new TokenPlaceholderResolvers(service); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...th/admin/ui/configuration/postprocessors/IdpHomeValueSettingEnvironmentPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.configuration.postprocessors; | ||
|
||
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.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 a temp directory | ||
* if no IDP_HOME environment variable has been set already. | ||
* | ||
* @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) { | ||
if(environment.getProperty(IDP_HOME_PROP) == null) { | ||
Map<String, Object> map = new HashMap<>(1); | ||
try { | ||
Path tempDir = Files.createTempDirectory(null); | ||
tempDir.toFile().deleteOnExit(); | ||
String tempDirName = tempDir.toAbsolutePath().toString(); | ||
Path tempMetadataSubDir = Paths.get(tempDirName, METADATA_DIR); | ||
Files.createDirectories(tempMetadataSubDir); | ||
map.put(IDP_HOME_PROP, tempDirName); | ||
} catch (IOException e) { | ||
LOGGER.error(e.getMessage()); | ||
throw new RuntimeException(e); | ||
} | ||
environment.getPropertySources().addLast(new MapPropertySource("idp.home.propertysource", map)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ier/shibboleth/admin/ui/service/ShibbolethPlaceholderTokenAwareValueResolvingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import org.springframework.core.env.PropertyResolver; | ||
import org.springframework.core.env.PropertySources; | ||
import org.springframework.core.env.PropertySourcesPropertyResolver; | ||
|
||
|
||
/** | ||
* Implementation of {@link TokenPlaceholderValueResolvingService} based on Spring Framework's property resolver which | ||
* understands Shibboleth Idp custom placeholder prefix of <strong>%{</strong> and can resolve property values from these | ||
* placeholders against existing property sources. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public class ShibbolethPlaceholderTokenAwareValueResolvingService implements TokenPlaceholderValueResolvingService { | ||
|
||
private PropertyResolver propertyResolver; | ||
|
||
ShibbolethPlaceholderTokenAwareValueResolvingService(PropertySources propertySources) { | ||
PropertySourcesPropertyResolver propertySourcesPropertyResolver = new PropertySourcesPropertyResolver(propertySources); | ||
propertySourcesPropertyResolver.setPlaceholderPrefix("%{"); | ||
this.propertyResolver = propertySourcesPropertyResolver; | ||
} | ||
|
||
@Override | ||
public String resolveValueFromPossibleTokenPlaceholder(String potentialTokenPlaceholder) { | ||
return potentialTokenPlaceholder != null | ||
? this.propertyResolver.resolveRequiredPlaceholders(potentialTokenPlaceholder) | ||
: potentialTokenPlaceholder; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...edu/internet2/tier/shibboleth/admin/ui/service/TokenPlaceholderValueResolvingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import org.springframework.core.env.PropertyResolver; | ||
import org.springframework.core.env.PropertySources; | ||
|
||
/** | ||
* Generic API to resolve values from arbitrary tokenized placeholders such as '%{token.placeholder}' etc. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
@FunctionalInterface | ||
public interface TokenPlaceholderValueResolvingService { | ||
|
||
String resolveValueFromPossibleTokenPlaceholder(String potentialTokenPlaceholder); | ||
|
||
|
||
static TokenPlaceholderValueResolvingService shibbolethPlaceholderPrefixAware(PropertySources propertySources) { | ||
return new ShibbolethPlaceholderTokenAwareValueResolvingService(propertySources); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...end/src/main/java/edu/internet2/tier/shibboleth/admin/util/TokenPlaceholderResolvers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.internet2.tier.shibboleth.admin.util; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.service.TokenPlaceholderValueResolvingService; | ||
|
||
/** | ||
* Accessor facade class to expose {@link TokenPlaceholderValueResolvingService} to non-Spring-managed classes. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public class TokenPlaceholderResolvers { | ||
|
||
private static TokenPlaceholderValueResolvingService placeholderResolverService; | ||
|
||
public TokenPlaceholderResolvers(TokenPlaceholderValueResolvingService service) { | ||
TokenPlaceholderResolvers.placeholderResolverService = service; | ||
} | ||
|
||
public static TokenPlaceholderValueResolvingService placeholderResolverService() { | ||
return placeholderResolverService; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.