-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: archetype fix MP security (#7947)
Signed-off-by: tvallin <[email protected]>
- Loading branch information
Showing
28 changed files
with
968 additions
and
789 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
archetypes/helidon/src/main/archetype/common/files/application.abac.yaml
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
archetypes/helidon/src/main/archetype/common/files/application.oidc.yaml
This file was deleted.
Oops, something went wrong.
225 changes: 1 addition & 224 deletions
225
archetypes/helidon/src/main/archetype/common/security.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
archetypes/helidon/src/main/archetype/mp/custom/files/application.abac.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- abac: | ||
fail-on-unvalidated: true | ||
fail-if-none-validated: true |
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
archetypes/helidon/src/main/archetype/mp/custom/files/application.oidc.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
- oidc: | ||
# use a custom name, so it does not clash with other examples | ||
cookie-name: "OIDC_EXAMPLE_COOKIE" | ||
# support for "Authorization" header with bearer token | ||
header-use: true | ||
# the default redirect-uri, where the webserver listens on redirects from identity server | ||
redirect-uri: "/oidc/redirect" | ||
issuer: "https://tenant.some-server.com/oauth2/default" | ||
audience: "configured audience" | ||
client-id: "some client id" | ||
client-secret: "some client secret" | ||
identity-uri: "https://tenant.some-server.com/oauth2/default" | ||
frontend-uri: "http://localhost:7987" | ||
server-type: "@default" | ||
# We want to redirect to login page (and token can be received either through cookie or header) | ||
redirect: true |
17 changes: 17 additions & 0 deletions
17
...don/src/main/archetype/mp/custom/files/src/main/java/__pkg__/JwtApplication.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package {{package}}; | ||
|
||
import java.util.Set; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.core.Application; | ||
import org.eclipse.microprofile.auth.LoginConfig; | ||
|
||
@LoginConfig(authMethod = "MP-JWT") | ||
@ApplicationScoped | ||
public class JwtApplication extends Application { | ||
@Override | ||
public Set<Class<?>> getClasses() { | ||
return Set.of(JwtResource.class); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...elidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/JwtResource.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package {{package}}; | ||
|
||
import java.util.Optional; | ||
|
||
import io.helidon.security.Principal; | ||
import io.helidon.security.SecurityContext; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN; | ||
|
||
@Path("/hello") | ||
public class JwtResource { | ||
@GET | ||
@Produces(TEXT_PLAIN) | ||
public String hello(@Context SecurityContext context) { | ||
Optional<Principal> userPrincipal = context.userPrincipal(); | ||
return "Hello, " + userPrincipal.get().getName() + "!"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...lidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/OidcResource.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package {{package}}; | ||
|
||
import io.helidon.security.SecurityContext; | ||
import io.helidon.security.annotations.Authenticated; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
/** | ||
* A simple JAX-RS resource with a single GET method. | ||
*/ | ||
@Path("/test") | ||
public class OidcResource { | ||
/** | ||
* Hello world using security context. | ||
* @param securityContext context as established during login | ||
* @return a string with current username | ||
*/ | ||
@Authenticated | ||
@GET | ||
public String getIt(@Context SecurityContext securityContext) { | ||
return "Hello " + securityContext.userName(); | ||
} | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
archetypes/helidon/src/main/archetype/mp/custom/security-outputs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<archetype-script xmlns="https://helidon.io/archetype/2.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd"> | ||
<methods> | ||
<method name="security-oidc"> | ||
<output if="${security.atn} contains ['oidc']"> | ||
<templates engine="mustache" transformations="mustache,packaged"> | ||
<directory>files</directory> | ||
<includes> | ||
<include>**/OidcResource.java.mustache</include> | ||
</includes> | ||
</templates> | ||
<model> | ||
<list key="dependencies"> | ||
<map> | ||
<value key="groupId">io.helidon.microprofile</value> | ||
<value key="artifactId">helidon-microprofile-oidc</value> | ||
</map> | ||
</list> | ||
<list key="providers-config-entries"> | ||
<value file="files/application.oidc.yaml"/> | ||
</list> | ||
<list key="module-requires"> | ||
<value>io.helidon.security</value> | ||
<value>io.helidon.security.annotations</value> | ||
</list> | ||
<list key="readme-sections"> | ||
<value><![CDATA[ | ||
## Security integration with OIDC | ||
This example demonstrates integration with OIDC (Open ID Connect) providers. | ||
To configure it, you need to replace the default values from configuration | ||
to your tenant and application configuration. | ||
]]></value> | ||
</list> | ||
</model> | ||
</output> | ||
</method> | ||
<method name="security-jwt"> | ||
<output if="${security.atn} contains ['jwt']"> | ||
<templates engine="mustache" transformations="mustache,packaged"> | ||
<directory>files</directory> | ||
<includes> | ||
<include>**/JwtApplication.java.mustache</include> | ||
<include>**/JwtResource.java.mustache</include> | ||
</includes> | ||
</templates> | ||
<model> | ||
<list key="dependencies"> | ||
<map> | ||
<value key="groupId">io.helidon.microprofile.jwt</value> | ||
<value key="artifactId">helidon-microprofile-jwt-auth</value> | ||
</map> | ||
</list> | ||
<list key="microprofile-config-entries"> | ||
<value>mp.jwt.verify.issuer=https://{IssuerPublicDomain}/oauth2/default</value> | ||
<value template="mustache">mp.jwt.verify.publickey.location=${mp.jwt.verify.issuer}/v1/keys</value> | ||
</list> | ||
<list key="module-requires"> | ||
<value >io.helidon.microprofile.jwt.auth</value> | ||
</list> | ||
</model> | ||
</output> | ||
</method> | ||
<method name="security-google"> | ||
<output if="${security.atn} contains ['google']"> | ||
<model> | ||
<list key="providers-config-entries"> | ||
<value file="files/application.google.yaml"/> | ||
</list> | ||
</model> | ||
</output> | ||
</method> | ||
<method name="security-signature"> | ||
<output if="${security.atn} contains ['http-signature']"> | ||
<model> | ||
<list key="providers-config-entries"> | ||
<value file="files/application.http-signature.yaml"/> | ||
</list> | ||
</model> | ||
</output> | ||
</method> | ||
<method name="security-abac"> | ||
<output if="${security.atz} contains ['abac']"> | ||
<model> | ||
<list key="providers-config-entries"> | ||
<value file="files/application.abac.yaml"/> | ||
</list> | ||
</model> | ||
</output> | ||
</method> | ||
</methods> | ||
<call method="security-abac"/> | ||
<call method="security-oidc"/> | ||
<call method="security-jwt"/> | ||
<call method="security-google"/> | ||
<call method="security-signature"/> | ||
<output> | ||
<model> | ||
<list key="dependencies"> | ||
<map> | ||
<value key="groupId">io.helidon.microprofile</value> | ||
<value key="artifactId">helidon-microprofile-security</value> | ||
</map> | ||
</list> | ||
<list key="paths-config-entries"> | ||
<value><![CDATA[ - path: "/simple-greet" | ||
methods: ["get"] | ||
authenticate: true]]></value> | ||
</list> | ||
</model> | ||
</output> | ||
</archetype-script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.