Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.

Commit 9451509

Browse files
committed
Feedback. Part 3.
#436 (comment)
1 parent c502f76 commit 9451509

File tree

2 files changed

+15
-46
lines changed

2 files changed

+15
-46
lines changed

samples/service-provider/starter/src/main/java/org/springframework/security/config/annotation/web/configurers/Saml2ServiceProviderConfigurer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.security.saml2.serviceprovider.registration.Saml2IdentityProviderDetails.Saml2IdentityProviderDetailsBuilder;
3434
import org.springframework.security.saml2.serviceprovider.registration.Saml2IdentityProviderRepository;
3535
import org.springframework.security.saml2.serviceprovider.registration.Saml2ServiceProviderRegistration;
36-
import org.springframework.security.saml2.serviceprovider.registration.Saml2ServiceProviderRegistration.Saml2ServiceProviderRegistrationBuilder;
3736
import org.springframework.security.saml2.credentials.Saml2X509Credential;
3837
import org.springframework.security.saml2.serviceprovider.servlet.filter.Saml2AuthenticationFailureHandler;
3938
import org.springframework.security.saml2.serviceprovider.servlet.filter.Saml2WebSsoAuthenticationFilter;
@@ -46,7 +45,8 @@ public static Saml2ServiceProviderConfigurer saml2Login() {
4645
return new Saml2ServiceProviderConfigurer();
4746
}
4847

49-
private Saml2ServiceProviderRegistrationBuilder serviceProvider = Saml2ServiceProviderRegistration.builder();
48+
private String spEntityId = null;
49+
private List<Saml2X509Credential> spCredentials = new LinkedList<>();
5050
private List<Saml2IdentityProviderDetails> idps = new LinkedList<>();
5151
private AuthenticationProvider authenticationProvider;
5252

@@ -55,12 +55,12 @@ public Saml2ServiceProviderConfigurer() {
5555
}
5656

5757
public Saml2ServiceProviderConfigurer serviceProviderEntityId(String entityId) {
58-
this.serviceProvider.entityId(entityId);
58+
this.spEntityId = entityId;
5959
return this;
6060
}
6161

6262
public Saml2ServiceProviderConfigurer addServiceProviderKey(Saml2X509Credential key) {
63-
this.serviceProvider.credential(key);
63+
this.spCredentials.add(key);
6464
return this;
6565
}
6666

@@ -94,7 +94,7 @@ public void init(HttpSecurity builder) throws Exception {
9494
);
9595

9696
authenticationProvider = new Saml2AuthenticationProvider(
97-
serviceProvider.build(),
97+
new Saml2ServiceProviderRegistration(spEntityId, spCredentials),
9898
identityProviderRepository
9999
);
100100
}

samples/service-provider/starter/src/main/java/org/springframework/security/saml2/serviceprovider/registration/Saml2ServiceProviderRegistration.java

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import org.springframework.security.saml2.credentials.Saml2X509Credential;
2424

25+
import static org.springframework.util.Assert.notEmpty;
26+
import static org.springframework.util.Assert.notNull;
27+
2528

2629
/**
2730
* Configuration object that represents a local(hosted) service provider
@@ -31,18 +34,14 @@ public class Saml2ServiceProviderRegistration {
3134
private final String entityId;
3235
private final List<Saml2X509Credential> credentials = new LinkedList<>();
3336

34-
public static Saml2ServiceProviderRegistrationBuilder builder() {
35-
return new Saml2ServiceProviderRegistrationBuilder();
36-
}
37-
38-
public static Saml2ServiceProviderRegistrationBuilder builder(Saml2ServiceProviderRegistration registration) {
39-
return builder()
40-
.credentials(registration.getSaml2Credentials())
41-
.entityId(registration.getEntityId());
42-
}
43-
44-
private Saml2ServiceProviderRegistration(String entityId,
37+
public Saml2ServiceProviderRegistration(String entityId,
4538
List<Saml2X509Credential> credentials) {
39+
notNull(entityId, "entityId is required");
40+
notEmpty(credentials, "at least one private key and certificate is required for signed and encrypted messages");
41+
credentials.stream().forEach(c -> {
42+
notNull(c.getPrivateKey(), "private key required in all credentials");
43+
notNull(c.getCertificate(), "certificate required in all credentials");
44+
});
4645
this.entityId = entityId;
4746
this.credentials.addAll(credentials);
4847
}
@@ -55,34 +54,4 @@ public String getEntityId() {
5554
return entityId;
5655
}
5756

58-
public static final class Saml2ServiceProviderRegistrationBuilder {
59-
private String entityId;
60-
private List<Saml2X509Credential> credentials = new LinkedList<>();
61-
62-
private Saml2ServiceProviderRegistrationBuilder() {
63-
}
64-
65-
public Saml2ServiceProviderRegistrationBuilder entityId(String entityId) {
66-
this.entityId = entityId;
67-
return this;
68-
}
69-
70-
public Saml2ServiceProviderRegistrationBuilder credentials(List<Saml2X509Credential> keys) {
71-
this.credentials = keys;
72-
return this;
73-
}
74-
75-
public void credential(Saml2X509Credential key) {
76-
this.credentials.add(key);
77-
}
78-
79-
public Saml2ServiceProviderRegistration build() {
80-
Saml2ServiceProviderRegistration saml2ServiceProviderRegistration = new Saml2ServiceProviderRegistration(
81-
entityId,
82-
credentials
83-
);
84-
return saml2ServiceProviderRegistration;
85-
}
86-
}
87-
8857
}

0 commit comments

Comments
 (0)