Skip to content

Commit a0fe04c

Browse files
committed
Document @ClientRegistrationId on types
Issue gh-17806
1 parent 02a948d commit a0fe04c

File tree

6 files changed

+137
-1
lines changed

6 files changed

+137
-1
lines changed

docs/modules/ROOT/pages/features/integrations/rest/http-interface.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ include-code::./UserService[tag=getAuthenticatedUser]
5151

5252
The xref:features/integrations/rest/http-interface.adoc#client-registration-id[`@ClientRegistrationId`] will be processed by xref:features/integrations/rest/http-interface.adoc#client-registration-id-processor[`ClientRegistrationIdProcessor`]
5353

54+
[[type]]
55+
=== Type Level Declarations
56+
57+
`@ClientRegistrationId` can also be added at the type level to avoid repeating the declaration on every method.
58+
59+
include-code::./UserService[tag=type]
60+
5461
[[client-registration-id-processor]]
5562
== `ClientRegistrationIdProcessor`
5663

docs/modules/ROOT/pages/whats-new.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ http.csrf((csrf) -> csrf.spa());
4949
* Added OAuth2 Support for xref:features/integrations/rest/http-interface.adoc[HTTP Interface Integration]
5050
* Added support for custom `JwkSource` in `NimbusJwtDecoder`, allowing usage of Nimbus's `JwkSourceBuilder` API
5151
* Added builder for `NimbusJwtEncoder`, supports specifying an EC or RSA key pair or a secret key
52-
* Added support for `@ClientRegistrationId` at class level, eliminating the need for method level repetition
52+
* Added support for `@ClientRegistrationId` at the xref:features/integrations/rest/http-interface.adoc#type[type level], eliminating the need for method level repetition
5353

5454
== SAML 2.0
5555

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.docs.features.integrations.rest.type;
18+
19+
/**
20+
* Used to ensure {@link UserService} compiles, but not show in the documentation.
21+
*
22+
* @author Rob Winch
23+
*/
24+
public record Hovercard() {
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain clients copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.docs.features.integrations.rest.type;
18+
19+
import org.springframework.security.docs.features.integrations.rest.clientregistrationid.User;
20+
import org.springframework.security.oauth2.client.annotation.ClientRegistrationId;
21+
import org.springframework.web.bind.annotation.PathVariable;
22+
import org.springframework.web.service.annotation.GetExchange;
23+
import org.springframework.web.service.annotation.HttpExchange;
24+
25+
/**
26+
* Demonstrates a service for {@link ClientRegistrationId} at the type level.
27+
* @author Rob Winch
28+
*/
29+
// tag::type[]
30+
@HttpExchange
31+
@ClientRegistrationId("github")
32+
public interface UserService {
33+
34+
@GetExchange("/user")
35+
User getAuthenticatedUser();
36+
37+
@GetExchange("/users/{username}/hovercard")
38+
Hovercard getHovercard(@PathVariable String username);
39+
40+
}
41+
// end::type[]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.kt.docs.features.integrations.rest.type
18+
19+
/**
20+
* Used to ensure [UserService] compiles, but not show in the documentation.
21+
*
22+
* @author Rob Winch
23+
*/
24+
class Hovercard
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain clients copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.kt.docs.features.integrations.rest.type
18+
19+
import org.springframework.security.kt.docs.features.integrations.rest.clientregistrationid.User
20+
import org.springframework.security.oauth2.client.annotation.ClientRegistrationId
21+
import org.springframework.web.bind.annotation.PathVariable
22+
import org.springframework.web.service.annotation.GetExchange
23+
import org.springframework.web.service.annotation.HttpExchange
24+
25+
/**
26+
* Demonstrates a service for [ClientRegistrationId] at the type level.
27+
* @author Rob Winch
28+
*/
29+
// tag::type[]
30+
@HttpExchange
31+
@ClientRegistrationId("github")
32+
interface UserService {
33+
@GetExchange("/user")
34+
fun getAuthenticatedUser(): User
35+
36+
@GetExchange("/users/{username}/hovercard")
37+
fun getHovercard(@PathVariable username: String): Hovercard
38+
}
39+
// end::type[]

0 commit comments

Comments
 (0)