Skip to content

Commit 834f819

Browse files
author
chao.wang
committed
Format code
1 parent 0025fe9 commit 834f819

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/JdbcAssertingPartyMetadataRepository.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
28+
2829
import org.springframework.core.log.LogMessage;
2930
import org.springframework.core.serializer.DefaultDeserializer;
3031
import org.springframework.core.serializer.Deserializer;
@@ -47,8 +48,8 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
4748

4849
private final JdbcOperations jdbcOperations;
4950

50-
private RowMapper<AssertingPartyMetadata> assertingPartyMetadataRowMapper =
51-
new AssertingPartyMetadataRowMapper(ResultSet::getBytes);
51+
private RowMapper<AssertingPartyMetadata> assertingPartyMetadataRowMapper = new AssertingPartyMetadataRowMapper(
52+
ResultSet::getBytes);
5253

5354
// @formatter:off
5455
static final String COLUMN_NAMES = "entity_id, "
@@ -79,7 +80,6 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
7980
/**
8081
* Constructs a {@code JdbcRelyingPartyRegistrationRepository} using the provided
8182
* parameters.
82-
*
8383
* @param jdbcOperations the JDBC operations
8484
*/
8585
public JdbcAssertingPartyMetadataRepository(JdbcOperations jdbcOperations) {
@@ -91,21 +91,18 @@ public JdbcAssertingPartyMetadataRepository(JdbcOperations jdbcOperations) {
9191
* Sets the {@link RowMapper} used for mapping the current row in
9292
* {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}. The default is
9393
* {@link AssertingPartyMetadataRowMapper}.
94-
*
9594
* @param assertingPartyMetadataRowMapper the {@link RowMapper} used for mapping the
96-
* current row in {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}
95+
* current row in {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}
9796
*/
98-
public void setAssertingPartyMetadataRowMapper(
99-
RowMapper<AssertingPartyMetadata> assertingPartyMetadataRowMapper) {
97+
public void setAssertingPartyMetadataRowMapper(RowMapper<AssertingPartyMetadata> assertingPartyMetadataRowMapper) {
10098
Assert.notNull(assertingPartyMetadataRowMapper, "assertingPartyMetadataRowMapper cannot be null");
10199
this.assertingPartyMetadataRowMapper = assertingPartyMetadataRowMapper;
102100
}
103101

104102
@Override
105103
public AssertingPartyMetadata findByEntityId(String entityId) {
106104
Assert.hasText(entityId, "entityId cannot be empty");
107-
SqlParameterValue[] parameters = new SqlParameterValue[]{
108-
new SqlParameterValue(Types.VARCHAR, entityId)};
105+
SqlParameterValue[] parameters = new SqlParameterValue[] { new SqlParameterValue(Types.VARCHAR, entityId) };
109106
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters);
110107
List<AssertingPartyMetadata> result = this.jdbcOperations.query(LOAD_BY_ID_SQL, pss,
111108
this.assertingPartyMetadataRowMapper);
@@ -123,7 +120,7 @@ public Iterator<AssertingPartyMetadata> iterator() {
123120
* The default {@link RowMapper} that maps the current row in
124121
* {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}.
125122
*/
126-
private final static class AssertingPartyMetadataRowMapper implements RowMapper<AssertingPartyMetadata> {
123+
private static final class AssertingPartyMetadataRowMapper implements RowMapper<AssertingPartyMetadata> {
127124

128125
private final Log logger = LogFactory.getLog(AssertingPartyMetadataRowMapper.class);
129126

@@ -151,38 +148,37 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
151148
AssertingPartyMetadata.Builder<?> builder = new AssertingPartyDetails.Builder();
152149
try {
153150
if (signingAlgorithmsBytes != null) {
154-
List<String> signingAlgorithms = (List<String>)
155-
this.deserializer.deserializeFromByteArray(signingAlgorithmsBytes);
156-
builder.signingAlgorithms(algorithms -> algorithms.addAll(signingAlgorithms));
151+
List<String> signingAlgorithms = (List<String>) this.deserializer
152+
.deserializeFromByteArray(signingAlgorithmsBytes);
153+
builder.signingAlgorithms((algorithms) -> algorithms.addAll(signingAlgorithms));
157154
}
158155
if (verificationCredentialsBytes != null) {
159-
Collection<Saml2X509Credential> verificationCredentials = (Collection<Saml2X509Credential>)
160-
this.deserializer.deserializeFromByteArray(verificationCredentialsBytes);
161-
builder.verificationX509Credentials(
162-
credentials -> credentials.addAll(verificationCredentials));
156+
Collection<Saml2X509Credential> verificationCredentials = (Collection<Saml2X509Credential>) this.deserializer
157+
.deserializeFromByteArray(verificationCredentialsBytes);
158+
builder.verificationX509Credentials((credentials) -> credentials.addAll(verificationCredentials));
163159
}
164160
if (encryptionCredentialsBytes != null) {
165-
Collection<Saml2X509Credential> encryptionCredentials = (Collection<Saml2X509Credential>)
166-
this.deserializer.deserializeFromByteArray(encryptionCredentialsBytes);
167-
builder.encryptionX509Credentials(
168-
credentials -> credentials.addAll(encryptionCredentials));
161+
Collection<Saml2X509Credential> encryptionCredentials = (Collection<Saml2X509Credential>) this.deserializer
162+
.deserializeFromByteArray(encryptionCredentialsBytes);
163+
builder.encryptionX509Credentials((credentials) -> credentials.addAll(encryptionCredentials));
169164
}
170-
} catch (Exception ex) {
171-
this.logger.debug(
172-
LogMessage.format("Parsing serialized credentials for entity %s failed", entityId), ex);
165+
}
166+
catch (Exception ex) {
167+
this.logger.debug(LogMessage.format("Parsing serialized credentials for entity %s failed", entityId),
168+
ex);
173169
return null;
174170
}
175171

176-
builder
177-
.entityId(entityId)
178-
.wantAuthnRequestsSigned(singleSignOnSignRequest)
179-
.singleSignOnServiceLocation(singleSignOnUrl)
180-
.singleSignOnServiceBinding(singleSignOnBinding)
181-
.singleLogoutServiceLocation(singleLogoutUrl)
182-
.singleLogoutServiceBinding(singleLogoutBinding)
183-
.singleLogoutServiceResponseLocation(singleLogoutResponseUrl);
172+
builder.entityId(entityId)
173+
.wantAuthnRequestsSigned(singleSignOnSignRequest)
174+
.singleSignOnServiceLocation(singleSignOnUrl)
175+
.singleSignOnServiceBinding(singleSignOnBinding)
176+
.singleLogoutServiceLocation(singleLogoutUrl)
177+
.singleLogoutServiceBinding(singleLogoutBinding)
178+
.singleLogoutServiceResponseLocation(singleLogoutResponseUrl);
184179
return builder.build();
185180
}
181+
186182
}
187183

188184
private interface GetBytes {

saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/registration/JdbcAssertingPartyMetadataRepositoryTests.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.junit.jupiter.api.AfterEach;
1212
import org.junit.jupiter.api.BeforeEach;
1313
import org.junit.jupiter.api.Test;
14+
1415
import org.springframework.core.io.ClassPathResource;
1516
import org.springframework.core.serializer.DefaultSerializer;
1617
import org.springframework.core.serializer.Serializer;
@@ -32,8 +33,7 @@ class JdbcAssertingPartyMetadataRepositoryTests {
3233
private static final String SCHEMA_SQL_RESOURCE = "org/springframework/security/saml2/saml2-asserting-party-metadata-schema.sql";
3334

3435
private static final String SAVE_SQL = "INSERT INTO saml2_asserting_party_metadata ("
35-
+ JdbcAssertingPartyMetadataRepository.COLUMN_NAMES
36-
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
36+
+ JdbcAssertingPartyMetadataRepository.COLUMN_NAMES + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
3737

3838
private static final String ENTITY_ID = "https://localhost/simplesaml/saml2/idp/metadata.php";
3939

@@ -97,8 +97,8 @@ void findByEntityId() throws IOException {
9797
this.jdbcOperations.update(SAVE_SQL, ENTITY_ID, SINGLE_SIGNON_URL, SINGLE_SIGNON_BINDING,
9898
SINGLE_SIGNON_SIGN_REQUEST, this.serializer.serializeToByteArray(SIGNING_ALGORITHMS),
9999
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
100-
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
101-
SINGLE_LOGOUT_URL, SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
100+
this.serializer.serializeToByteArray(asCredentials(this.certificate)), SINGLE_LOGOUT_URL,
101+
SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
102102

103103
AssertingPartyMetadata found = this.repository.findByEntityId(ENTITY_ID);
104104

@@ -126,15 +126,15 @@ void iterator() throws IOException {
126126
this.jdbcOperations.update(SAVE_SQL, ENTITY_ID, SINGLE_SIGNON_URL, SINGLE_SIGNON_BINDING,
127127
SINGLE_SIGNON_SIGN_REQUEST, this.serializer.serializeToByteArray(SIGNING_ALGORITHMS),
128128
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
129-
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
130-
SINGLE_LOGOUT_URL, SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
129+
this.serializer.serializeToByteArray(asCredentials(this.certificate)), SINGLE_LOGOUT_URL,
130+
SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
131131

132-
this.jdbcOperations.update(SAVE_SQL, "https://localhost/simplesaml2/saml2/idp/metadata.php",
133-
SINGLE_SIGNON_URL, SINGLE_SIGNON_BINDING,
134-
SINGLE_SIGNON_SIGN_REQUEST, this.serializer.serializeToByteArray(SIGNING_ALGORITHMS),
132+
this.jdbcOperations.update(SAVE_SQL, "https://localhost/simplesaml2/saml2/idp/metadata.php", SINGLE_SIGNON_URL,
133+
SINGLE_SIGNON_BINDING, SINGLE_SIGNON_SIGN_REQUEST,
134+
this.serializer.serializeToByteArray(SIGNING_ALGORITHMS),
135135
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
136-
this.serializer.serializeToByteArray(asCredentials(this.certificate)),
137-
SINGLE_LOGOUT_URL, SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
136+
this.serializer.serializeToByteArray(asCredentials(this.certificate)), SINGLE_LOGOUT_URL,
137+
SINGLE_LOGOUT_RESPONSE_URL, SINGLE_LOGOUT_BINDING);
138138

139139
Iterator<AssertingPartyMetadata> iterator = this.repository.iterator();
140140
AssertingPartyMetadata first = iterator.next();
@@ -144,7 +144,6 @@ void iterator() throws IOException {
144144
assertThat(iterator.hasNext()).isFalse();
145145
}
146146

147-
148147
private static EmbeddedDatabase createDb() {
149148
return createDb(SCHEMA_SQL_RESOURCE);
150149
}
@@ -164,7 +163,8 @@ private X509Certificate loadCertificate(String path) {
164163
try (InputStream is = new ClassPathResource(path).getInputStream()) {
165164
CertificateFactory factory = CertificateFactory.getInstance("X.509");
166165
return (X509Certificate) factory.generateCertificate(is);
167-
} catch (Exception ex) {
166+
}
167+
catch (Exception ex) {
168168
throw new RuntimeException("Error loading certificate from " + path, ex);
169169
}
170170
}
@@ -173,4 +173,5 @@ private Collection<Saml2X509Credential> asCredentials(X509Certificate certificat
173173
return List.of(new Saml2X509Credential(certificate, Saml2X509Credential.Saml2X509CredentialType.ENCRYPTION,
174174
Saml2X509Credential.Saml2X509CredentialType.VERIFICATION));
175175
}
176+
176177
}

0 commit comments

Comments
 (0)