use of edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow in project dataverse by IQSS.
the class Admin method deleteAuthenticationProvider.
@DELETE
@Path("authenticationProviders/{id}/")
public Response deleteAuthenticationProvider(@PathParam("id") String id) {
authSvc.deregisterProvider(id);
AuthenticationProviderRow row = em.find(AuthenticationProviderRow.class, id);
if (row != null) {
em.remove(row);
}
return ok("AuthenticationProvider " + id + " deleted. " + (authSvc.getAuthenticationProviderIds().isEmpty() ? "WARNING: no enabled authentication providers left." : ""));
}
use of edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow 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.providers.AuthenticationProviderRow 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." : ""));
}
}
Aggregations