Skip to content

Commit b23ed4e

Browse files
committed
Refactored to use 'enabled' flag to hide provider from JSF
1 parent 5c71eeb commit b23ed4e

File tree

9 files changed

+41
-31
lines changed

9 files changed

+41
-31
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This release will allow for SPA created OIDC Providers to be hidden from JSF login screens. By setting the ``enabled`` attribute either in the config file ``DATAVERSE_AUTH_OIDC_ENABLED: "0"`` or in the Json of the api call:
2+
POST api/admin/authenticationProviders
3+
4+
{
5+
"id": "oidc1",
6+
"factoryAlias": "oidc",
7+
"title": "Open ID Connect SPA",
8+
"subtitle": "SPA OIDC Provider",
9+
"factoryData": "type: oidc | issuer: http://keycloak.mydomain.com:8090/realms/test | clientId: test | clientSecret: 94XHrfNRwXsjqTqApRrwWmhDLDHpIYV8",
10+
```"enabled": false```
11+
}
12+
13+
Calling GET api/admin/authenticationProviders will return all providers allowing SPA to display even the ones with enabled = false

src/main/java/edu/harvard/iq/dataverse/LoginPage.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,15 @@ public List<AuthenticationProviderDisplayInfo> listCredentialsAuthenticationProv
135135
* Retrieve information about all enabled identity providers in a sorted order to be displayed to the user.
136136
* @return list of display information for each provider
137137
*/
138-
public List<AuthenticationProviderDisplayInfo> listAuthenticationProvidersJSF() {
139-
return listAuthenticationProviders(false);
140-
}
141138
public List<AuthenticationProviderDisplayInfo> listAuthenticationProviders() {
142-
return listAuthenticationProviders(true);
143-
}
144-
public List<AuthenticationProviderDisplayInfo> listAuthenticationProviders(boolean ignoreBlocked) {
145139
List<AuthenticationProviderDisplayInfo> infos = new LinkedList<>();
146140
List<AuthenticationProvider> idps = new ArrayList<>(authSvc.getAuthenticationProviders());
147141

148142
// sort by order first. in case of same order values, be deterministic in UI and sort by id, too.
149143
Collections.sort(idps, Comparator.comparing(AuthenticationProvider::getOrder).thenComparing(AuthenticationProvider::getId));
150144

151145
for (AuthenticationProvider idp : idps) {
152-
if (idp != null && (ignoreBlocked || !idp.isJsfBlocked())) {
153-
infos.add(idp.getInfo());
154-
}
146+
infos.add(idp.getInfo());
155147
}
156148
return infos;
157149
}

