2121import static java .util .Collections .singletonList ;
2222import static org .keycloak .representations .IDToken .LOCALE ;
2323
24- import java .text .ParseException ;
2524import java .util .Arrays ;
2625import java .util .Collections ;
2726import java .util .HashMap ;
3938import javax .ws .rs .WebApplicationException ;
4039import javax .ws .rs .core .Response ;
4140
41+ import com .jayway .jsonpath .JsonPath ;
4242import org .apache .commons .collections .CollectionUtils ;
4343import org .apache .commons .lang3 .StringUtils ;
4444import org .eclipse .microprofile .config .ConfigProvider ;
5151import org .slf4j .Logger ;
5252import org .slf4j .LoggerFactory ;
5353
54- import com .nimbusds .jose .util .JSONObjectUtils ;
55-
5654import de .symeda .sormas .api .AuthProvider ;
5755import de .symeda .sormas .api .Language ;
5856import de .symeda .sormas .api .user .UserRole ;
6159import de .symeda .sormas .backend .user .event .PasswordResetEvent ;
6260import de .symeda .sormas .backend .user .event .UserCreateEvent ;
6361import de .symeda .sormas .backend .user .event .UserUpdateEvent ;
64- import net .minidev .json .JSONObject ;
6562
6663/**
6764 * @author Alex Vidrean
@@ -78,8 +75,7 @@ public class KeycloakService {
7875
7976 private static final String OIDC_REALM = "realm" ;
8077 private static final String OIDC_SERVER_URL = "auth-server-url" ;
81- private static final String OIDC_CREDENTIALS = "credentials" ;
82- private static final String OIDC_SECRET = "secret" ;
78+ private static final String OIDC_SECRET = "credentials.secret" ;
8379
8480 private static final String REALM_NAME = "SORMAS" ;
8581
@@ -106,20 +102,16 @@ public void init() {
106102 return ;
107103 }
108104
109- try {
110- JSONObject json = JSONObjectUtils .parse (oidcJson .get ());
105+ String keycloakJsonConfig = oidcJson .get ();
111106
112- keycloak = KeycloakBuilder .builder ()
113- .realm (json . getAsString ( OIDC_REALM ))
114- .serverUrl (json . getAsString ( OIDC_SERVER_URL ))
115- .clientId ("sormas-backend" )
116- .clientSecret (JSONObjectUtils . getJSONObject ( json , OIDC_CREDENTIALS ). getAsString ( OIDC_SECRET ))
117- .grantType (OAuth2Constants .CLIENT_CREDENTIALS )
118- .build ();
107+ keycloak = KeycloakBuilder .builder ()
108+ .realm (JsonPath . read ( keycloakJsonConfig , OIDC_REALM ))
109+ .serverUrl (JsonPath . read ( keycloakJsonConfig , OIDC_SERVER_URL ))
110+ .clientId ("sormas-backend" )
111+ .clientSecret (JsonPath . read ( keycloakJsonConfig , OIDC_SECRET ))
112+ .grantType (OAuth2Constants .CLIENT_CREDENTIALS )
113+ .build ();
119114
120- } catch (ParseException e ) {
121- throw new IllegalArgumentException ("Invalid JSON for backend keycloak oidc" );
122- }
123115 }
124116
125117 public void handleUserCreateEvent (@ Observes UserCreateEvent userCreateEvent ) {
0 commit comments