Search in sources :

Example 1 with AuthenticationProviderRow

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." : ""));
}
Also used : AuthenticationProviderRow(edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 2 with AuthenticationProviderRow

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());
    }
}
Also used : AuthenticationProvider(edu.harvard.iq.dataverse.authorization.AuthenticationProvider) ShibAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider) AuthenticationProviderRow(edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow) AuthorizationSetupException(edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with AuthenticationProviderRow

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." : ""));
    }
}
Also used : AuthenticationProviderFactoryNotFoundException(edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException) AuthenticationProviderRow(edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow) AuthorizationSetupException(edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

AuthenticationProviderRow (edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow)3 Path (javax.ws.rs.Path)3 AuthorizationSetupException (edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException)2 AuthenticationProvider (edu.harvard.iq.dataverse.authorization.AuthenticationProvider)1 AuthenticationProviderFactoryNotFoundException (edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException)1 ShibAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1