Search in sources :

Example 1 with BuiltinAuthenticationProvider

use of edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider in project dataverse by IQSS.

the class AuthUtilTest method testIsNonLocalLoginEnabled.

/**
 * Test of isNonLocalLoginEnabled method, of class AuthUtil.
 */
@Test
public void testIsNonLocalLoginEnabled() {
    System.out.println("isNonLocalLoginEnabled");
    AuthUtil authUtil = new AuthUtil();
    assertEquals(false, AuthUtil.isNonLocalLoginEnabled(null));
    Collection<AuthenticationProvider> shibOnly = new HashSet<>();
    shibOnly.add(new ShibAuthenticationProvider());
    assertEquals(true, AuthUtil.isNonLocalLoginEnabled(shibOnly));
    Collection<AuthenticationProvider> manyNonLocal = new HashSet<>();
    manyNonLocal.add(new ShibAuthenticationProvider());
    manyNonLocal.add(new GitHubOAuth2AP(null, null));
    manyNonLocal.add(new GoogleOAuth2AP(null, null));
    manyNonLocal.add(new OrcidOAuth2AP(null, null, null));
    assertEquals(true, AuthUtil.isNonLocalLoginEnabled(manyNonLocal));
    Collection<AuthenticationProvider> onlyBuiltin = new HashSet<>();
    onlyBuiltin.add(new BuiltinAuthenticationProvider(null, null));
    // only builtin provider
    assertEquals(false, AuthUtil.isNonLocalLoginEnabled(onlyBuiltin));
}
Also used : ShibAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider) GoogleOAuth2AP(edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.GoogleOAuth2AP) OrcidOAuth2AP(edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.OrcidOAuth2AP) BuiltinAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider) ShibAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider) BuiltinAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider) GitHubOAuth2AP(edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.GitHubOAuth2AP) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with BuiltinAuthenticationProvider

use of edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider in project dataverse by IQSS.

the class OAuth2FirstLoginPage method convertExistingAccount.

public String convertExistingAccount() {
    BuiltinAuthenticationProvider biap = new BuiltinAuthenticationProvider(builtinUserSvc, passwordValidatorService);
    AuthenticationRequest auReq = new AuthenticationRequest();
    final List<CredentialsAuthenticationProvider.Credential> creds = biap.getRequiredCredentials();
    auReq.putCredential(creds.get(0).getTitle(), getUsername());
    auReq.putCredential(creds.get(1).getTitle(), getPassword());
    try {
        AuthenticatedUser existingUser = authenticationSvc.getCreateAuthenticatedUser(BuiltinAuthenticationProvider.PROVIDER_ID, auReq);
        authenticationSvc.updateProvider(existingUser, newUser.getServiceId(), newUser.getIdInService());
        builtinUserSvc.removeUser(existingUser.getUserIdentifier());
        session.setUser(existingUser);
        AuthenticationProvider newUserAuthProvider = authenticationSvc.getAuthenticationProvider(newUser.getServiceId());
        JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("oauth2.convertAccount.success", Arrays.asList(newUserAuthProvider.getInfo().getTitle())));
        return "/dataverse.xhtml?faces-redirect=true";
    } catch (AuthenticationFailedException ex) {
        setAuthenticationFailed(true);
        return null;
    }
}
Also used : AuthenticationFailedException(edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException) BuiltinAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider) CredentialsAuthenticationProvider(edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider) AuthenticationProvider(edu.harvard.iq.dataverse.authorization.AuthenticationProvider) BuiltinAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider) AuthenticationRequest(edu.harvard.iq.dataverse.authorization.AuthenticationRequest) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Aggregations

BuiltinAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider)2 AuthenticationProvider (edu.harvard.iq.dataverse.authorization.AuthenticationProvider)1 AuthenticationRequest (edu.harvard.iq.dataverse.authorization.AuthenticationRequest)1 CredentialsAuthenticationProvider (edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider)1 AuthenticationFailedException (edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException)1 GitHubOAuth2AP (edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.GitHubOAuth2AP)1 GoogleOAuth2AP (edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.GoogleOAuth2AP)1 OrcidOAuth2AP (edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.OrcidOAuth2AP)1 ShibAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1