use of org.candlepin.service.impl.DefaultUserServiceAdapter 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.";
}
}
Aggregations