-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQ] Spring Server generators should allow for adding OAuth2 Preauthorize annotations based on scope #1975
Comments
As this will target the Java and Kotlin Spring generators, I'd appreciate any thoughts or feedback you have on this. I think adding a new config property 'use.spring.security.oauth' which would add the appropriate I will also look at the generated build.gradle/pom.xml file to ensure that if required, the appropriate spring security dependencies are brought in. @jimschubert, @dr4ke616, @bbdouglas, @JFCote, @sreeshas, @jfiala, @lukoyanov, @cbornet, @jeff9finger Let me know if I haven't explained things sufficiently. |
@mikezx6r Did you find a way to do this yet? since adding |
It's been a long time since I've even thought about this. I believe the @PreAuthorize needs to be with the @mapping, and that's on the interface. So yes, it won't work if you put it on the Controller. But at the moment, I'm not using this project (not writing REST Services, doing other work) |
…rator into OpenAPIToolsgh-1975 � Conflicts: � modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
…rator into OpenAPIToolsgh-1975 # Conflicts: # modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java # samples/client/petstore/dart2/openapi/.openapi-generator/VERSION
…rator into OpenAPIToolsgh-1975 � Conflicts: � samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md � samples/openapi3/client/petstore/python/docs/FakeApi.md � samples/server/petstore/python-aiohttp-srclayout/Makefile
…rator into OpenAPIToolsgh-1975 # Conflicts: # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/ApiClient.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/ApiException.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/ApiResponse.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/Configuration.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/CustomInstantDeserializer.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/JSON.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/Pair.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/ServerConfiguration.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/ServerVariable.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/StringUtil.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/AnotherFakeApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/DefaultApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/FakeApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/PetApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/StoreApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/api/UserApi.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/ApiKeyAuth.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/Authentication.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/HttpBasicAuth.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/OAuth.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/auth/OAuthFlow.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/EnumTest.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/Foo.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/FormatTest.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/HealthCheckResult.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject1.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject2.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject3.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject4.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineObject5.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/InlineResponseDefault.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/NullableClass.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/OuterEnumDefaultValue.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/OuterEnumInteger.java # samples/client/petstore/java/jersey2-experimental/src/main/java/org/openapitools/client/model/OuterEnumIntegerDefaultValue.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/RFC3339DateFormat.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Animal.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnly.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ArrayOfNumberOnly.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ArrayTest.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Capitalization.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Cat.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/CatAllOf.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Category.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ClassModel.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Client.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Dog.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/DogAllOf.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/EnumArrays.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/EnumClass.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/MapTest.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Model200Response.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ModelApiResponse.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ModelReturn.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Name.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/NumberOnly.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Order.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/OuterComposite.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/OuterEnum.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Pet.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/ReadOnlyFirst.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/SpecialModelName.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/Tag.java # samples/server/petstore/spring-security/src/main/java/org/openapitools/model/User.java
…rator into OpenAPIToolsgh-1975-VI � Conflicts: � bin/spring-all-petstore.sh � modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
…rator into OpenAPIToolsgh-1975-VI � Conflicts: � bin/spring-all-petstore.sh � modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
…nAPIToolsgh-1975-VI # Conflicts: # bin/spring-all-petstore.sh # modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
Hi, in my opinion this pull request #6358 should NOT close the issue about the oauth2 as it is not fixing the kotlin-spring and this is referenced here as well. Also happy to create a seperate issue for the kotlin-spring if that is requestes |
Hi there. There is quite sometime since last comment on this issue? Any progress on this? |
@epochcoder I tried with having the @PreAuthorize on a controller implementation and all the Spring mvc mappings on an interface and this one has worked like a charm. BTW, I have used Spring mvc 5.3.6 and Spring boot started security 2.4.5. |
Hello team, Just for clarification, does this mean that when you specify a endpoint with scope restrictions. Or may be I missed something. |
Using OAuth JWT scopes and Spring Security's PreAuthorize annotation requires the PreAuthorize annotation to be on the same method as the Mapping related annotation.
With the current generators (Java/Kotlin), the Mapping annotation is in generated code, so manually adding the PreAuthorize annotation can't be done without modifying generated code.
It would be good if the generator had a flag for Spring Security, and would then leverage the OAuth2 security settings to add @PreAuthorize() annotations to the Controller class methods with the Mapping related annotations.
This is dependent on #392 being corrected first.
The text was updated successfully, but these errors were encountered: