-
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.
Authorized set to false fix Signed-off-by: David Kral <david.k.kral@oracle.com>
- Loading branch information
Showing
8 changed files
with
280 additions
and
6 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
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,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<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> | ||
<groupId>io.helidon.tests.integration</groupId> | ||
<artifactId>helidon-tests-integration-security</artifactId> | ||
<version>4.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
|
||
<artifactId>helidon-tests-integration-security-annotation</artifactId> | ||
<name>Helidon Tests Integration Security Annotations</name> | ||
|
||
<description> | ||
Integration test for security annotations | ||
</description> | ||
|
||
<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.testing</groupId> | ||
<artifactId>helidon-microprofile-testing-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
59 changes: 59 additions & 0 deletions
59
...otation/src/main/java/io/helidon/tests/integration/security/annotation/AdminResource.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,59 @@ | ||
/* | ||
* 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.tests.integration.security.annotation; | ||
|
||
import io.helidon.security.annotations.Authenticated; | ||
import io.helidon.security.annotations.Authorized; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
/** | ||
* An admin resource that should not be accessible without proper credentials. | ||
*/ | ||
@Path("/admin") | ||
public class AdminResource { | ||
|
||
/** | ||
* The resource. | ||
* | ||
* @return admin secret. | ||
*/ | ||
@GET | ||
@Authenticated | ||
@Authorized | ||
@RolesAllowed("admin") | ||
public String admin() { | ||
return "admin"; | ||
} | ||
|
||
|
||
/** | ||
* The resource. | ||
* | ||
* @return admin secret. | ||
*/ | ||
@GET | ||
@Path("/unauthorized") | ||
@Authenticated | ||
@Authorized(false) | ||
@RolesAllowed("admin") | ||
public String unauthorizedAdmin() { | ||
return "unauthorized admin"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/integration/security/security-annotation/src/main/resources/META-INF/beans.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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee | ||
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" | ||
version="3.0" | ||
bean-discovery-mode="annotated"> | ||
</beans> | ||
k |
27 changes: 27 additions & 0 deletions
27
tests/integration/security/security-annotation/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,27 @@ | ||
# | ||
# 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. | ||
# | ||
server.port: 0 | ||
security: | ||
providers: | ||
- abac: | ||
- http-basic-auth: | ||
realm: "helidon" | ||
users: | ||
- login: "success" | ||
password: "password" | ||
roles: ["admin"] | ||
- login: "fail" | ||
password: "password" |
29 changes: 29 additions & 0 deletions
29
tests/integration/security/security-annotation/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,29 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# Example Logging Configuration File | ||
# For more information see $JAVA_HOME/jre/lib/logging.properties | ||
|
||
# Send messages to the console | ||
handlers=io.helidon.logging.jul.HelidonConsoleHandler | ||
|
||
# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread | ||
java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n | ||
|
||
# Global logging level. Can be overridden by specific loggers | ||
.level=INFO | ||
AUDIT.level=FINEST | ||
|
73 changes: 73 additions & 0 deletions
73
...-annotation/src/test/java/io/helidon/tests/integration/security/pathparams/AdminTest.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,73 @@ | ||
/* | ||
* 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.tests.integration.security.pathparams; | ||
|
||
import java.util.Base64; | ||
|
||
import io.helidon.http.Status; | ||
import io.helidon.microprofile.testing.junit5.HelidonTest; | ||
|
||
import jakarta.ws.rs.client.WebTarget; | ||
import jakarta.ws.rs.core.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@HelidonTest | ||
class AdminTest { | ||
|
||
@Test | ||
void testProtectedAdminEndpoint(WebTarget target) { | ||
try (Response response = target.path("/admin") | ||
.request() | ||
.header("Authorization", basic("fail")) | ||
.get()) { | ||
assertThat(response.getStatus(), is(Status.FORBIDDEN_403.code())); | ||
} | ||
try (Response response = target.path("/admin") | ||
.request() | ||
.header("Authorization", basic("success")) | ||
.get()) { | ||
assertThat(response.getStatus(), is(Status.OK_200.code())); | ||
assertThat(response.readEntity(String.class), is("admin")); | ||
} | ||
} | ||
|
||
@Test | ||
void testUnauthorizedAdminEndpoint(WebTarget target) { | ||
try (Response response = target.path("/admin/unauthorized") | ||
.request() | ||
.header("Authorization", basic("fail")) | ||
.get()) { | ||
assertThat(response.getStatus(), is(Status.OK_200.code())); | ||
assertThat(response.readEntity(String.class), is("unauthorized admin")); | ||
} | ||
try (Response response = target.path("/admin/unauthorized") | ||
.request() | ||
.header("Authorization", basic("success")) | ||
.get()) { | ||
assertThat(response.getStatus(), is(Status.OK_200.code())); | ||
assertThat(response.readEntity(String.class), is("unauthorized admin")); | ||
} | ||
} | ||
|
||
private String basic(String user) { | ||
String uap = user + ":password"; | ||
return "basic " + Base64.getEncoder().encodeToString(uap.getBytes()); | ||
} | ||
} |