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));
}
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;
}
}
Aggregations