Search in sources :

Example 11 with SecurityHole

use of org.candlepin.common.auth.SecurityHole in project candlepin by candlepin.

the class StatusResource method status.

/**
 * Retrieves the Status of the System
 * <p>
 * <pre>
 * {
 *   "result" : true,
 *   "version" : "0.9.10",
 *   "rulesVersion" : "5.8",
 *   "release" : "1",
 *   "standalone" : true,
 *   "timeUTC" : [date],
 *   "managerCapabilities" : [ "cores", "ram", "instance_multiplier" ],
 *   "rulesSource" : "DEFAULT"
 * }
 * </pre>
 * <p>
 * Status to see if a server is up and running
 *
 * @return a Status object
 * @httpcode 200
 */
@GET
@ApiOperation(value = "Status", notes = "Returns status of the server", authorizations = {})
@Produces({ MediaType.APPLICATION_JSON })
@SecurityHole(noAuth = true, anon = true)
public Status status() {
    StatusCache statusCache = candlepinCache.getStatusCache();
    Status cached = statusCache.getStatus();
    if (cached != null) {
        return cached;
    }
    /*
         * Originally this was used to indicate database connectivity being good/bad.
         * In reality it could never be false, the request would fail. This check has
         * been moved to GET /status/db.
         */
    boolean good = true;
    try {
        rulesCurator.getUpdatedFromDB();
    } catch (Exception e) {
        log.error("Error checking database connection", e);
        good = false;
    }
    CandlepinModeChange modeChange = modeManager.getLastCandlepinModeChange();
    if (modeChange.getMode() != Mode.NORMAL) {
        good = false;
    }
    Status status = new Status(good, version, release, standalone, jsProvider.getRulesVersion(), jsProvider.getRulesSource(), modeChange.getMode(), modeChange.getReason(), modeChange.getChangeTime());
    statusCache.setStatus(status);
    return status;
}
Also used : Status(org.candlepin.model.Status) StatusCache(org.candlepin.cache.StatusCache) CandlepinModeChange(org.candlepin.model.CandlepinModeChange) SecurityHole(org.candlepin.common.auth.SecurityHole) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with SecurityHole

use of org.candlepin.common.auth.SecurityHole in project candlepin by candlepin.

the class AuthorizationFeature method configure.

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    Method method = resourceInfo.getResourceMethod();
    SecurityHole securityHole = method.getAnnotation(SecurityHole.class);
    String name = method.getDeclaringClass().getName() + "." + method.getName();
    if (securityHole != null) {
        log.debug("Not registering authorization filter on {}", name);
        context.register(securityHoleFilter);
    } else if (resourceInfo.getResourceClass().equals(ApiListingResource.class)) {
        log.debug("Not registering authorization filter for Swagger: {}", name);
        context.register(securityHoleFilter);
    } else if (isSuperAdminOnly(method)) {
        log.debug("Registering superadmin only on {}", name);
        context.register(superAdminFilter);
    } else {
        log.debug("Registering standard authorization on {}", name);
        context.register(authorizationFilter);
    }
}
Also used : SecurityHole(org.candlepin.common.auth.SecurityHole) ApiListingResource(io.swagger.jaxrs.listing.ApiListingResource) Method(java.lang.reflect.Method)

Aggregations

SecurityHole (org.candlepin.common.auth.SecurityHole)12 Produces (javax.ws.rs.Produces)10 ApiOperation (io.swagger.annotations.ApiOperation)8 GET (javax.ws.rs.GET)6 ApiResponses (io.swagger.annotations.ApiResponses)5 Path (javax.ws.rs.Path)5 Transactional (com.google.inject.persist.Transactional)4 Consumes (javax.ws.rs.Consumes)4 BadRequestException (org.candlepin.common.exceptions.BadRequestException)4 Owner (org.candlepin.model.Owner)4 Product (org.candlepin.model.Product)3 ApiListingResource (io.swagger.jaxrs.listing.ApiListingResource)2 Method (java.lang.reflect.Method)2 POST (javax.ws.rs.POST)2 Consumer (org.candlepin.model.Consumer)2 ContentOverride (org.candlepin.model.ContentOverride)2 ProductCertificate (org.candlepin.model.ProductCertificate)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1