-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jwt improvements & Updates to support latest dev release of GraalVM n…
…ative image (#8874) * Updates to native image configuration to support latest release of GraalVM. (#8838) * Jwt improvements (#8865) Signed-off-by: David Kral <[email protected]> * Update changelog to document 8838 and 8865 --------- Signed-off-by: David Kral <[email protected]> Co-authored-by: Tomas Langer <[email protected]> Co-authored-by: David Král <[email protected]>
- Loading branch information
1 parent
c8306d1
commit 963c07d
Showing
32 changed files
with
2,219 additions
and
154 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
...TA-INF/native-image/io.helidon.common/helidon-common-configurable/native-image.properties
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,18 @@ | ||
# | ||
# Copyright (c) 2024 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. | ||
# | ||
|
||
Args=--initialize-at-build-time=io.helidon.common.configurable.LruCache \ | ||
--initialize-at-build-time=io.helidon.common.configurable.LruCacheConfig |
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
17 changes: 17 additions & 0 deletions
17
...rces/META-INF/native-image/io.helidon.logging/helidon-logging-jul/native-image.properties
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 @@ | ||
# | ||
# Copyright (c) 2024 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. | ||
# | ||
|
||
Args=--initialize-at-build-time=io.helidon.logging.jul.JulMdcPropagator |
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
100 changes: 100 additions & 0 deletions
100
security/jwt/src/main/java/io/helidon/security/jwt/AudienceValidator.java
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,100 @@ | ||
/* | ||
* Copyright (c) 2024 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. | ||
*/ | ||
|
||
package io.helidon.security.jwt; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import io.helidon.common.Errors; | ||
|
||
/** | ||
* Audience claim validator. | ||
*/ | ||
public final class AudienceValidator extends OptionalValidator { | ||
private final Set<String> expectedAudience; | ||
|
||
private AudienceValidator(Builder builder) { | ||
super(builder); | ||
this.expectedAudience = Set.copyOf(builder.expectedAudience); | ||
} | ||
|
||
/** | ||
* Return a new Builder instance. | ||
* | ||
* @return new builder instance | ||
*/ | ||
public static Builder builder() { | ||
return new Builder() | ||
.addClaim(Jwt.AUDIENCE) | ||
.mandatory(true); | ||
} | ||
|
||
@Override | ||
public void validate(Jwt jwt, Errors.Collector collector, List<ClaimValidator> validators) { | ||
Optional<List<String>> jwtAudiences = jwt.audience(); | ||
jwtAudiences.ifPresent(jwtAudience -> { | ||
if (expectedAudience.stream().anyMatch(jwtAudiences.get()::contains)) { | ||
return; | ||
} | ||
collector.fatal(jwt, "Audience must contain " + expectedAudience + ", yet it is: " + jwtAudiences); | ||
}); | ||
super.validate(Jwt.AUDIENCE, jwtAudiences, collector); | ||
} | ||
|
||
/** | ||
* Builder of the {@link AudienceValidator}. | ||
*/ | ||
public static final class Builder extends OptionalValidator.BaseBuilder<Builder, AudienceValidator> { | ||
|
||
private Set<String> expectedAudience = new HashSet<>(); | ||
|
||
private Builder() { | ||
} | ||
|
||
@Override | ||
public AudienceValidator build() { | ||
return new AudienceValidator(this); | ||
} | ||
|
||
/** | ||
* Add expected audience value. | ||
* | ||
* @param audience expected audience | ||
* @return updated builder instance | ||
*/ | ||
public Builder addExpectedAudience(String audience) { | ||
Objects.requireNonNull(audience); | ||
expectedAudience.add(audience); | ||
return this; | ||
} | ||
|
||
/** | ||
* Overwrite previously set audience with the new {@link Set} of values. | ||
* | ||
* @param expectedAudience expected audience values | ||
* @return updated builder instance | ||
*/ | ||
public Builder expectedAudience(Set<String> expectedAudience) { | ||
Objects.requireNonNull(expectedAudience); | ||
this.expectedAudience = new HashSet<>(expectedAudience); | ||
return this; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
security/jwt/src/main/java/io/helidon/security/jwt/ClaimValidator.java
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,53 @@ | ||
/* | ||
* Copyright (c) 2024 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. | ||
*/ | ||
|
||
package io.helidon.security.jwt; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import io.helidon.common.Errors; | ||
|
||
/** | ||
* JWT claim validator. | ||
*/ | ||
public interface ClaimValidator { | ||
|
||
/** | ||
* Scope of the JWT claims. | ||
* | ||
* @return JWT claim scope | ||
*/ | ||
JwtScope jwtScope(); | ||
|
||
/** | ||
* Handled JWT claims. | ||
* | ||
* @return claims | ||
*/ | ||
Set<String> claims(); | ||
|
||
/** | ||
* Validate JWT against this class's configuration. | ||
* | ||
* @param jwt jwt to validate | ||
* @param collector collector of error messages to add problems to. Use {@link Errors.Collector#fatal(Object, String)} | ||
* to mark the validation as a failure | ||
* @param validators immutable list of all currently processed claim validators | ||
*/ | ||
void validate(Jwt jwt, Errors.Collector collector, List<ClaimValidator> validators); | ||
|
||
} |
Oops, something went wrong.