Skip to content

Commit 1f03608

Browse files
philwebbrwinch
authored andcommitted
Polish spring-security-saml2 main code
Manually polish `spring-security-saml2` following the formatting and checkstyle fixes. Issue gh-8945
1 parent e8094b8 commit 1f03608

20 files changed

+179
-230
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/core/OpenSamlInitializationService.java

+14-19
Original file line numberDiff line numberDiff line change
@@ -118,44 +118,39 @@ public static void requireInitialize(Consumer<XMLObjectProviderRegistry> registr
118118
private static boolean initialize(Consumer<XMLObjectProviderRegistry> registryConsumer) {
119119
if (initialized.compareAndSet(false, true)) {
120120
log.trace("Initializing OpenSAML");
121-
122121
try {
123122
InitializationService.initialize();
124123
}
125124
catch (Exception ex) {
126125
throw new Saml2Exception(ex);
127126
}
128-
129127
BasicParserPool parserPool = new BasicParserPool();
130128
parserPool.setMaxPoolSize(50);
131-
132-
Map<String, Boolean> parserBuilderFeatures = new HashMap<>();
133-
parserBuilderFeatures.put("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
134-
parserBuilderFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
135-
parserBuilderFeatures.put("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
136-
parserBuilderFeatures.put("http://apache.org/xml/features/validation/schema/normalized-value",
137-
Boolean.FALSE);
138-
parserBuilderFeatures.put("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
139-
parserBuilderFeatures.put("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
140-
parserPool.setBuilderFeatures(parserBuilderFeatures);
141-
129+
parserPool.setBuilderFeatures(getParserBuilderFeatures());
142130
try {
143131
parserPool.initialize();
144132
}
145133
catch (Exception ex) {
146134
throw new Saml2Exception(ex);
147135
}
148136
XMLObjectProviderRegistrySupport.setParserPool(parserPool);
149-
150137
registryConsumer.accept(ConfigurationService.get(XMLObjectProviderRegistry.class));
151-
152138
log.debug("Initialized OpenSAML");
153139
return true;
154140
}
155-
else {
156-
log.debug("Refused to re-initialize OpenSAML");
157-
return false;
158-
}
141+
log.debug("Refused to re-initialize OpenSAML");
142+
return false;
143+
}
144+
145+
private static Map<String, Boolean> getParserBuilderFeatures() {
146+
Map<String, Boolean> parserBuilderFeatures = new HashMap<>();
147+
parserBuilderFeatures.put("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
148+
parserBuilderFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
149+
parserBuilderFeatures.put("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
150+
parserBuilderFeatures.put("http://apache.org/xml/features/validation/schema/normalized-value", Boolean.FALSE);
151+
parserBuilderFeatures.put("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
152+
parserBuilderFeatures.put("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
153+
return parserBuilderFeatures;
159154
}
160155

161156
}

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/core/Saml2X509Credential.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
*/
3838
public final class Saml2X509Credential {
3939

40-
public enum Saml2X509CredentialType {
41-
42-
VERIFICATION, ENCRYPTION, SIGNING, DECRYPTION,
43-
44-
}
45-
4640
private final PrivateKey privateKey;
4741

4842
private final X509Certificate certificate;
@@ -225,4 +219,16 @@ private void validateUsages(Saml2X509CredentialType[] usages, Saml2X509Credentia
225219
}
226220
}
227221

222+
public enum Saml2X509CredentialType {
223+
224+
VERIFICATION,
225+
226+
ENCRYPTION,
227+
228+
SIGNING,
229+
230+
DECRYPTION,
231+
232+
}
233+
228234
}

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/credentials/Saml2X509Credential.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@
3939
@Deprecated
4040
public class Saml2X509Credential {
4141

42-
/**
43-
* @deprecated Use
44-
* {@link org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType}
45-
* instead
46-
*/
47-
@Deprecated
48-
public enum Saml2X509CredentialType {
49-
50-
VERIFICATION, ENCRYPTION, SIGNING, DECRYPTION,
51-
52-
}
53-
5442
private final PrivateKey privateKey;
5543

5644
private final X509Certificate certificate;
@@ -199,4 +187,22 @@ private void validateUsages(Saml2X509CredentialType[] usages, Saml2X509Credentia
199187
}
200188
}
201189

190+
/**
191+
* @deprecated Use
192+
* {@link org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType}
193+
* instead
194+
*/
195+
@Deprecated
196+
public enum Saml2X509CredentialType {
197+
198+
VERIFICATION,
199+
200+
ENCRYPTION,
201+
202+
SIGNING,
203+
204+
DECRYPTION,
205+
206+
}
207+
202208
}

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/DefaultSaml2AuthenticatedPrincipal.java

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class DefaultSaml2AuthenticatedPrincipal implements Saml2AuthenticatedPri
3737
public DefaultSaml2AuthenticatedPrincipal(String name, Map<String, List<Object>> attributes) {
3838
Assert.notNull(name, "name cannot be null");
3939
Assert.notNull(attributes, "attributes cannot be null");
40-
4140
this.name = name;
4241
this.attributes = attributes;
4342
}

0 commit comments

Comments
 (0)