-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.x: Security context not overridden (#7512)
Security context not overridden Signed-off-by: David Kral <[email protected]>
- Loading branch information
Showing
10 changed files
with
287 additions
and
8 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
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
52 changes: 52 additions & 0 deletions
52
tests/integration/security/security-context-not-overridden/pom.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,52 @@ | ||
<?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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>helidon-tests-integration-security</artifactId> | ||
<groupId>io.helidon.tests.integration</groupId> | ||
<version>3.2.3-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>helidon-tests-integration-security-context-not-overridden</artifactId> | ||
<name>Helidon Tests Integration Security Response Mappers</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.bundles</groupId> | ||
<artifactId>helidon-microprofile</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.tests</groupId> | ||
<artifactId>helidon-microprofile-tests-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
...t-overridden/src/main/java/io/helidon/tests/integration/context/TestEndpointResource.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,44 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.helidon.tests.integration.context; | ||
|
||
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 jakarta.ws.rs.core.MediaType; | ||
|
||
/** | ||
* Simple test endpoint. | ||
*/ | ||
@Path("/test-endpoint") | ||
public class TestEndpointResource { | ||
|
||
/** | ||
* Return user greeting. | ||
* | ||
* @return {@link String} | ||
*/ | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String getDefaultMessage(@Context SecurityContext securityContext) { | ||
return "Hello " + securityContext.userName(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ntext-not-overridden/src/main/java/io/helidon/tests/integration/context/TestProvider.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,31 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.helidon.tests.integration.context; | ||
|
||
import io.helidon.security.AuthenticationResponse; | ||
import io.helidon.security.ProviderRequest; | ||
import io.helidon.security.spi.AuthenticationProvider; | ||
import io.helidon.security.spi.SynchronousProvider; | ||
|
||
class TestProvider extends SynchronousProvider implements AuthenticationProvider{ | ||
|
||
@Override | ||
protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { | ||
return AuthenticationResponse.abstain(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ot-overridden/src/main/java/io/helidon/tests/integration/context/TestProviderService.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,39 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.helidon.tests.integration.context; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.security.spi.SecurityProvider; | ||
import io.helidon.security.spi.SecurityProviderService; | ||
|
||
public class TestProviderService implements SecurityProviderService { | ||
@Override | ||
public String providerConfigKey() { | ||
return "test"; | ||
} | ||
|
||
@Override | ||
public Class<? extends SecurityProvider> providerClass() { | ||
return TestProvider.class; | ||
} | ||
|
||
@Override | ||
public SecurityProvider providerInstance(Config config) { | ||
return new TestProvider(); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...dden/src/main/resources/META-INF/services/io.helidon.security.spi.SecurityProviderService
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 @@ | ||
io.helidon.tests.integration.context.TestProviderService |
31 changes: 31 additions & 0 deletions
31
.../integration/security/security-context-not-overridden/src/main/resources/application.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,31 @@ | ||
# | ||
# 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. | ||
# | ||
security: | ||
providers: | ||
- abac: | ||
- test: | ||
optional: true | ||
- http-basic-auth: | ||
realm: "helidon" | ||
users: | ||
- login: "test" | ||
password: "password" | ||
roles: ["user"] | ||
web-server: | ||
paths: | ||
- path: "/test-endpoint[/{*}]" | ||
authenticate: true | ||
authenticator: "http-basic-auth" |
23 changes: 23 additions & 0 deletions
23
...ntegration/security/security-context-not-overridden/src/main/resources/logging.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,23 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
handlers = java.util.logging.ConsoleHandler | ||
|
||
java.util.logging.ConsoleHandler.level = FINEST | ||
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter | ||
java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n | ||
|
||
.level = INFO |
51 changes: 51 additions & 0 deletions
51
...ntext-not-overridden/src/test/java/io/helidon/tests/integration/context/SecurityTest.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,51 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.helidon.tests.integration.context; | ||
|
||
import io.helidon.microprofile.tests.junit5.AddBean; | ||
import io.helidon.microprofile.tests.junit5.HelidonTest; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.client.WebTarget; | ||
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@HelidonTest | ||
@AddBean(TestEndpointResource.class) | ||
public class SecurityTest { | ||
|
||
private final WebTarget target; | ||
|
||
@Inject | ||
SecurityTest(WebTarget target) { | ||
this.target = target; | ||
} | ||
|
||
@Test | ||
void testNotPropagatedSecurityContext() { | ||
String response = target.register(HttpAuthenticationFeature.basic("test", "password")) | ||
.path("/test-endpoint") | ||
.request() | ||
.get(String.class); | ||
assertThat(response, is("Hello test")); | ||
} | ||
|
||
|
||
} |