14
14
import javax .enterprise .inject .Alternative ;
15
15
import javax .inject .Inject ;
16
16
import javax .net .ssl .SSLContext ;
17
- import javax .servlet .http .HttpServletRequest ;
18
17
19
18
import org .apache .commons .io .IOUtils ;
20
19
import org .apache .http .client .methods .CloseableHttpResponse ;
25
24
import org .apache .http .impl .client .CloseableHttpClient ;
26
25
import org .apache .http .impl .client .HttpClients ;
27
26
import org .apache .http .ssl .SSLContexts ;
27
+ import org .eclipse .microprofile .jwt .JsonWebToken ;
28
28
import org .jboss .logmanager .Level ;
29
29
import org .keycloak .RSATokenVerifier ;
30
30
import org .keycloak .common .VerificationException ;
51
51
import io .apicurio .hub .api .beans .InitiatedLinkedAccount ;
52
52
import io .apicurio .hub .core .beans .LinkedAccountType ;
53
53
import io .apicurio .hub .core .config .HubConfiguration ;
54
- import io .smallrye .jwt .auth .principal .JWTCallerPrincipal ;
55
54
56
55
/**
57
56
* An implementation of {@link ILinkedAccountsProvider} that used Keycloak to manage
@@ -75,11 +74,12 @@ public class QuarkusLinkedAccountsProvider
75
74
@ Inject
76
75
HubConfiguration config ;
77
76
78
- @ Inject
79
- HttpServletRequest request ;
80
77
81
78
private CloseableHttpClient httpClient ;
82
79
80
+ @ Inject
81
+ JsonWebToken accessToken ;
82
+
83
83
@ PostConstruct
84
84
protected void postConstruct () {
85
85
try {
@@ -107,10 +107,8 @@ public InitiatedLinkedAccount initiateLinkedAccount(LinkedAccountType accountTyp
107
107
String realm = config .getKeycloakRealm ();
108
108
String provider = accountType .alias ();
109
109
110
- JWTCallerPrincipal principal = (JWTCallerPrincipal ) request .getUserPrincipal ();
111
-
112
110
try {
113
- AccessToken token = RSATokenVerifier .create (principal .getRawToken ()).getToken ();
111
+ AccessToken token = RSATokenVerifier .create (accessToken .getRawToken ()).getToken ();
114
112
String clientId = token .getIssuedFor ();
115
113
MessageDigest md = null ;
116
114
try {
@@ -145,12 +143,9 @@ public void deleteLinkedAccount(LinkedAccountType type) throws IOException {
145
143
try {
146
144
String authServerRootUrl = config .getKeycloakAuthUrl ();
147
145
String realm = config .getKeycloakRealm ();
148
-
149
146
String provider = type .alias ();
150
147
151
- JWTCallerPrincipal principal = (JWTCallerPrincipal ) request .getUserPrincipal ();
152
-
153
- AccessToken token = RSATokenVerifier .create (principal .getRawToken ()).getToken ();
148
+ AccessToken token = RSATokenVerifier .create (accessToken .getRawToken ()).getToken ();
154
149
155
150
String url = KeycloakUriBuilder .fromUri (authServerRootUrl )
156
151
.path ("/realms/{realm}/account/federated-identity-update" ).queryParam ("action" , "REMOVE" )
@@ -183,7 +178,7 @@ public String getLinkedAccountToken(LinkedAccountType type) throws IOException {
183
178
try {
184
179
String externalTokenUrl = KeycloakUriBuilder .fromUri (authServerRootUrl )
185
180
.path ("/realms/{realm}/broker/{provider}/token" ).build (realm , provider ).toString ();
186
- String token = this . security . getToken ();
181
+ String token = accessToken . getRawToken ();
187
182
188
183
HttpGet get = new HttpGet (externalTokenUrl );
189
184
get .addHeader ("Accept" , "application/json" );
0 commit comments