Skip to content

Commit

Permalink
Feature/is 88 credentials support (#89)
Browse files Browse the repository at this point in the history
Now using credentials-support 2.0.0
  • Loading branch information
martin-lindstrom authored Dec 8, 2024
1 parent 75b1f92 commit 8188eb3
Show file tree
Hide file tree
Showing 120 changed files with 4,889 additions and 2,912 deletions.
8 changes: 7 additions & 1 deletion autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<version>2.2.1</version>
<version>2.3.0-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Spring Boot Autoconfigure module</name>
Expand Down Expand Up @@ -60,6 +60,12 @@
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>se.swedenconnect.security</groupId>
<artifactId>credentials-support-spring-boot-starter</artifactId>
<version>${credentials-support.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
*/
package se.swedenconnect.spring.saml.idp.autoconfigure.audit;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.audit.AuditEvent;
Expand All @@ -31,16 +26,19 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import com.fasterxml.jackson.databind.ObjectMapper;

import se.swedenconnect.spring.saml.idp.audit.repository.AuditEventMapper;
import se.swedenconnect.spring.saml.idp.audit.repository.DelegatingAuditEventRepository;
import se.swedenconnect.spring.saml.idp.audit.repository.FileBasedAuditEventRepository;
import se.swedenconnect.spring.saml.idp.audit.repository.FilteringAuditEventRepository;
import se.swedenconnect.spring.saml.idp.audit.repository.JsonAuditEventMapper;
import se.swedenconnect.spring.saml.idp.audit.repository.MemoryBasedAuditEventRepository;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

/**
* Autoconfiguration for auditing support where an {@link AuditEventRepository} is created.
*
Expand All @@ -63,7 +61,8 @@ public class AuditRepositoryAutoConfiguration {
* @param properties the audit properties
* @param objectMapper the JSON object mapper
*/
public AuditRepositoryAutoConfiguration(final AuditRepositoryConfigurationProperties properties, final ObjectMapper objectMapper) {
public AuditRepositoryAutoConfiguration(final AuditRepositoryConfigurationProperties properties,
final ObjectMapper objectMapper) {
this.properties = Objects.requireNonNull(properties, "properties must not be null");
this.objectMapper = Objects.requireNonNull(objectMapper, "objectMapper must not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/
package se.swedenconnect.spring.saml.idp.autoconfigure.audit;

import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import se.swedenconnect.spring.saml.idp.audit.repository.MemoryBasedAuditEventRepository;

import java.util.ArrayList;
import java.util.List;

/**
* Configuration properties for auditing.
*
Expand Down Expand Up @@ -60,15 +59,14 @@ public class AuditRepositoryConfigurationProperties implements InitializingBean
private RedisRepository redis;

/**
* A list of event ID:s for the events that will be logged to the repository. If not set, all events will
* be logged (except to excluded by the "exclude-events").
* A list of event ID:s for the events that will be logged to the repository. If not set, all events will be logged
* (except to excluded by the "exclude-events").
*/
@Getter
private final List<String> includeEvents = new ArrayList<>();

/**
* A list of event ID:s to exclude from being logged to the repository. See also the "include-events"
* setting.
* A list of event ID:s to exclude from being logged to the repository. See also the "include-events" setting.
*/
@Getter
private final List<String> excludeEvents = new ArrayList<>();
Expand Down Expand Up @@ -107,7 +105,7 @@ public static class FileRepository implements InitializingBean {

/** {@inheritDoc} */
@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Assert.hasText(this.logFile, "saml.idp.audit.file.log-file must be assigned");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,23 @@
*/
package se.swedenconnect.spring.saml.idp.autoconfigure.base;

import jakarta.annotation.Nonnull;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import se.swedenconnect.opensaml.common.utils.LocalizedString;
import se.swedenconnect.security.credential.converters.PropertyToX509CertificateConverter;
import se.swedenconnect.spring.saml.idp.metadata.PropertyToEntityDescriptorConverter;

import java.security.cert.X509Certificate;

/**
* Configuration class that registers converters for Spring converters needed to apply properties to
* configuration properties classes.
* Configuration class that registers converters for Spring converters needed to apply properties to configuration
* properties classes.
*/
@AutoConfiguration(after = OpenSAMLConfiguration.class)
public class ConvertersConfiguration {

/**
* Creates the bean the allows us to use property values that are referencing certificate resources and get the
* {@link X509Certificate} injected.
*
* @return a PropertyToX509CertificateConverter bean
*/
@ConditionalOnMissingBean
@Bean
@ConfigurationPropertiesBinding
PropertyToX509CertificateConverter propertyToX509CertificateConverter() {
return new PropertyToX509CertificateConverter();
}

/**
* Creates the bean the allows us to use property values that are referencing EntityDescriptor resources and get the
* {@link EntityDescriptor} injected.
Expand All @@ -72,7 +56,7 @@ Converter<String, LocalizedString> localizedStringConverter() {
return new Converter<>() {

@Override
public LocalizedString convert(@NonNull final String source) {
public LocalizedString convert(@Nonnull final String source) {
return new LocalizedString(source);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package se.swedenconnect.spring.saml.idp.autoconfigure.error;

import java.nio.charset.StandardCharsets;
import java.util.Map;

import jakarta.annotation.Nonnull;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
Expand All @@ -29,12 +30,11 @@
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.util.HtmlUtils;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import se.swedenconnect.spring.saml.idp.error.UnrecoverableSaml2IdpException;

import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
* A SAML error view resolver for handling {@link UnrecoverableSaml2IdpException}.
*
Expand Down Expand Up @@ -106,8 +106,8 @@ private static class IdpErrorStaticView implements View {
private static final MediaType TEXT_HTML_UTF8 = new MediaType("text", "html", StandardCharsets.UTF_8);

@Override
public void render(final Map<String, ?> model, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
public void render(final Map<String, ?> model, @Nonnull final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
if (response.isCommitted()) {
final String message = this.getMessage(model);
log.error(message);
Expand All @@ -125,7 +125,7 @@ public void render(final Map<String, ?> model, final HttpServletRequest request,
response.setContentType(this.getContentType());
}
builder.append("<html><body><h1>IdP Error</h1>").append(
"<p>This application has no explicit mapping for IdP errors, so you are seeing this as a fallback.</p>")
"<p>This application has no explicit mapping for IdP errors, so you are seeing this as a fallback.</p>")
.append("<div id='created'>").append(timestamp).append("</div>")
.append("<div>There was an unexpected error (type=").append(this.htmlEscape(model.get("error")))
.append(", status=").append(this.htmlEscape(model.get("status"))).append(").</div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.RedisOperations;

import se.swedenconnect.spring.saml.idp.autoconfigure.redis.RedisTlsExtensionsConfiguration.SslBundleRegistrationBean;

/**
* Autoconfiguration for Redis extensions.
*
* @author Martin Lindström
*/
@AutoConfiguration(before = RedisAutoConfiguration.class )
@AutoConfiguration(before = RedisAutoConfiguration.class)
@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties({ RedisProperties.class, RedisTlsProperties.class })
@Import(RedisTlsExtensionsConfiguration.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
*/
package se.swedenconnect.spring.saml.idp.autoconfigure.redis;

import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.UUID;
import java.util.stream.StreamSupport;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.ssl.SslBundle;
Expand All @@ -35,7 +27,14 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.UUID;
import java.util.stream.StreamSupport;

/**
* Configuration class that transforms the deprecated {@link RedisTlsProperties} to a {@link SslBundle}.
Expand Down Expand Up @@ -114,7 +113,7 @@ public SslBundleRegistrationBean(final RedisProperties redisProperties,
keyStore.load(is, keyStorePassword.toCharArray());
}
final String alias = StreamSupport.stream(
Spliterators.spliteratorUnknownSize(keyStore.aliases().asIterator(), Spliterator.ORDERED), false)
Spliterators.spliteratorUnknownSize(keyStore.aliases().asIterator(), Spliterator.ORDERED), false)
.filter(a -> {
try {
return keyStore.isKeyEntry(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.ReadMode;
import org.redisson.config.SingleServerConfig;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.redisson.spring.starter.RedissonAutoConfigurationV2;
import org.springframework.boot.autoconfigure.AutoConfiguration;
Expand All @@ -34,8 +33,6 @@
import se.swedenconnect.spring.saml.idp.autoconfigure.redis.RedisTlsExtensionsConfiguration.SslBundleRegistrationBean;
import se.swedenconnect.spring.saml.idp.autoconfigure.redis.RedissonClusterProperties.NatTranslationEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -127,7 +124,8 @@ private BaseConfig<?> getRedissonConfiguration(final Config config) {
*/
private static class RedissonAddressCustomizers {

public static BiFunction<ClusterServersConfig, RedissonClusterProperties, ClusterServersConfig> clusterServerCustomizer =
public static BiFunction<ClusterServersConfig, RedissonClusterProperties, ClusterServersConfig>
clusterServerCustomizer =
(config, clusterProperties) -> {
if (clusterProperties.getNatTranslation() != null) {
final HostPortNatMapper mapper = new HostPortNatMapper();
Expand Down

This file was deleted.

Loading

0 comments on commit 8188eb3

Please sign in to comment.