src/main/java/edu/harvard/iq/dataverse/authorization/AuthenticationProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public interface AuthenticationProvider {
3333
default boolean isUserInfoUpdateAllowed() { return false; };
3434
default boolean isUserDeletionAllowed() { return false; };
3535
default boolean isOAuthProvider() { return false; };
36-
default boolean isJsfBlocked() { return false; };
37-
38-
36+
default boolean isEnabled() { return true; };
3937

4038
/**
4139
* Some providers (e.g organizational ones) provide verified email addresses.

src/main/java/edu/harvard/iq/dataverse/authorization/providers/oauth2/AbstractOAuth2AuthenticationProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public String toString() {
9393
protected String clientSecret;
9494
protected String baseUserEndpoint;
9595
protected String redirectUrl;
96+
protected boolean enabled = true;
9697

9798
/**
9899
* List of scopes to be requested for authorization at identity provider.
@@ -272,6 +273,9 @@ public String getSubTitle() {
272273

273274
public String getSpacedScope() { return String.join(" ", getScope()); }
274275

276+
public void setEnabled(boolean enabled) { this.enabled = enabled; }
277+
public boolean isEnabled() { return enabled; }
278+
275279
@Override
276280
public int hashCode() {
277281
int hash = 7;

src/main/java/edu/harvard/iq/dataverse/authorization/providers/oauth2/oidc/OIDCAuthProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public class OIDCAuthProvider extends AbstractOAuth2AuthenticationProvider {
6767
final OIDCProviderMetadata idpMetadata;
6868
final boolean pkceEnabled;
6969
final CodeChallengeMethod pkceMethod;
70-
final boolean jsfBlocked;
71-
70+
7271
/**
7372
* Using PKCE, we create and send a special {@link CodeVerifier}. This contains a secret
7473
* we need again when verifying the response by the provider, thus the cache.
@@ -81,7 +80,7 @@ public class OIDCAuthProvider extends AbstractOAuth2AuthenticationProvider {
8180
.build();
8281

8382
public OIDCAuthProvider(String aClientId, String aClientSecret, String issuerEndpointURL,
84-
boolean pkceEnabled, String pkceMethod, boolean jsfBlocked) throws AuthorizationSetupException {
83+
boolean pkceEnabled, String pkceMethod) throws AuthorizationSetupException {
8584
this.clientSecret = aClientSecret; // needed for state creation
8685
this.clientAuth = new ClientSecretBasic(new ClientID(aClientId), new Secret(aClientSecret));
8786
this.issuer = new Issuer(issuerEndpointURL);
@@ -90,10 +89,7 @@ public OIDCAuthProvider(String aClientId, String aClientSecret, String issuerEnd
9089

9190
this.pkceEnabled = pkceEnabled;
9291
this.pkceMethod = CodeChallengeMethod.parse(pkceMethod);
93-
this.jsfBlocked = jsfBlocked;
9492
}
95-
96-
public boolean isJsfBlocked() { return jsfBlocked; }
9793

9894
/**
9995
* Setup metadata from OIDC provider during creation of the provider representation

src/main/java/edu/harvard/iq/dataverse/authorization/providers/oauth2/oidc/OIDCAuthenticationProviderFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public AuthenticationProvider buildProvider( AuthenticationProviderRow aRow ) th
4343
factoryData.get("clientSecret"),
4444
factoryData.get("issuer"),
4545
Boolean.parseBoolean(factoryData.getOrDefault("pkceEnabled", "false")),
46-
factoryData.getOrDefault("pkceMethod", "S256"),
47-
Boolean.parseBoolean(factoryData.getOrDefault("jsfBlocked", "false"))
46+
factoryData.getOrDefault("pkceMethod", "S256")
4847
);
4948

5049
oidc.setId(aRow.getId());
5150
oidc.setTitle(aRow.getTitle());
5251
oidc.setSubTitle(aRow.getSubtitle());
52+
oidc.setEnabled(aRow.isEnabled());
5353

5454
return oidc;
5555
}
@@ -65,13 +65,13 @@ public static AuthenticationProvider buildFromSettings() throws AuthorizationSet
6565
JvmSettings.OIDC_CLIENT_SECRET.lookup(),
6666
JvmSettings.OIDC_AUTH_SERVER_URL.lookup(),
6767
JvmSettings.OIDC_PKCE_ENABLED.lookupOptional(Boolean.class).orElse(false),
68-
JvmSettings.OIDC_PKCE_METHOD.lookupOptional().orElse("S256"),
69-
JvmSettings.OIDC_JSFBLOCKED.lookupOptional(Boolean.class).orElse(false)
68+
JvmSettings.OIDC_PKCE_METHOD.lookupOptional().orElse("S256")
7069
);
7170

7271
oidc.setId("oidc-mpconfig");
7372
oidc.setTitle(JvmSettings.OIDC_TITLE.lookupOptional().orElse("OpenID Connect"));
7473
oidc.setSubTitle(JvmSettings.OIDC_SUBTITLE.lookupOptional().orElse("OpenID Connect"));
74+
oidc.setEnabled(JvmSettings.OIDC_ENABLED.lookupOptional(Boolean.class).orElse(true));
7575

7676
return oidc;
7777
}

src/main/java/edu/harvard/iq/dataverse/settings/JvmSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ public enum JvmSettings {
252252
OIDC_AUTH_SERVER_URL(SCOPE_OIDC, "auth-server-url"),
253253
OIDC_CLIENT_ID(SCOPE_OIDC, "client-id"),
254254
OIDC_CLIENT_SECRET(SCOPE_OIDC, "client-secret"),
255-
OIDC_JSFBLOCKED(SCOPE_OIDC, "jsfBlocked"),
256255
SCOPE_OIDC_PKCE(SCOPE_OIDC, "pkce"),
257256
OIDC_PKCE_ENABLED(SCOPE_OIDC_PKCE, "enabled"),
258257
OIDC_PKCE_METHOD(SCOPE_OIDC_PKCE, "method"),

src/main/webapp/loginpage.xhtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ui:param name="showMessagePanel" value="#{true}"/>
2424
<ui:param name="loginRedirectPage" value="dataverse.xhtml"/>
2525
<ui:define name="body">
26-
<ui:fragment rendered="#{LoginPage.listAuthenticationProvidersJSF().size() lt 1}">
26+
<ui:fragment rendered="#{LoginPage.listAuthenticationProviders().size() lt 1}">
2727
<div class="row">
2828
<div class="col-sm-12">
2929
<div class="alert alert-danger">
@@ -214,10 +214,10 @@
214214
</div>
215215
</div>
216216

217-
<div id="otherProviders" jsf:rendered="#{LoginPage.listAuthenticationProvidersJSF().size() > 1}">
217+
<div id="otherProviders" jsf:rendered="#{LoginPage.listAuthenticationProviders().size() > 1}">
218218
<h3>#{bundle['auth.providers.title']}</h3>
219219
<h:form>
220-
<ui:repeat value="#{LoginPage.listAuthenticationProvidersJSF()}" var="provider">
220+
<ui:repeat value="#{LoginPage.listAuthenticationProviders()}" var="provider">
221221
<p:commandLink rendered="#{provider.id != LoginPage.authProvider.id}" styleClass="btn btn-default" actionListener="#{LoginPage.setAuthProviderById(provider.id)}" update="login-container">
222222
<h:outputText value="#{provider.title}" />
223223
</p:commandLink>

src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,14 +978,14 @@ public void testAddAuthProviders() {
978978
Response getAuthProviders = UtilIT.getAuthProviders(superuserApiToken);
979979
getAuthProviders.prettyPrint();
980980

981-
String factoryData = String.format("type: oidc | issuer: http://keycloak.mydomain.com:8090/realms/test | clientId: %s | clientSecret: %s | jsfBlocked: true", clientId, clientSecret);
981+
String factoryData = String.format("type: oidc | issuer: http://keycloak.mydomain.com:8090/realms/test | clientId: %s | clientSecret: %s", clientId, clientSecret);
982982
JsonObject jsonObject = Json.createObjectBuilder()
983983
.add("id", "oidc1")
984984
.add("factoryAlias", "oidc")
985985
.add("title", "Open ID Connect SPA")
986986
.add("subtitle", "SPA OIDC Provider")
987987
.add("factoryData", factoryData)
988-
.add("enabled", true)
988+
.add("enabled", false)
989989
.build();
990990
Response addAuthProviders = UtilIT.addAuthProviders(superuserApiToken, jsonObject);
991991
addAuthProviders.prettyPrint();
@@ -995,9 +995,17 @@ public void testAddAuthProviders() {
995995
getAuthProviders = UtilIT.getAuthProviders(superuserApiToken);
996996
getAuthProviders.prettyPrint();
997997
getAuthProviders.then().assertThat()
998-
.statusCode(OK.getStatusCode())
999-
.body("data[1].id", equalTo("oidc1"))
1000-
.body("data[1].factoryData", containsString("jsfBlocked: true"));
998+
.statusCode(OK.getStatusCode());
1001999

1000+
boolean found = false;
1001+
List<Map<String, Object>> providers = getAuthProviders.body().jsonPath().getList("data");
1002+
for (Map<String, Object> provider : providers) {
1003+
if ("oidc1".equalsIgnoreCase((String) provider.get("id"))) {
1004+
found = true;
1005+
assertTrue(provider.get("title") != null && provider.get("title").equals("Open ID Connect SPA"));
1006+
assertTrue(provider.get("enabled") != null && !(Boolean) provider.get("enabled"));
1007+
}
1008+
}
1009+
assertTrue(found);
10021010
}
10031011
}

0 commit comments

Comments
 (0)