use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class InboxScannerService method updated.
// synchronized with activate(ComponentContext)
@Override
public synchronized void updated(Dictionary properties) throws ConfigurationException {
// build scanner configuration
final String orgId = getCfg(properties, USER_ORG);
final String userId = getCfg(properties, USER_NAME);
final String mediaFlavor = getCfg(properties, MEDIA_FLAVOR);
final String workflowDefinition = getCfg(properties, WORKFLOW_DEFINITION);
final Map<String, String> workflowConfig = getCfgAsMap(properties, WORKFLOW_CONFIG);
final int interval = getCfgAsInt(properties, INBOX_POLL);
final File inbox = new File(getCfg(properties, INBOX_PATH));
if (!inbox.isDirectory()) {
try {
FileUtils.forceMkdir(inbox);
} catch (IOException e) {
throw new ConfigurationException(INBOX_PATH, String.format("%s does not exists and could not be created", inbox.getAbsolutePath()));
}
}
/* We need to be able to read from the inbox to get files from there */
if (!inbox.canRead()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot read from %s", inbox.getAbsolutePath()));
}
/* We need to be able to write to the inbox to remove files after they have been ingested */
if (!inbox.canWrite()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot write to %s", inbox.getAbsolutePath()));
}
final int maxthreads = option(cc.getBundleContext().getProperty("org.opencastproject.inbox.threads")).bind(Strings.toInt).getOrElse(1);
final Option<SecurityContext> secCtx = getUserAndOrganization(securityService, orgDir, orgId, userDir, userId).bind(new Function<Tuple<User, Organization>, Option<SecurityContext>>() {
@Override
public Option<SecurityContext> apply(Tuple<User, Organization> a) {
return some(new SecurityContext(securityService, a.getB(), a.getA()));
}
});
// Only setup new inbox if security context could be aquired
if (secCtx.isSome()) {
// remove old file install configuration
fileInstallCfg.foreach(removeFileInstallCfg);
// set up new file install config
fileInstallCfg = some(configureFileInstall(cc.getBundleContext(), inbox, interval));
// create new scanner
ingestor = some(new Ingestor(ingestService, workingFileRepository, secCtx.get(), workflowDefinition, workflowConfig, mediaFlavor, inbox, maxthreads));
logger.info("Now watching inbox {}", inbox.getAbsolutePath());
} else {
logger.warn("Cannot create security context for user {}, organization {}. " + "Either the organization or the user does not exist", userId, orgId);
}
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class InboxScannerService method getCfg.
/**
* Get a mandatory, non-blank value from a dictionary.
*
* @throws ConfigurationException
* key does not exist or its value is blank
*/
public static String getCfg(Dictionary d, String key) throws ConfigurationException {
Object p = d.get(key);
if (p == null)
throw new ConfigurationException(key, "does not exist");
String ps = p.toString();
if (StringUtils.isBlank(ps))
throw new ConfigurationException(key, "is blank");
return ps;
}
use of org.osgi.service.cm.ConfigurationException in project acs-aem-commons by Adobe-Consulting-Services.
the class MonthlyExpiresHeaderFilter method doActivate.
@Override
protected void doActivate(ComponentContext context) throws Exception {
super.doActivate(context);
@SuppressWarnings("unchecked") Dictionary<String, Object> props = context.getProperties();
dayOfMonth = PropertiesUtil.toString(props.get(PROP_EXPIRES_DAY_OF_MONTH), null);
if (StringUtils.isBlank(dayOfMonth)) {
throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month must be specified.");
}
if (!StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) {
// Make sure it's a valid value for Calendar.
try {
int intDay = Integer.parseInt(dayOfMonth);
Calendar test = Calendar.getInstance();
if (intDay < test.getMinimum(Calendar.DAY_OF_MONTH)) {
throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is smaller than minimum allowed value.");
}
if (intDay > test.getActualMaximum(Calendar.DAY_OF_MONTH)) {
throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is larger than least maximum allowed value.");
}
} catch (NumberFormatException ex) {
throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is not a valid value.");
}
}
}
use of org.osgi.service.cm.ConfigurationException in project acs-aem-commons by Adobe-Consulting-Services.
the class AbstractExpiresHeaderFilter method doActivate.
@Override
protected void doActivate(ComponentContext context) throws Exception {
Dictionary<?, ?> properties = context.getProperties();
String time = PropertiesUtil.toString(properties.get(PROP_EXPIRES_TIME), null);
if (StringUtils.isBlank(time)) {
throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified.");
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
sdf.setLenient(false);
try {
Date date = sdf.parse(time);
expiresTime.setTime(date);
} catch (ParseException ex) {
throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified.");
}
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class LdapUserProviderFactory method updated.
/**
* {@inheritDoc}
*
* @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
*/
@Override
public void updated(String pid, Dictionary properties) throws ConfigurationException {
logger.debug("Updating LdapUserProviderFactory");
String organization = (String) properties.get(ORGANIZATION_KEY);
if (StringUtils.isBlank(organization))
throw new ConfigurationException(ORGANIZATION_KEY, "is not set");
String searchBase = (String) properties.get(SEARCH_BASE_KEY);
if (StringUtils.isBlank(searchBase))
throw new ConfigurationException(SEARCH_BASE_KEY, "is not set");
String searchFilter = (String) properties.get(SEARCH_FILTER_KEY);
if (StringUtils.isBlank(searchFilter))
throw new ConfigurationException(SEARCH_FILTER_KEY, "is not set");
String url = (String) properties.get(LDAP_URL_KEY);
if (StringUtils.isBlank(url))
throw new ConfigurationException(LDAP_URL_KEY, "is not set");
String instanceId = (String) properties.get(INSTANCE_ID_KEY);
if (StringUtils.isBlank(instanceId))
throw new ConfigurationException(INSTANCE_ID_KEY, "is not set");
String userDn = (String) properties.get(SEARCH_USER_DN);
String password = (String) properties.get(SEARCH_PASSWORD);
String roleAttributes = (String) properties.get(ROLE_ATTRIBUTES_KEY);
String rolePrefix = (String) properties.get(ROLE_PREFIX_KEY);
String[] excludePrefixes = null;
String strExcludePrefixes = (String) properties.get(EXCLUDE_PREFIXES_KEY);
if (StringUtils.isNotBlank(strExcludePrefixes)) {
excludePrefixes = strExcludePrefixes.split(",");
}
// Make sure that property convertToUppercase is true by default
String strUppercase = (String) properties.get(UPPERCASE_KEY);
boolean convertToUppercase = StringUtils.isBlank(strUppercase) ? true : Boolean.valueOf(strUppercase);
String[] extraRoles = new String[0];
String strExtraRoles = (String) properties.get(EXTRA_ROLES_KEY);
if (StringUtils.isNotBlank(strExtraRoles)) {
extraRoles = strExtraRoles.split(",");
}
int cacheSize = 1000;
logger.debug("Using cache size {} for {}", properties.get(CACHE_SIZE), LdapUserProviderFactory.class.getName());
try {
if (properties.get(CACHE_SIZE) != null) {
Integer configuredCacheSize = Integer.parseInt(properties.get(CACHE_SIZE).toString());
if (configuredCacheSize != null) {
cacheSize = configuredCacheSize.intValue();
}
}
} catch (Exception e) {
logger.warn("{} could not be loaded, default value is used: {}", CACHE_SIZE, cacheSize);
}
int cacheExpiration = 1;
try {
if (properties.get(CACHE_EXPIRATION) != null) {
Integer configuredCacheExpiration = Integer.parseInt(properties.get(CACHE_EXPIRATION).toString());
if (configuredCacheExpiration != null) {
cacheExpiration = configuredCacheExpiration.intValue();
}
}
} catch (Exception e) {
logger.warn("{} could not be loaded, default value is used: {}", CACHE_EXPIRATION, cacheExpiration);
}
// Now that we have everything we need, go ahead and activate a new provider, removing an old one if necessary
ServiceRegistration existingRegistration = providerRegistrations.remove(pid);
if (existingRegistration != null) {
existingRegistration.unregister();
}
Organization org;
try {
org = orgDirectory.getOrganization(organization);
} catch (NotFoundException e) {
logger.warn("Organization {} not found!", organization);
throw new ConfigurationException(ORGANIZATION_KEY, "not found");
}
// Dictionary to include a property to identify this LDAP instance in the security.xml file
Hashtable<String, String> dict = new Hashtable<>();
dict.put(INSTANCE_ID_SERVICE_PROPERTY_KEY, instanceId);
// Instantiate this LDAP instance and register it as such
LdapUserProviderInstance provider = new LdapUserProviderInstance(pid, org, searchBase, searchFilter, url, userDn, password, roleAttributes, rolePrefix, extraRoles, excludePrefixes, convertToUppercase, cacheSize, cacheExpiration, securityService);
providerRegistrations.put(pid, bundleContext.registerService(UserProvider.class.getName(), provider, null));
OpencastLdapAuthoritiesPopulator authoritiesPopulator = new OpencastLdapAuthoritiesPopulator(roleAttributes, rolePrefix, excludePrefixes, convertToUppercase, org, securityService, groupRoleProvider, extraRoles);
// Also, register this instance as LdapAuthoritiesPopulator so that it can be used within the security.xml file
authoritiesPopulatorRegistrations.put(pid, bundleContext.registerService(LdapAuthoritiesPopulator.class.getName(), authoritiesPopulator, dict));
}
Aggregations