Search in sources :

Example 1 with AuthorizationSetupException

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);
        }
    });
}
Also used : AuthenticationProviderFactoryNotFoundException(edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException) BuiltinAuthenticationProviderFactory(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProviderFactory) OAuth2AuthenticationProviderFactory(edu.harvard.iq.dataverse.authorization.providers.oauth2.OAuth2AuthenticationProviderFactory) ShibAuthenticationProviderFactory(edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProviderFactory) AuthorizationSetupException(edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with AuthorizationSetupException

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());
    }
}
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 AuthorizationSetupException

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." : ""));
    }
}
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)

Example 4 with AuthorizationSetupException

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);
    }
}
Also used : AuthorizationSetupException(edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException) AuthenticationProviderDisplayInfo(edu.harvard.iq.dataverse.authorization.AuthenticationProviderDisplayInfo)

Aggregations

AuthorizationSetupException (edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException)4 AuthenticationProviderFactoryNotFoundException (edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException)2 AuthenticationProviderRow (edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow)2 Path (javax.ws.rs.Path)2 AuthenticationProvider (edu.harvard.iq.dataverse.authorization.AuthenticationProvider)1 AuthenticationProviderDisplayInfo (edu.harvard.iq.dataverse.authorization.AuthenticationProviderDisplayInfo)1 BuiltinAuthenticationProviderFactory (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProviderFactory)1 OAuth2AuthenticationProviderFactory (edu.harvard.iq.dataverse.authorization.providers.oauth2.OAuth2AuthenticationProviderFactory)1 ShibAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider)1 ShibAuthenticationProviderFactory (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProviderFactory)1 PostConstruct (javax.annotation.PostConstruct)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1