Skip to content

Commit e3e30a5

Browse files
authored
Merge pull request #1993 from carlesarnal/fix-quarkus-gh-integration
Fix quarkus github integration
2 parents 202e21c + 75292b3 commit e3e30a5

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

platforms/quarkus/api/src/main/java/io/apicurio/hub/api/security/QuarkusLinkedAccountsProvider.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import javax.enterprise.inject.Alternative;
1515
import javax.inject.Inject;
1616
import javax.net.ssl.SSLContext;
17-
import javax.servlet.http.HttpServletRequest;
1817

1918
import org.apache.commons.io.IOUtils;
2019
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -25,6 +24,7 @@
2524
import org.apache.http.impl.client.CloseableHttpClient;
2625
import org.apache.http.impl.client.HttpClients;
2726
import org.apache.http.ssl.SSLContexts;
27+
import org.eclipse.microprofile.jwt.JsonWebToken;
2828
import org.jboss.logmanager.Level;
2929
import org.keycloak.RSATokenVerifier;
3030
import org.keycloak.common.VerificationException;
@@ -51,7 +51,6 @@
5151
import io.apicurio.hub.api.beans.InitiatedLinkedAccount;
5252
import io.apicurio.hub.core.beans.LinkedAccountType;
5353
import io.apicurio.hub.core.config.HubConfiguration;
54-
import io.smallrye.jwt.auth.principal.JWTCallerPrincipal;
5554

5655
/**
5756
* An implementation of {@link ILinkedAccountsProvider} that used Keycloak to manage
@@ -75,11 +74,12 @@ public class QuarkusLinkedAccountsProvider
7574
@Inject
7675
HubConfiguration config;
7776

78-
@Inject
79-
HttpServletRequest request;
8077

8178
private CloseableHttpClient httpClient;
8279

80+
@Inject
81+
JsonWebToken accessToken;
82+
8383
@PostConstruct
8484
protected void postConstruct() {
8585
try {
@@ -107,10 +107,8 @@ public InitiatedLinkedAccount initiateLinkedAccount(LinkedAccountType accountTyp
107107
String realm = config.getKeycloakRealm();
108108
String provider = accountType.alias();
109109

110-
JWTCallerPrincipal principal = (JWTCallerPrincipal) request.getUserPrincipal();
111-
112110
try {
113-
AccessToken token = RSATokenVerifier.create(principal.getRawToken()).getToken();
111+
AccessToken token = RSATokenVerifier.create(accessToken.getRawToken()).getToken();
114112
String clientId = token.getIssuedFor();
115113
MessageDigest md = null;
116114
try {
@@ -145,12 +143,9 @@ public void deleteLinkedAccount(LinkedAccountType type) throws IOException {
145143
try {
146144
String authServerRootUrl = config.getKeycloakAuthUrl();
147145
String realm = config.getKeycloakRealm();
148-
149146
String provider = type.alias();
150147

151-
JWTCallerPrincipal principal = (JWTCallerPrincipal) request.getUserPrincipal();
152-
153-
AccessToken token = RSATokenVerifier.create(principal.getRawToken()).getToken();
148+
AccessToken token = RSATokenVerifier.create(accessToken.getRawToken()).getToken();
154149

155150
String url = KeycloakUriBuilder.fromUri(authServerRootUrl)
156151
.path("/realms/{realm}/account/federated-identity-update").queryParam("action", "REMOVE")
@@ -183,7 +178,7 @@ public String getLinkedAccountToken(LinkedAccountType type) throws IOException {
183178
try {
184179
String externalTokenUrl = KeycloakUriBuilder.fromUri(authServerRootUrl)
185180
.path("/realms/{realm}/broker/{provider}/token").build(realm, provider).toString();
186-
String token = this.security.getToken();
181+
String token = accessToken.getRawToken();
187182

188183
HttpGet get = new HttpGet(externalTokenUrl);
189184
get.addHeader("Accept", "application/json");
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apicurio.studio.fe.servlet.filters;
17+
package io.apicurio.ui;
1818

1919
import io.apicurio.studio.fe.servlet.config.RequestAttributeKeys;
2020
import io.apicurio.studio.shared.beans.StudioConfigAuth;
2121
import io.apicurio.studio.shared.beans.StudioConfigAuthType;
2222
import io.apicurio.studio.shared.beans.StudioRole;
2323
import io.apicurio.studio.shared.beans.User;
2424
import io.smallrye.jwt.auth.principal.JWTCallerPrincipal;
25+
import org.eclipse.microprofile.jwt.JsonWebToken;
2526

27+
import javax.inject.Inject;
2628
import javax.json.JsonObject;
2729
import javax.json.JsonString;
2830
import javax.servlet.*;
@@ -41,6 +43,9 @@
4143
*/
4244
public class QuarkusAuthenticationFilter implements Filter {
4345

46+
@Inject
47+
JsonWebToken accessToken;
48+
4449
/**
4550
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
4651
*/
@@ -64,21 +69,21 @@ public class QuarkusAuthenticationFilter implements Filter {
6469
StudioConfigAuth auth = new StudioConfigAuth();
6570
auth.setType(StudioConfigAuthType.token);
6671
auth.setLogoutUrl(((HttpServletRequest) request).getContextPath() + "/logout");
67-
auth.setToken(principal.getRawToken());
72+
auth.setToken(accessToken.getRawToken());
6873
//TODO carnalca unsafe cast from long to int
69-
auth.setTokenRefreshPeriod((int) expirationToRefreshPeriod(principal.getExpirationTime()));
74+
auth.setTokenRefreshPeriod((int) expirationToRefreshPeriod(accessToken.getExpirationTime()));
7075
httpSession.setAttribute(RequestAttributeKeys.AUTH_KEY, auth);
7176

7277
// Fabricate a User object from information in the access token and store it in the request.
7378
User user = new User();
74-
user.setEmail(principal.getClaim("email"));
75-
user.setLogin(principal.getClaim("preferred_username"));
76-
user.setName(principal.getClaim("name"));
77-
if (!principal.containsClaim("realm_access") || principal.<JsonObject>getClaim("realm_access").isNull("roles")) {
79+
user.setEmail(accessToken.getClaim("email"));
80+
user.setLogin(accessToken.getClaim("preferred_username"));
81+
user.setName(accessToken.getClaim("name"));
82+
if (!accessToken.containsClaim("realm_access") || accessToken.<JsonObject>getClaim("realm_access").isNull("roles")) {
7883
user.setRoles(Collections.emptyList());
7984
} else {
8085
user.setRoles(
81-
principal.<JsonObject>getClaim("realm_access")
86+
accessToken.<JsonObject>getClaim("realm_access")
8287
.getJsonArray("roles").stream()
8388
.map(JsonString.class::cast)
8489
.map(JsonString::getString)

platforms/quarkus/ui/src/main/resources/META-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<filter>
1616
<filter-name>QuarkusAuthenticationFilter</filter-name>
17-
<filter-class>io.apicurio.studio.fe.servlet.filters.QuarkusAuthenticationFilter</filter-class>
17+
<filter-class>io.apicurio.ui.QuarkusAuthenticationFilter</filter-class>
1818
</filter>
1919
<filter-mapping>
2020
<filter-name>QuarkusAuthenticationFilter</filter-name>

0 commit comments

Comments
 (0)