Search in sources :

Example 1 with Configuration

use of org.candlepin.common.config.Configuration in project candlepin by candlepin.

the class OAuth method setupAccessors.

/**
 * Look for settings which are in the form of
 * candlepin.auth.oauth.consumer.CONSUMERNAME.secret = CONSUMERSECRET and
 * create consumers for them.
 */
protected void setupAccessors() {
    String prefix = "candlepin.auth.oauth.consumer.";
    Configuration oauthConfig = config.strippedSubset(prefix);
    for (String key : oauthConfig.getKeys()) {
        String[] parts = key.split("\\.");
        if ((parts.length == 2) && (parts[1].equals("secret"))) {
            String consumerName = parts[0];
            String secret = oauthConfig.getString(key);
            log.debug(String.format("Creating consumer '%s'", consumerName));
            OAuthConsumer consumer = new OAuthConsumer("", consumerName, secret, null);
            OAuthAccessor accessor = new OAuthAccessor(consumer);
            accessors.put(consumerName, accessor);
        }
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) Configuration(org.candlepin.common.config.Configuration) OAuthConsumer(net.oauth.OAuthConsumer)

Example 2 with Configuration

use of org.candlepin.common.config.Configuration in project candlepin by candlepin.

the class DefaultProductServiceAdapterTest method init.

@Before
public void init() {
    opc = mock(OwnerProductCurator.class);
    idgen = mock(UniqueIdGenerator.class);
    Configuration config = mock(Configuration.class);
    pki = mock(PKIUtility.class);
    extUtil = new X509ExtensionUtil(config);
    cc = mock(ContentCurator.class);
    pcc = spy(new ProductCertificateCurator(pki, extUtil));
    when(config.getBoolean(ConfigProperties.ENV_CONTENT_FILTERING)).thenReturn(false);
    dpsa = new DefaultProductServiceAdapter(opc, pcc, cc, idgen);
}
Also used : X509ExtensionUtil(org.candlepin.util.X509ExtensionUtil) UniqueIdGenerator(org.candlepin.service.UniqueIdGenerator) Configuration(org.candlepin.common.config.Configuration) ContentCurator(org.candlepin.model.ContentCurator) ProductCertificateCurator(org.candlepin.model.ProductCertificateCurator) PKIUtility(org.candlepin.pki.PKIUtility) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) Before(org.junit.Before)

Example 3 with Configuration

use of org.candlepin.common.config.Configuration in project candlepin by candlepin.

the class CandlepinContextListener method readConfiguration.

protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
    // Use StandardCharsets.UTF_8 when we move to Java 7
    Charset utf8 = Charset.forName("UTF-8");
    EncryptedConfiguration systemConfig = new EncryptedConfiguration();
    systemConfig.setEncoding(utf8);
    File configFile = new File(ConfigProperties.DEFAULT_CONFIG_FILE);
    if (configFile.canRead()) {
        log.debug("Loading system configuration");
        // First, read the system configuration
        systemConfig.load(configFile);
        log.debug("System configuration: " + systemConfig);
    }
    systemConfig.use(PASSPHRASE_SECRET_FILE).toDecrypt(ENCRYPTED_PROPERTIES);
    // load the defaults
    MapConfiguration defaults = new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES);
    // Default to Postgresql if jpa.config.hibernate.dialect is unset
    DatabaseConfigFactory.SupportedDatabase db = determinDatabaseConfiguration(systemConfig.getString("jpa.config.hibernate.dialect", PostgreSQLDialect.class.getName()));
    log.info("Running under {}", db.getLabel());
    Configuration databaseConfig = DatabaseConfigFactory.fetchConfig(db);
    // users should be doing unbidden so it is undocumented.
    return EncryptedConfiguration.merge(systemConfig, databaseConfig, defaults);
}
Also used : MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) MapConfiguration(org.candlepin.common.config.MapConfiguration) Charset(java.nio.charset.Charset) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) File(java.io.File) DatabaseConfigFactory(org.candlepin.config.DatabaseConfigFactory)

Example 4 with Configuration

use of org.candlepin.common.config.Configuration in project candlepin by candlepin.

the class PinsetterKernelTest method deletedCronTask.

@Test
public void deletedCronTask() throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
    props.put("org.quartz.jobStore.isClustered", "true");
    props.put("pinsetter.org.candlepin.pinsetter.tasks.JobCleaner.schedule", "*/1 * * * * ?");
    Configuration config = new MapConfiguration(props);
    JobDetail jobDetail = mock(JobDetail.class);
    String crongrp = "cron group";
    Set<JobKey> jobs = new HashSet<>();
    String deletedJobId = "StatisticHistoryTask-taylor-swift";
    JobKey deletedKey = jobKey(deletedJobId);
    jobs.add(deletedKey);
    JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
    jobs.add(key);
    CronTrigger cronTrigger = mock(CronTrigger.class);
    when(cronTrigger.getJobKey()).thenReturn(deletedKey);
    when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
    when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
    when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
    doReturn(JobCleaner.class).when(jobDetail).getJobClass();
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.startup();
    verify(jcurator).deleteJobNoStatusReturn(eq(deletedJobId));
    verify(sched, atLeastOnce()).deleteJob(deletedKey);
}
Also used : CronTrigger(org.quartz.CronTrigger) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Configuration

use of org.candlepin.common.config.Configuration in project candlepin by candlepin.

the class PinsetterKernelTest method updateSchedule.

@Test
public void updateSchedule() throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
    props.put("org.quartz.jobStore.isClustered", "true");
    props.put("pinsetter.org.candlepin.pinsetter.tasks." + "JobCleaner.schedule", "*/1 * * * * ?");
    Configuration config = new MapConfiguration(props);
    JobDetail jobDetail = mock(JobDetail.class);
    String crongrp = "cron group";
    Set<JobKey> jobs = new HashSet<>();
    JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
    jobs.add(key);
    CronTrigger cronTrigger = mock(CronTrigger.class);
    when(cronTrigger.getJobKey()).thenReturn(key);
    when(cronTrigger.getCronExpression()).thenReturn("*/7 * * * * ?");
    when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
    when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
    when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
    doReturn(JobCleaner.class).when(jobDetail).getJobClass();
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.startup();
    verify(sched).deleteJob(key);
    verify(jcurator).create(any(JobStatus.class));
}
Also used : CronTrigger(org.quartz.CronTrigger) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) TriggerKey(org.quartz.TriggerKey) JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Configuration (org.candlepin.common.config.Configuration)20 MapConfiguration (org.candlepin.common.config.MapConfiguration)9 Test (org.junit.Test)9 Before (org.junit.Before)7 JobDetail (org.quartz.JobDetail)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)3 JobCleaner (org.candlepin.pinsetter.tasks.JobCleaner)3 CronTrigger (org.quartz.CronTrigger)3 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ServletContext (javax.servlet.ServletContext)2 Target (org.candlepin.audit.Event.Target)2 Type (org.candlepin.audit.Event.Type)2 ConfigurationException (org.candlepin.common.config.ConfigurationException)2 PropertiesFileConfiguration (org.candlepin.common.config.PropertiesFileConfiguration)2 StandardTranslator (org.candlepin.dto.StandardTranslator)2 Consumer (org.candlepin.model.Consumer)2