Skip to content

Commit

Permalink
#3614 bundles for friendly AuthenticationProvider names
Browse files Browse the repository at this point in the history
  • Loading branch information
raprasad committed Jun 29, 2017
1 parent 2bcef31 commit 6d73408
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1657,4 +1657,13 @@ citationFrame.banner.message=If the site below does not load, the archived data
citationFrame.banner.message.here=here
citationFrame.banner.closeIcon=Close this message, go to dataset
citationFrame.banner.countdownMessage= This message will close in
citationFrame.banner.countdownMessage.seconds=seconds
citationFrame.banner.countdownMessage.seconds=seconds

# Friendly AuthenticationProvider names
authenticationProvider.name.builtin=Dataverse
authenticationProvider.name.null=(provider is unknown)
authenticationProvider.name.github=GitHub
authenticationProvider.name.google=Google
authenticationProvider.name.orcid=ORCiD
authenticationProvider.name.orcid-sandbox=ORCiD Sandbox
authenticationProvider.name.shib=Shibboleth
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse.authorization;

import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.util.BundleUtil;

/**
* Objects that can authenticate users. The authentication process yields a unique
Expand All @@ -10,14 +11,21 @@
* can be queried using the {@code isXXXAllowed()} methods. If an implementation returns {@code true}
* from one of these methods, it has to implement the matching methods.
*
* Note: If you are adding an implementation of this interface, please add a "friendly" name to the bundles.
* Example: ShibAuthenticationProvider implements this interface.
* (a) ShibAuthenticationProvider.getID() returns "ship"
* (b) Construct bundle name using String id "shib" from (a):
* "authenticationProvider.name." + "ship" ->
* (c) Bundle.properties entry: "authenticationProvider.name.shib=Shibboleth"
*
* {@code AuthenticationPrvider}s are normally registered at startup in {@link AuthenticationServiceBean#startup()}.
*
* @author michael
*/
public interface AuthenticationProvider {

String getId();

AuthenticationProviderDisplayInfo getInfo();

default boolean isPasswordUpdateAllowed() { return false; };
Expand All @@ -35,12 +43,16 @@ public interface AuthenticationProvider {
default String getPersistentIdUrlPrefix() { return null; };
default String getLogo() { return null; };



/**
* Some providers (e.g organizational ones) provide verified email addresses.
* @return {@code true} if we can treat email addresses coming from this provider as verified, {@code false} otherwise.
*/
default boolean isEmailVerified() { return false; };



/**
* Updates the password of the user whose id is passed.
* @param userIdInProvider User id in the provider. NOT the {@link AuthenticatedUser#id}, which is internal to the installation.
Expand Down Expand Up @@ -80,4 +92,37 @@ default void updateUserInfo( String userIdInProvider, AuthenticatedUserDisplayIn
default void deleteUser( String userIdInProvider ) {
throw new UnsupportedOperationException(this.toString() + " does not implement account deletions");
}


/**
* Given the AuthenticationProvider id, return the friendly name
* of the AuthenticationProvider as defined in the bundle
*
* If no name is defined, return the id itself
*
* @param authProviderId
* @return
*/
public static String getFriendlyName(String authProviderId){
if (authProviderId == null){
return BundleUtil.getStringFromBundle("authenticationProvider.name.null");
}

String friendlyName = BundleUtil.getStringFromBundle("authenticationProvider.name." + authProviderId);
if (friendlyName == null){
return authProviderId;
}
return friendlyName;
}

/**
* Given the AuthenticationProvider id,
* return the friendly name using the static method
*/
default String getFriendlyName(){
// call static method
return BundleUtil.getStringFromBundle("authentication.human_readable." + this.getId());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.harvard.iq.dataverse.PermissionsWrapper;
import edu.harvard.iq.dataverse.UserServiceBean;
import edu.harvard.iq.dataverse.api.Admin;
import edu.harvard.iq.dataverse.authorization.AuthenticationProvider;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.mydata.Pager;
Expand Down Expand Up @@ -198,5 +199,8 @@ public void cancelSuperuserStatusChange(){
selectedUserPersistent = null;
}


public String getAuthProviderFriendlyName(String authProviderId){

return AuthenticationProvider.getFriendlyName(authProviderId);
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/dashboard-users.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<h:outputText value="#{user.roles}" />
</p:column>
<p:column width="13%" headerText="#{bundle['dashboard.list_users.tbl_header.authProviderFactoryAlias']}">
<h:outputText value="#{user.authProviderFactoryAlias}" />
<h:outputText value="#{DashboardUsersPage.getAuthProviderFriendlyName(user.authProviderId)}" />
</p:column>
<p:column width="10%" class="text-center" headerText="#{bundle['dashboard.list_users.tbl_header.isSuperuser']}">
<!-- A simple implementation of the superuser status toggle - via a boolean checkbox with an immediate ajax update. -->
Expand Down

0 comments on commit 6d73408

Please sign in to comment.