Java Code Examples for org.apache.brooklyn.api.mgmt.ManagementContext#getConfig()
The following examples show how to use
org.apache.brooklyn.api.mgmt.ManagementContext#getConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OsgiLauncherImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected void startingUp() { super.startingUp(); ManagementContext managementContext = getManagementContext(); BrooklynProperties brooklynProperties = (BrooklynProperties) managementContext.getConfig(); if (BrooklynWebConfig.hasNoSecurityOptions(brooklynProperties)) { LOG.info("No security provider options specified. Define a security provider or users to prevent a random password being created and logged."); // Deprecated in 0.11.0. Add to release notes and remove in next release. brooklynProperties.put( BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); managementContext.getScratchpad().put( BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, new BrooklynUserWithRandomPasswordSecurityProvider(managementContext)); } }
Example 2
Source File: SshTasks.java From brooklyn-server with Apache License 2.0 | 6 votes |
private static Map<String, Object> getSshFlags(Location location) { Set<ConfigKey<?>> sshConfig = MutableSet.of(); StringConfigMap mgmtConfig = null; sshConfig.addAll(location.config().findKeysPresent(ConfigPredicates.nameStartsWith(SshTool.BROOKLYN_CONFIG_KEY_PREFIX))); if (location instanceof AbstractLocation) { ManagementContext mgmt = ((AbstractLocation)location).getManagementContext(); if (mgmt!=null) { mgmtConfig = mgmt.getConfig(); sshConfig.addAll(mgmtConfig.findKeysPresent(ConfigPredicates.nameStartsWith(SshTool.BROOKLYN_CONFIG_KEY_PREFIX))); } } Map<String, Object> result = Maps.newLinkedHashMap(); for (ConfigKey<?> key : sshConfig) { Maybe<Object> v = ((LocationInternal)location).config().getRaw(key); if (v.isAbsent() && mgmtConfig!=null) v = Maybe.of( (Object) mgmtConfig.getConfig(key) ); result.put(ConfigUtils.unprefixedKey(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, key).getName(), v.get()); } return result; }
Example 3
Source File: LdapSecurityProvider.java From brooklyn-server with Apache License 2.0 | 5 votes |
public LdapSecurityProvider(ManagementContext mgmt) { StringConfigMap properties = mgmt.getConfig(); ldapUrl = properties.getConfig(BrooklynWebConfig.LDAP_URL); Strings.checkNonEmpty(ldapUrl, "LDAP security provider configuration missing required property "+BrooklynWebConfig.LDAP_URL); ldapRealm = CharMatcher.isNot('"').retainFrom(properties.getConfig(BrooklynWebConfig.LDAP_REALM)); Strings.checkNonEmpty(ldapRealm, "LDAP security provider configuration missing required property "+BrooklynWebConfig.LDAP_REALM); if(Strings.isBlank(properties.getConfig(BrooklynWebConfig.LDAP_OU))) { LOG.info("Setting LDAP ou attribute to: Users"); organizationUnit = "Users"; } else { organizationUnit = CharMatcher.isNot('"').retainFrom(properties.getConfig(BrooklynWebConfig.LDAP_OU)); } Strings.checkNonEmpty(ldapRealm, "LDAP security provider configuration missing required property "+BrooklynWebConfig.LDAP_OU); }
Example 4
Source File: ExplicitUsersSecurityProvider.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** checks the supplied candidate user and password against the * expect password (or SHA-256 + SALT thereof) defined as brooklyn properties. */ public static boolean checkExplicitUserPassword(ManagementContext mgmt, String user, String password) { BrooklynProperties properties = (BrooklynProperties) mgmt.getConfig(); String expectedPassword = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user)); String salt = properties.getConfig(BrooklynWebConfig.SALT_FOR_USER(user)); String expectedSha256 = properties.getConfig(BrooklynWebConfig.SHA256_FOR_USER(user)); return checkPassword(password, expectedPassword, expectedSha256, salt); }
Example 5
Source File: BrooklynServerPaths.java From brooklyn-server with Apache License 2.0 | 5 votes |
public static File getOsgiCacheDir(ManagementContext mgmt) { StringConfigMap brooklynProperties = mgmt.getConfig(); String cacheDir = brooklynProperties.getConfig(BrooklynServerConfig.OSGI_CACHE_DIR); // note dir should be different for each instance if starting multiple instances // hence default including management node ID cacheDir = TemplateProcessor.processTemplateContents(cacheDir, mgmt, MutableMap.of(BrooklynServerConfig.MGMT_BASE_DIR.getName(), getMgmtBaseDir(mgmt), BrooklynServerConfig.MANAGEMENT_NODE_ID_PROPERTY, mgmt.getManagementNodeId(), Os.TmpDirFinder.BROOKLYN_OS_TMPDIR_PROPERTY, Os.tmp())); cacheDir = resolveAgainstBaseDir(mgmt.getConfig(), cacheDir); return new File(cacheDir); }
Example 6
Source File: BrooklynServerPaths.java From brooklyn-server with Apache License 2.0 | 5 votes |
public static boolean isOsgiCacheForCleaning(ManagementContext mgmt, File cacheDir) { StringConfigMap brooklynProperties = mgmt.getConfig(); Boolean clean = brooklynProperties.getConfig(BrooklynServerConfig.OSGI_CACHE_CLEAN); if (clean==null) { // as per javadoc on key, clean defaults to iff it is a node-id-specific directory clean = cacheDir.getName().contains(mgmt.getManagementNodeId()); } return clean; }
Example 7
Source File: WebAppContextProvider.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** * Serve given WAR at the given pathSpec; if not yet started, it is simply remembered until start; * if server already running, the context for this WAR is started. * @return the context created and added as a handler (and possibly already started if server is * started, so be careful with any changes you make to it!) */ public WebAppContext get(ManagementContext managementContext, Map<String, Object> attributes, boolean ignoreFailures) { checkNotNull(managementContext, "managementContext"); checkNotNull(attributes, "attributes"); boolean isRoot = pathSpec.isEmpty(); final WebAppContext context = new WebAppContext(); // use a unique session ID to prevent interference with other web apps on same server (esp for localhost); // note however this is only run for the legacy launcher // TODO would be nice if the various karaf startups rename the session cookie property (from JSESSIONID) // as the default is likely to conflict with other java-based servers (esp on localhost); // this can be done e.g. on ServletContext.getSessionCookieConfig(), but will be needed for REST and for JS (static) bundles // low priority however, if you /etc/hosts a localhost-brooklyn and use that it will stop conflicting context.setInitParameter(SessionHandler.__SessionCookieProperty, SessionHandler.__DefaultSessionCookie + "_" + "BROOKLYN" + Identifiers.makeRandomId(6)); context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); context.setAttribute(BrooklynServiceAttributes.BROOKLYN_MANAGEMENT_CONTEXT, managementContext); for (Map.Entry<String, Object> attributeEntry : attributes.entrySet()) { context.setAttribute(attributeEntry.getKey(), attributeEntry.getValue()); } try { final CustomResourceLocator locator = new CustomResourceLocator(managementContext.getConfig(), ResourceUtils.create(this)); final InputStream resource = locator.getResourceFromUrl(warUrl); final String warName = isRoot ? "ROOT" : ("embedded-" + pathSpec); File tmpWarFile = Os.writeToTempFile(resource, warName, ".war"); context.setWar(tmpWarFile.getAbsolutePath()); } catch (Exception e) { LOG.warn("Failed to deploy webapp " + pathSpec + " from " + warUrl + (ignoreFailures ? "; launching run without WAR" : " (rethrowing)") + ": " + Exceptions.collapseText(e)); if (!ignoreFailures) { throw new IllegalStateException("Failed to deploy webapp " + pathSpec + " from " + warUrl + ": " + Exceptions.collapseText(e), e); } LOG.debug("Detail on failure to deploy webapp: " + e, e); context.setWar("/dev/null"); } context.setContextPath("/" + pathSpec); context.setParentLoaderPriority(true); return context; }
Example 8
Source File: BrooklynServerPaths.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** @see PersistencePathResolver */ public static PersistencePathResolver newMainPersistencePathResolver(ManagementContext mgmt) { return new PersistencePathResolver(mgmt.getConfig()); }
Example 9
Source File: BrooklynServerPaths.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** @see PersistenceBackupPathResolver */ public static PersistenceBackupPathResolver newBackupPersistencePathResolver(ManagementContext mgmt) { return new PersistenceBackupPathResolver(mgmt.getConfig()); }