use of edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException in project dataverse by IQSS.
the class AuthenticationServiceBean method startup.
@PostConstruct
public void startup() {
// First, set up the factories
try {
registerProviderFactory(new BuiltinAuthenticationProviderFactory(builtinUserServiceBean, passwordValidatorService));
registerProviderFactory(new ShibAuthenticationProviderFactory());
registerProviderFactory(new OAuth2AuthenticationProviderFactory());
} catch (AuthorizationSetupException ex) {
logger.log(Level.SEVERE, "Exception setting up the authentication provider factories: " + ex.getMessage(), ex);
}
// Now, load the providers.
em.createNamedQuery("AuthenticationProviderRow.findAllEnabled", AuthenticationProviderRow.class).getResultList().forEach((row) -> {
try {
registerProvider(loadProvider(row));
} catch (AuthenticationProviderFactoryNotFoundException e) {
logger.log(Level.SEVERE, "Cannot find authentication provider factory with alias '" + e.getFactoryAlias() + "'", e);
} catch (AuthorizationSetupException ex) {
logger.log(Level.SEVERE, "Exception setting up the authentication provider '" + row.getId() + "': " + ex.getMessage(), ex);
}
});
}
use of edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException in project dataverse by IQSS.
the class Admin method addProvider.
@Path("authenticationProviders")
@POST
public Response addProvider(AuthenticationProviderRow row) {
try {
AuthenticationProviderRow managed = em.find(AuthenticationProviderRow.class, row.getId());
if (managed != null) {
managed = em.merge(row);
} else {
em.persist(row);
managed = row;
}
if (managed.isEnabled()) {
AuthenticationProvider provider = authSvc.loadProvider(managed);
authSvc.deregisterProvider(provider.getId());
authSvc.registerProvider(provider);
}
return created("/api/admin/authenticationProviders/" + managed.getId(), json(managed));
} catch (AuthorizationSetupException e) {
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException in project dataverse by IQSS.
the class Admin method enableAuthenticationProvider.
@PUT
@Path("authenticationProviders/{id}/enabled")
@Produces("application/json")
public Response enableAuthenticationProvider(@PathParam("id") String id, String body) {
body = body.trim();
if (!Util.isBoolean(body)) {
return error(Response.Status.BAD_REQUEST, "Illegal value '" + body + "'. Use 'true' or 'false'");
}
boolean enable = Util.isTrue(body);
AuthenticationProviderRow row = em.find(AuthenticationProviderRow.class, id);
if (row == null) {
return notFound("Can't find authentication provider with id '" + id + "'");
}
row.setEnabled(enable);
em.merge(row);
if (enable) {
// enable a provider
if (authSvc.getAuthenticationProvider(id) != null) {
return ok(String.format("Authentication provider '%s' already enabled", id));
}
try {
authSvc.registerProvider(authSvc.loadProvider(row));
return ok(String.format("Authentication Provider %s enabled", row.getId()));
} catch (AuthenticationProviderFactoryNotFoundException ex) {
return notFound(String.format("Can't instantiate provider, as there's no factory with alias %s", row.getFactoryAlias()));
} catch (AuthorizationSetupException ex) {
logger.log(Level.WARNING, "Error instantiating authentication provider: " + ex.getMessage(), ex);
return error(Status.INTERNAL_SERVER_ERROR, String.format("Can't instantiate provider: %s", ex.getMessage()));
}
} else {
// disable a provider
authSvc.deregisterProvider(id);
return ok("Authentication Provider '" + id + "' disabled. " + (authSvc.getAuthenticationProviderIds().isEmpty() ? "WARNING: no enabled authentication providers left." : ""));
}
}
use of edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException in project dataverse by IQSS.
the class EchoAuthenticationProviderFactory method buildProvider.
@Override
public AuthenticationProvider buildProvider(AuthenticationProviderRow aRow) throws AuthorizationSetupException {
String rawData = aRow.getFactoryData();
String[] data = { "", "" };
if (rawData != null) {
data = aRow.getFactoryData().split(",", -1);
}
try {
return new EchoAuthenticationProvider(aRow.getId(), data[0], data[1], new AuthenticationProviderDisplayInfo(aRow.getId(), aRow.getTitle(), aRow.getSubtitle()));
} catch (ArrayIndexOutOfBoundsException e) {
throw new AuthorizationSetupException("Can't create Echo prov. Raw data: '" + rawData + "'", e);
}
}
Aggregations