-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFLY-17649] Adds integration tests and github action workflow for ej…
…b-security-jwt quickstart
- Loading branch information
Showing
7 changed files
with
211 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: WildFly EJB Security JWT Quickstart CI | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
paths: | ||
- 'ejb-security-jwt/**' | ||
- '.github/workflows/quickstart_ci.yml' | ||
|
||
jobs: | ||
call-quickstart_ci: | ||
uses: ./.github/workflows/quickstart_ci.yml | ||
with: | ||
QUICKSTART_PATH: ejb-security-jwt | ||
TEST_PROVISIONED_SERVER: true | ||
TEST_OPENSHIFT: false | ||
MATRIX_OS: '"ubuntu-latest"' | ||
DEPLOYMENT_DIR: app-one/ear |
10 changes: 10 additions & 0 deletions
10
.github/workflows/quickstart_ejb-security-jwt_ci_before.sh
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,10 @@ | ||
#!/bin/sh | ||
set -x | ||
|
||
# Start keycloak with required configuration | ||
docker run -d --rm --name "keycloak" \ | ||
-p 8180:8080 \ | ||
-e KEYCLOAK_ADMIN=admin \ | ||
-e KEYCLOAK_ADMIN_PASSWORD=admin \ | ||
-v ${GITHUB_WORKSPACE}/quickstarts/ejb-security-jwt/keycloak/realm:/opt/keycloak/data/import \ | ||
quay.io/keycloak/keycloak:21.0.0 start-dev --import-realm |
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
62 changes: 62 additions & 0 deletions
62
...-jwt/client/src/test/java/org/jboss/as/quickstarts/ejb/security/jwt/EJBSecurityJWTIT.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,62 @@ | ||
/* | ||
* Copyright 2023 JBoss by Red Hat. | ||
* | ||
* 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 org.jboss.as.quickstarts.ejb.security.jwt; | ||
|
||
import org.jboss.as.quickstarts.ejb.security.jwt.appone.JWTSecurityEJBRemoteA; | ||
import org.jboss.as.quickstarts.ejb.security.jwt.client.RemoteEJBClient; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.wildfly.security.auth.client.AuthenticationContext; | ||
|
||
import javax.naming.NamingException; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Tests that | ||
* | ||
* @author <a href="mailto:[email protected]">Lin Gao</a> | ||
*/ | ||
public class EJBSecurityJWTIT { | ||
private static final String DEFAULT_SERVER_HOST = "http://localhost:8080"; | ||
|
||
private String getProviderURl() { | ||
final String serverHost = System.getProperty("server.host"); | ||
return "remote+" + (serverHost != null ? serverHost : DEFAULT_SERVER_HOST); | ||
} | ||
|
||
@Test | ||
public void testRegular() throws NamingException { | ||
AuthenticationContext.getContextManager().setThreadDefault(null); | ||
JWTSecurityEJBRemoteA remoteA = RemoteEJBClient.lookupEJBRemoteA(true, getProviderURl()); | ||
Assert.assertEquals("quickstartuser", remoteA.principal().toLowerCase()); | ||
Assert.assertTrue(remoteA.inRole("user")); | ||
Assert.assertFalse(remoteA.inRole("admin")); | ||
Assert.assertTrue(remoteA.inRoleFromB("user", true)); | ||
Assert.assertFalse(remoteA.inRoleFromB("admin", true)); | ||
} | ||
|
||
@Test | ||
public void testAdmin() throws IOException, NamingException { | ||
RemoteEJBClient.switchToAdmin(); | ||
JWTSecurityEJBRemoteA remoteA = RemoteEJBClient.lookupEJBRemoteA(true, getProviderURl()); | ||
Assert.assertEquals("admin", remoteA.principal().toLowerCase()); | ||
Assert.assertTrue(remoteA.inRole("user")); | ||
Assert.assertTrue(remoteA.inRole("admin")); | ||
Assert.assertTrue(remoteA.inRoleFromB("user", true)); | ||
Assert.assertTrue(remoteA.inRoleFromB("admin", true)); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
ejb-security-jwt/client/src/test/resources/META-INF/wildfly-config.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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ JBoss, Home of Professional Open Source. | ||
~ Copyright 2023 Red Hat, Inc., and individual contributors | ||
~ as indicated by the @author tags. | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<configuration> | ||
<authentication-client xmlns="urn:elytron:client:1.7"> | ||
<authentication-rules> | ||
<rule use-configuration="default" /> | ||
</authentication-rules> | ||
<authentication-configurations> | ||
<configuration name="default"> | ||
<sasl-mechanism-selector selector="OAUTHBEARER" /> | ||
<credentials> | ||
<oauth2-bearer-token token-endpoint-uri="http://localhost:8180/realms/jwt-realm/protocol/openid-connect/token"> | ||
<resource-owner-credentials name="quickstartUser"> | ||
<credential-store-reference clear-text="quickstartPwd1!" /> | ||
</resource-owner-credentials> | ||
<client-credentials client-id="app" client-secret="secret"/> | ||
</oauth2-bearer-token> | ||
</credentials> | ||
</configuration> | ||
</authentication-configurations> | ||
</authentication-client> | ||
</configuration> |