Skip to content

Commit 36f1249

Browse files
committed
Polish
1 parent 71acc90 commit 36f1249

File tree

9 files changed

+92
-51
lines changed

9 files changed

+92
-51
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static class ExemplarsConfiguration {
295295
@Bean
296296
SpanContextSupplier spanContextSupplier() {
297297
return new SpanContextSupplier() {
298+
298299
@Override
299300
public String getTraceId() {
300301
return null;
@@ -304,6 +305,7 @@ public String getTraceId() {
304305
public String getSpanId() {
305306
return null;
306307
}
308+
307309
};
308310
}
309311

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/DefaultGraphQlSchemaCondition.java

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
5858
boolean match = false;
5959
List<ConditionMessage> messages = new ArrayList<>(2);
6060
ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnGraphQlSchema.class);
61-
6261
Binder binder = Binder.get(context.getEnvironment());
6362
GraphQlProperties.Schema schema = binder.bind("spring.graphql.schema", GraphQlProperties.Schema.class)
6463
.orElse(new GraphQlProperties.Schema());

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333

3434
/**
3535
* {@link EnableAutoConfiguration Auto-configuration} for {@link RSocketGraphQlClient}.
36-
* This auto-configuration creates {@link RSocketGraphQlClient.Builder} prototype beans,
37-
* as the builders are stateful and should not be reused to build client instances with
38-
* different configurations.
36+
* This auto-configuration creates
37+
* {@link org.springframework.graphql.client.RSocketGraphQlClient.Builder
38+
* RSocketGraphQlClient.Builder} prototype beans, as the builders are stateful and should
39+
* not be reused to build client instances with different configurations.
3940
*
4041
* @author Brian Clozel
4142
* @since 2.7.0

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @author Madhura Bhave
3232
* @author Phillip Webb
33+
* @author Moritz Halbritter
3334
* @since 2.2.0
3435
*/
3536
@ConfigurationProperties("spring.security.saml2.relyingparty")

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java

+73-34
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.springframework.context.annotation.Conditional;
4141
import org.springframework.context.annotation.Configuration;
4242
import org.springframework.core.io.Resource;
43+
import org.springframework.core.log.LogMessage;
4344
import org.springframework.security.converter.RsaKeyConverters;
4445
import org.springframework.security.saml2.core.Saml2X509Credential;
4546
import org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType;
@@ -49,6 +50,7 @@
4950
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder;
5051
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
5152
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations;
53+
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding;
5254
import org.springframework.util.Assert;
5355
import org.springframework.util.StringUtils;
5456

@@ -58,6 +60,7 @@
5860
*
5961
* @author Madhura Bhave
6062
* @author Phillip Webb
63+
* @author Moritz Halbritter
6164
*/
6265
@Configuration(proxyBeanMethods = false)
6366
@Conditional(RegistrationConfiguredCondition.class)
@@ -78,21 +81,20 @@ private RelyingPartyRegistration asRegistration(Map.Entry<String, Registration>
7881
}
7982

8083
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
81-
boolean usingMetadata = StringUtils
82-
.hasText(getFromAssertingParty(properties, id, "metadata-uri", AssertingParty::getMetadataUri));
83-
Builder builder = (usingMetadata) ? RelyingPartyRegistrations
84-
.fromMetadataLocation(
85-
getFromAssertingParty(properties, id, "metadata-uri", AssertingParty::getMetadataUri))
86-
.registrationId(id) : RelyingPartyRegistration.withRegistrationId(id);
84+
AssertingPartyProperties assertingParty = new AssertingPartyProperties(properties, id);
85+
boolean usingMetadata = StringUtils.hasText(assertingParty.getMetadataUri());
86+
Builder builder = (usingMetadata)
87+
? RelyingPartyRegistrations.fromMetadataLocation(assertingParty.getMetadataUri()).registrationId(id)
88+
: RelyingPartyRegistration.withRegistrationId(id);
8789
builder.assertionConsumerServiceLocation(properties.getAcs().getLocation());
8890
builder.assertionConsumerServiceBinding(properties.getAcs().getBinding());
8991
builder.assertingPartyDetails(mapAssertingParty(properties, id, usingMetadata));
9092
builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream()
9193
.map(this::asSigningCredential).forEach(credentials::add));
9294
builder.decryptionX509Credentials((credentials) -> properties.getDecryption().getCredentials().stream()
9395
.map(this::asDecryptionCredential).forEach(credentials::add));
94-
builder.assertingPartyDetails((details) -> details.verificationX509Credentials(
95-
(credentials) -> getFromAssertingParty(properties, id, "verification", AssertingParty::getVerification)
96+
builder.assertingPartyDetails(
97+
(details) -> details.verificationX509Credentials((credentials) -> assertingParty.getVerification()
9698
.getCredentials().stream().map(this::asVerificationCredential).forEach(credentials::add)));
9799
builder.entityId(properties.getEntityId());
98100
RelyingPartyRegistration registration = builder.build();
@@ -101,35 +103,15 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
101103
return registration;
102104
}
103105

104-
@SuppressWarnings("deprecation")
105-
private <T> T getFromAssertingParty(Registration registration, String id, String name,
106-
Function<AssertingParty, T> getter) {
107-
T newValue = getter.apply(registration.getAssertingParty());
108-
if (newValue != null) {
109-
return newValue;
110-
}
111-
T deprecatedValue = getter.apply(registration.getIdentityprovider());
112-
if (deprecatedValue != null) {
113-
logger.warn(String.format(
114-
"Property 'spring.security.saml2.relyingparty.registration.identityprovider.%1$s.%2$s' is deprecated, please use 'spring.security.saml2.relyingparty.registration.asserting-party.%1$s.%2$s' instead",
115-
id, name));
116-
return deprecatedValue;
117-
}
118-
return newValue;
119-
}
120-
121106
private Consumer<AssertingPartyDetails.Builder> mapAssertingParty(Registration registration, String id,
122107
boolean usingMetadata) {
123-
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
124108
return (details) -> {
125-
map.from(() -> getFromAssertingParty(registration, id, "entity-id", AssertingParty::getEntityId))
126-
.to(details::entityId);
127-
map.from(() -> getFromAssertingParty(registration, id, "singlesignon.binding",
128-
(property) -> property.getSinglesignon().getBinding())).to(details::singleSignOnServiceBinding);
129-
map.from(() -> getFromAssertingParty(registration, id, "singlesignon.url",
130-
(property) -> property.getSinglesignon().getUrl())).to(details::singleSignOnServiceLocation);
131-
map.from(() -> getFromAssertingParty(registration, id, "singlesignon.sign-request",
132-
(property) -> property.getSinglesignon().getSignRequest())).when((ignored) -> !usingMetadata)
109+
AssertingPartyProperties assertingParty = new AssertingPartyProperties(registration, id);
110+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
111+
map.from(assertingParty::getEntityId).to(details::entityId);
112+
map.from(assertingParty::getSingleSignonBinding).to(details::singleSignOnServiceBinding);
113+
map.from(assertingParty::getSingleSignonUrl).to(details::singleSignOnServiceLocation);
114+
map.from(assertingParty::getSingleSignonSignRequest).when((ignored) -> !usingMetadata)
133115
.to(details::wantAuthnRequestsSigned);
134116
};
135117
}
@@ -181,4 +163,61 @@ private X509Certificate readCertificate(Resource location) {
181163
}
182164
}
183165

166+
/**
167+
* Access to {@link AssertingParty} properties taking into account deprecations.
168+
*/
169+
private static class AssertingPartyProperties {
170+
171+
private final Registration registration;
172+
173+
private final String id;
174+
175+
AssertingPartyProperties(Registration registration, String id) {
176+
this.registration = registration;
177+
this.id = id;
178+
}
179+
180+
String getMetadataUri() {
181+
return get("metadata-uri", AssertingParty::getMetadataUri);
182+
}
183+
184+
Verification getVerification() {
185+
return get("verification", AssertingParty::getVerification);
186+
}
187+
188+
String getEntityId() {
189+
return get("entity-id", AssertingParty::getEntityId);
190+
}
191+
192+
Saml2MessageBinding getSingleSignonBinding() {
193+
return get("singlesignon.binding", (property) -> property.getSinglesignon().getBinding());
194+
}
195+
196+
String getSingleSignonUrl() {
197+
return get("singlesignon.url", (property) -> property.getSinglesignon().getUrl());
198+
}
199+
200+
Boolean getSingleSignonSignRequest() {
201+
return get("singlesignon.sign-request", (property) -> property.getSinglesignon().getSignRequest());
202+
}
203+
204+
@SuppressWarnings("deprecation")
205+
private <T> T get(String name, Function<AssertingParty, T> getter) {
206+
T newValue = getter.apply(this.registration.getAssertingParty());
207+
if (newValue != null) {
208+
return newValue;
209+
}
210+
T deprecatedValue = getter.apply(this.registration.getIdentityprovider());
211+
if (deprecatedValue != null) {
212+
logger.warn(LogMessage.format(
213+
"Property 'spring.security.saml2.relyingparty.registration.identityprovider.%1$s.%2$s' is deprecated, "
214+
+ "please use 'spring.security.saml2.relyingparty.registration.asserting-party.%1$s.%2$s' instead",
215+
this.id, name));
216+
return deprecatedValue;
217+
}
218+
return newValue;
219+
}
220+
221+
}
222+
184223
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.security.servlet;
1818

19-
import java.util.EnumSet;
20-
2119
import javax.servlet.DispatcherType;
2220

2321
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -65,7 +63,9 @@ static class SecurityFilterChainConfiguration {
6563
@Bean
6664
@Order(SecurityProperties.BASIC_AUTH_ORDER)
6765
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
68-
http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
66+
http.authorizeRequests().anyRequest().authenticated();
67+
http.formLogin();
68+
http.httpBasic();
6969
return http.build();
7070
}
7171

@@ -83,7 +83,7 @@ static class ErrorPageSecurityFilterConfiguration {
8383
FilterRegistrationBean<ErrorPageSecurityFilter> errorPageSecurityFilter(ApplicationContext context) {
8484
FilterRegistrationBean<ErrorPageSecurityFilter> registration = new FilterRegistrationBean<>(
8585
new ErrorPageSecurityFilter(context));
86-
registration.setDispatcherTypes(EnumSet.of(DispatcherType.ERROR));
86+
registration.setDispatcherTypes(DispatcherType.ERROR);
8787
return registration;
8888
}
8989

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* Tests for {@link Saml2RelyingPartyAutoConfiguration}.
5454
*
5555
* @author Madhura Bhave
56+
* @author Moritz Halbritter
5657
*/
5758
class Saml2RelyingPartyAutoConfigurationTests {
5859

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/spring-graphql.adoc

+6-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Because GraphQL is transport-agnostic, you'll also need to have one or more addi
3131

3232
[[web.graphql.schema]]
3333
=== GraphQL Schema
34-
3534
A Spring GraphQL application requires a defined schema at startup.
3635
By default, you can write ".graphqls" or ".gqls" schema files under `src/main/resources/graphql/**` and Spring Boot will pick them up automatically.
3736
You can customize the locations with configprop:spring.graphql.schema.locations[] and the file extensions with configprop:spring.graphql.schema.file-extensions[].
@@ -46,9 +45,10 @@ include::{docs-resources}/graphql/schema.graphqls[]
4645
NOTE: By default, https://spec.graphql.org/draft/#sec-Introspection[field introspection] will be allowed on the schema as it is required for tools such as GraphiQL.
4746
If you wish to not expose information about the schema, you can disable introspection by setting configprop:spring.graphql.schema.introspection.enabled[] to `false`.
4847

48+
49+
4950
[[web.graphql.runtimewiring]]
5051
=== GraphQL RuntimeWiring
51-
5252
The GraphQL Java `RuntimeWiring.Builder` can be used to register custom scalar types, directives, type resolvers, `DataFetcher`s, and more.
5353
You can declare `RuntimeWiringConfigurer` beans in your Spring config to get access to the `RuntimeWiring.Builder`.
5454
Spring Boot detects such beans and adds them to the {spring-graphql-docs}#execution-graphqlsource[GraphQlSource builder].
@@ -63,7 +63,6 @@ include::code:GreetingController[]
6363

6464
[[web.graphql.data-query]]
6565
=== Querydsl and QueryByExample Repositories support
66-
6766
Spring Data offers support for both Querydsl and QueryByExample repositories.
6867
Spring GraphQL can {spring-graphql-docs}#data[configure Querydsl and QueryByExample repositories as `DataFetcher`].
6968

@@ -80,9 +79,10 @@ are detected by Spring Boot and considered as candidates for `DataFetcher` for m
8079
[[web.graphql.transports]]
8180
=== Transports
8281

82+
83+
8384
[[web.graphql.transports.http-websocket]]
8485
==== HTTP and WebSocket
85-
8686
The GraphQL HTTP endpoint is at HTTP POST "/graphql" by default. The path can be customized with configprop:spring.graphql.path[].
8787

8888
The GraphQL WebSocket endpoint is off by default. To enable it:
@@ -112,9 +112,9 @@ Spring Boot supports many configuration properties under the `spring.graphql.cor
112112
----
113113

114114

115+
115116
[[web.graphql.transports.rsocket]]
116117
==== RSocket
117-
118118
RSocket is also supported as a transport, on top of WebSocket or TCP.
119119
Once the <<messaging#messaging.rsocket.server-auto-configuration,RSocket server is configured>>, we can configure our GraphQL handler on a particular route using configprop:spring.graphql.rsocket.mapping[].
120120
For example, configuring that mapping as `"graphql"` means we can use that as a route when sending requests with the `RSocketGraphQlClient`.
@@ -127,9 +127,9 @@ And then send a request:
127127
include::code:RSocketGraphQlClientExample[tag=request]
128128

129129

130+
130131
[[web.graphql.exception-handling]]
131132
=== Exceptions Handling
132-
133133
Spring GraphQL enables applications to register one or more Spring `DataFetcherExceptionResolver` components that are invoked sequentially.
134134
The Exception must be resolved to a list of `graphql.GraphQLError` objects, see {spring-graphql-docs}#execution-exceptions[Spring GraphQL exception handling documentation].
135135
Spring Boot will automatically detect `DataFetcherExceptionResolver` beans and register them with the `GraphQlSource.Builder`.
@@ -138,7 +138,6 @@ Spring Boot will automatically detect `DataFetcherExceptionResolver` beans and r
138138

139139
[[web.graphql.graphiql]]
140140
=== GraphiQL and Schema printer
141-
142141
Spring GraphQL offers infrastructure for helping developers when consuming or developing a GraphQL API.
143142

144143
Spring GraphQL ships with a default https://github.com/graphql/graphiql[GraphiQL] page that is exposed at `"/graphiql"` by default.

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public ExecutionGraphQlServiceTester graphQlTester(ExecutionGraphQlService graph
5151
ObjectProvider<ObjectMapper> objectMapperProvider) {
5252
ExecutionGraphQlServiceTester.Builder<?> builder = ExecutionGraphQlServiceTester.builder(graphQlService);
5353
objectMapperProvider.ifAvailable((objectMapper) -> {
54-
final MediaType[] mediaTypes = new MediaType[] { MediaType.APPLICATION_JSON,
55-
MediaType.APPLICATION_GRAPHQL };
54+
MediaType[] mediaTypes = new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_GRAPHQL };
5655
builder.encoder(new Jackson2JsonEncoder(objectMapper, mediaTypes));
5756
builder.decoder(new Jackson2JsonDecoder(objectMapper, mediaTypes));
5857
});

0 commit comments

Comments
 (0)