Search in sources :

Example 96 with Consumes

use of javax.ws.rs.Consumes in project graylog2-server by Graylog2.

the class LdapResource method testLdapConfiguration.

@POST
@Timed
@RequiresPermissions(RestPermissions.LDAP_EDIT)
@ApiOperation("Test LDAP Configuration")
@Path("/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@NoAuditEvent("only used to test LDAP configuration")
public LdapTestConfigResponse testLdapConfiguration(@ApiParam(name = "Configuration to test", required = true) @Valid @NotNull LdapTestConfigRequest request) {
    final LdapConnectionConfig config = new LdapConnectionConfig();
    final URI ldapUri = request.ldapUri();
    config.setLdapHost(ldapUri.getHost());
    config.setLdapPort(ldapUri.getPort());
    config.setUseSsl(ldapUri.getScheme().startsWith("ldaps"));
    config.setUseTls(request.useStartTls());
    if (request.trustAllCertificates()) {
        config.setTrustManagers(new TrustAllX509TrustManager());
    }
    if (!isNullOrEmpty(request.systemUsername()) && !isNullOrEmpty(request.systemPassword())) {
        config.setName(request.systemUsername());
        config.setCredentials(request.systemPassword());
    }
    LdapNetworkConnection connection = null;
    try {
        try {
            connection = ldapConnector.connect(config);
        } catch (LdapException e) {
            return LdapTestConfigResponse.create(false, false, false, Collections.<String, String>emptyMap(), Collections.<String>emptySet(), e.getMessage());
        }
        if (null == connection) {
            return LdapTestConfigResponse.create(false, false, false, Collections.<String, String>emptyMap(), Collections.<String>emptySet(), "Could not connect to LDAP server");
        }
        boolean connected = connection.isConnected();
        boolean systemAuthenticated = connection.isAuthenticated();
        // the web interface allows testing the connection only, in that case we can bail out early.
        if (request.testConnectOnly()) {
            return LdapTestConfigResponse.create(connected, systemAuthenticated, false, Collections.<String, String>emptyMap(), Collections.<String>emptySet());
        }
        String userPrincipalName = null;
        boolean loginAuthenticated = false;
        Map<String, String> entryMap = Collections.emptyMap();
        String exception = null;
        Set<String> groups = Collections.emptySet();
        try {
            final LdapEntry entry = ldapConnector.search(connection, request.searchBase(), request.searchPattern(), "*", request.principal(), request.activeDirectory(), request.groupSearchBase(), request.groupIdAttribute(), request.groupSearchPattern());
            if (entry != null) {
                userPrincipalName = entry.getBindPrincipal();
                entryMap = entry.getAttributes();
                groups = entry.getGroups();
            }
        } catch (CursorException | LdapException e) {
            exception = e.getMessage();
        }
        try {
            loginAuthenticated = ldapConnector.authenticate(connection, userPrincipalName, request.password());
        } catch (Exception e) {
            exception = e.getMessage();
        }
        return LdapTestConfigResponse.create(connected, systemAuthenticated, loginAuthenticated, entryMap, groups, exception);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (IOException e) {
                LOG.warn("Unable to close LDAP connection.", e);
            }
        }
    }
}
Also used : LdapConnectionConfig(org.apache.directory.ldap.client.api.LdapConnectionConfig) LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) IOException(java.io.IOException) TrustAllX509TrustManager(org.graylog2.security.TrustAllX509TrustManager) URI(java.net.URI) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) IOException(java.io.IOException) ValidationException(org.graylog2.plugin.database.ValidationException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 97 with Consumes

use of javax.ws.rs.Consumes in project graylog2-server by Graylog2.

the class RotationStrategyResource method config.

@PUT
@Path("config")
@Consumes(MediaType.APPLICATION_JSON)
@Timed
@ApiOperation(value = "Configuration of the current rotation strategy", notes = "This resource stores the configuration of the currently used rotation strategy.")
@AuditEvent(type = AuditEventTypes.ES_INDEX_ROTATION_STRATEGY_UPDATE)
public RotationStrategySummary config(@ApiParam(value = "The description of the rotation strategy and its configuration", required = true) @Valid @NotNull RotationStrategySummary rotationStrategySummary) {
    if (!rotationStrategies.containsKey(rotationStrategySummary.strategy())) {
        throw new NotFoundException("Couldn't find rotation strategy for given type " + rotationStrategySummary.strategy());
    }
    final IndexManagementConfig oldConfig = clusterConfigService.get(IndexManagementConfig.class);
    if (oldConfig == null) {
        throw new InternalServerErrorException("Couldn't retrieve index management configuration");
    }
    final IndexManagementConfig indexManagementConfig = IndexManagementConfig.create(rotationStrategySummary.strategy(), oldConfig.retentionStrategy());
    clusterConfigService.write(rotationStrategySummary.config());
    clusterConfigService.write(indexManagementConfig);
    return rotationStrategySummary;
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 98 with Consumes

use of javax.ws.rs.Consumes in project nhin-d by DirectProject.

the class TrustBundleResource method updateSigningCert.

/**
     * Updates the signing certificate of a trust bundle.
     * @param bundleName The name of the trust bundle to update.
     * @param certData A DER encoded representation of the new signing certificate.
     * @return Status of 204 if the trust bundle's signing certificate was updated, status of 400 if the signing certificate is
     * invalid, or a status 404 if a trust bundle with the given name does not exist.
     */
@POST
@Path("{bundle}/signingCert")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateSigningCert(@PathParam("bundle") String bundleName, byte[] certData) {
    X509Certificate signingCert = null;
    if (certData.length > 0) {
        try {
            signingCert = CertUtils.toX509Certificate(certData);
        } catch (CertificateConversionException ex) {
            log.error("Signing certificate is not in a valid format " + bundleName, ex);
            return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
        }
    }
    // make sure the bundle exists
    org.nhindirect.config.store.TrustBundle entityBundle;
    try {
        entityBundle = bundleDao.getTrustBundleByName(bundleName);
        if (entityBundle == null)
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up bundle.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    // now update
    try {
        bundleDao.updateTrustBundleSigningCertificate(entityBundle.getId(), signingCert);
        return Response.noContent().cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error updating trust bundle signing certificate.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) X509Certificate(java.security.cert.X509Certificate) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 99 with Consumes

use of javax.ws.rs.Consumes in project nhin-d by DirectProject.

the class TrustBundleResource method updateBundleAttributes.

/**
     * Updates multiple bundle attributes.  If the URL of the bundle changes, then the bundle is automatically refreshed.
     * @param bundleName The name of the bundle to update.
     * @param bundleData The data of the trust bundle to update.  Empty or null attributes indicate that the attribute should not be changed.
     * @return Status of 204 if the bundle attributes were updated, status of 400 if the signing certificate is
     * invalid, or a status 404 if a trust bundle with the given name does not exist.
     */
@POST
@Path("{bundle}/bundleAttributes")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateBundleAttributes(@PathParam("bundle") String bundleName, TrustBundle bundleData) {
    // make sure the bundle exists
    org.nhindirect.config.store.TrustBundle entityBundle;
    try {
        entityBundle = bundleDao.getTrustBundleByName(bundleName);
        if (entityBundle == null)
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up bundle.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    final String oldBundleURL = entityBundle.getBundleURL();
    // if there is a signing certificate in the request, make sure it's valid
    X509Certificate newSigningCert = null;
    if (bundleData.getSigningCertificateData() != null) {
        try {
            newSigningCert = CertUtils.toX509Certificate(bundleData.getSigningCertificateData());
        } catch (CertificateConversionException ex) {
            log.error("Signing certificate is not in a valid format " + bundleName, ex);
            return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
        }
    }
    // update the bundle
    try {
        bundleDao.updateTrustBundleAttributes(entityBundle.getId(), bundleData.getBundleName(), bundleData.getBundleURL(), newSigningCert, bundleData.getRefreshInterval());
        // if the URL changed, the bundle needs to be refreshed
        if (bundleData.getBundleURL() != null && !bundleData.getBundleURL().isEmpty() && !oldBundleURL.equals(bundleData.getBundleURL())) {
            entityBundle = bundleDao.getTrustBundleById(entityBundle.getId());
            template.sendBody(entityBundle);
        }
        return Response.noContent().cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error updating trust bundle attributes.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) X509Certificate(java.security.cert.X509Certificate) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 100 with Consumes

use of javax.ws.rs.Consumes in project nhin-d by DirectProject.

the class AddressResource method addAddress.

/**
     * Adds an address to the system and associates it with a domain.
     * @param uriInfo Injected URI context used for building the location URI.
     * @param address The address to add.
     * @return Returns status 201 if added successfully, 404 if the domain does not exist, or 409 if
     * the address already exists.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addAddress(@Context UriInfo uriInfo, Address address) {
    // make sure the domain exists
    if (address.getDomainName() == null || address.getDomainName().isEmpty())
        return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
    org.nhindirect.config.store.Domain domain;
    try {
        domain = domainDao.getDomainByName(address.getDomainName());
        if (domain == null)
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up existing domain.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    // check to see if it already exists
    try {
        if (dao.get(address.getEmailAddress()) != null)
            return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up existing address.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    final org.nhindirect.config.store.Address toAdd = EntityModelConversion.toEntityAddress(address);
    toAdd.setDomain(domain);
    try {
        dao.add(toAdd);
        final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
        final URI newLoc = newLocBuilder.path("address/" + address.getEmailAddress()).build();
        return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error adding address.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)1610 Path (javax.ws.rs.Path)1243 Produces (javax.ws.rs.Produces)1233 POST (javax.ws.rs.POST)917 ApiOperation (io.swagger.annotations.ApiOperation)508 ApiResponses (io.swagger.annotations.ApiResponses)445 PUT (javax.ws.rs.PUT)439 GET (javax.ws.rs.GET)224 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)215 URI (java.net.URI)207 IOException (java.io.IOException)160 ArrayList (java.util.ArrayList)142 WebApplicationException (javax.ws.rs.WebApplicationException)142 Response (javax.ws.rs.core.Response)140 Authorizable (org.apache.nifi.authorization.resource.Authorizable)100 DELETE (javax.ws.rs.DELETE)87 TimedResource (org.killbill.commons.metrics.TimedResource)84 CallContext (org.killbill.billing.util.callcontext.CallContext)83 Timed (com.codahale.metrics.annotation.Timed)78 HashMap (java.util.HashMap)78