Search in sources :

Example 1 with SystemPrincipal

use of org.candlepin.auth.SystemPrincipal in project candlepin by candlepin.

the class DatabaseListener method onEvent.

@Override
public void onEvent(Event event) {
    // We're outside of a web request here, need to create this event and satisfy the
    // access control interceptor.
    Principal systemPrincipal = new SystemPrincipal();
    ResteasyProviderFactory.pushContext(Principal.class, systemPrincipal);
    if (log.isDebugEnabled()) {
        log.debug("Received event: " + event);
    }
    if (event != null) {
        eventCurator.create(event);
    }
}
Also used : SystemPrincipal(org.candlepin.auth.SystemPrincipal) SystemPrincipal(org.candlepin.auth.SystemPrincipal) Principal(org.candlepin.auth.Principal)

Example 2 with SystemPrincipal

use of org.candlepin.auth.SystemPrincipal in project candlepin by candlepin.

the class PinsetterKernel method scheduleSingleJob.

public JobStatus scheduleSingleJob(Class<? extends KingpinJob> job, String jobName) throws PinsetterException {
    JobDataMap map = new JobDataMap();
    map.put(PinsetterJobListener.PRINCIPAL_KEY, new SystemPrincipal());
    JobDetail detail = newJob(job).withIdentity(jobName, CRON_GROUP).usingJobData(map).build();
    Trigger trigger = newTrigger().withIdentity(detail.getKey().getName() + " trigger", SINGLE_JOB_GROUP).build();
    return scheduleJob(detail, SINGLE_JOB_GROUP, trigger);
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SystemPrincipal(org.candlepin.auth.SystemPrincipal)

Example 3 with SystemPrincipal

use of org.candlepin.auth.SystemPrincipal in project candlepin by candlepin.

the class AdminResource method initialize.

@GET
@Produces({ MediaType.TEXT_PLAIN })
@Path("init")
@SecurityHole(noAuth = true)
@ApiOperation(notes = "Initializes the Candlepin database. Currently this just" + " creates the admin user for standalone deployments using the" + " default user service adapter. It must be called once after" + " candlepin is installed, repeat calls are not required, but" + " will be harmless. The String returned is the description if" + " the db was or already is initialized.", value = "initialize")
public String initialize() {
    log.debug("Called initialize()");
    log.info("Initializing Candlepin database.");
    // the default user service adapter, and no other users exist already:
    if (userService instanceof DefaultUserServiceAdapter && userCurator.getUserCount() == 0) {
        // Push the system principal so we can create all these entries as a
        // superuser:
        ResteasyProviderFactory.pushContext(Principal.class, new SystemPrincipal());
        log.info("Creating default super admin.");
        User defaultAdmin = new User("admin", "admin", true);
        userService.createUser(defaultAdmin);
        return "Initialized!";
    } else {
        // Any other user service adapter and we really have nothing to do:
        return "Already initialized.";
    }
}
Also used : DefaultUserServiceAdapter(org.candlepin.service.impl.DefaultUserServiceAdapter) User(org.candlepin.model.User) SystemPrincipal(org.candlepin.auth.SystemPrincipal) Path(javax.ws.rs.Path) SecurityHole(org.candlepin.common.auth.SecurityHole) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with SystemPrincipal

use of org.candlepin.auth.SystemPrincipal in project candlepin by candlepin.

the class PinsetterKernel method scheduleJob.

@SuppressWarnings("unchecked")
public void scheduleJob(Class job, String jobName, Trigger trigger) throws PinsetterException {
    JobDataMap map = new JobDataMap();
    map.put(PinsetterJobListener.PRINCIPAL_KEY, new SystemPrincipal());
    JobDetail detail = newJob(job).withIdentity(jobName, CRON_GROUP).usingJobData(map).build();
    scheduleJob(detail, CRON_GROUP, trigger);
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) SystemPrincipal(org.candlepin.auth.SystemPrincipal)

Aggregations

SystemPrincipal (org.candlepin.auth.SystemPrincipal)4 JobDataMap (org.quartz.JobDataMap)2 JobDetail (org.quartz.JobDetail)2 ApiOperation (io.swagger.annotations.ApiOperation)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Principal (org.candlepin.auth.Principal)1 SecurityHole (org.candlepin.common.auth.SecurityHole)1 User (org.candlepin.model.User)1 DefaultUserServiceAdapter (org.candlepin.service.impl.DefaultUserServiceAdapter)1 CronTrigger (org.quartz.CronTrigger)1 Trigger (org.quartz.Trigger)1 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)1