@PostConstruct public void init() { this.activeProfiles = environment.getActiveProfiles(); }
private boolean hasKubernetesProfile(Environment environment) { for (String activeProfile : environment.getActiveProfiles()) { if (KUBERNETES_PROFILE.equalsIgnoreCase(activeProfile)) { return true; } } return false; }
@Override public void setEnvironment(Environment environment) { if (Arrays.asList(environment.getActiveProfiles()).contains("strict")) { this.exceptionIfInvalid = true; } }
@GetMapping("/profiles") public List<String> profiles() { return Arrays.asList(environment.getActiveProfiles()); }
private boolean hasIstioProfile(Environment environment) { return Arrays.stream(environment.getActiveProfiles()).anyMatch(ISTIO_PROFILE::equalsIgnoreCase); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Set<String> activeProfiles = Sets.newHashSet(context.getEnvironment().getActiveProfiles()); Set<String> requiredActiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnProfile.class.getName()); Set<String> requiredInactiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnMissingProfile.class .getName()); return Sets.difference(requiredActiveProfiles, activeProfiles).isEmpty() && Sets.intersection(requiredInactiveProfiles, activeProfiles).isEmpty(); }
@Test public void test() { assertTrue(Arrays.asList(applicationContext.getEnvironment().getActiveProfiles()).contains( getClass().getSimpleName().toLowerCase())); }
@Override protected void initFilterBean() throws ServletException { if (!initialized) { String[] pairs = compressionExtensionToMimeMappings.split(","); for (String pair : pairs) { String[] keyValue = pair.split(":"); extensionToMime.put(Pattern.compile(keyValue[0]), keyValue[1]); } if (!"none".equals(blackListURIs)) { String[] rawPatterns = blackListURIs.split(","); for (String rawPattern : rawPatterns) { blackListPatterns.add(Pattern.compile(rawPattern)); } } isDefaultEnvironment = !(ArrayUtils.isNotEmpty(environment.getActiveProfiles()) && Arrays.binarySearch(environment.getActiveProfiles(), "default") < 0); if (!resourceVersioningEnabled && shouldUseStaticCache()) { LOG.warn("Static file compression cache is enabled, but resource versioning is not enabled. This can lead " + "to unversioned resources being cached in the filesystem. If these resources are updated, you will " + "not see the changes because of the unversioned file cache of the same name. It is recommended to " + "not use static file compression cache when resource versioning is not enabled. Static file " + "compression cache can be controlled with the 'filter.compression.allow.static.file.cache' property."); } initialized = true; } }
@Bean public AcmIntegrationProperties acmIntegrationProperties() { AcmIntegrationProperties acmIntegrationProperties = new AcmIntegrationProperties(); String applicationName = environment.getProperty("spring.application.name"); String applicationGroup = environment.getProperty("spring.application.group"); Assert.isTrue(!StringUtils.isEmpty(applicationName), "'spring.application.name' must be configured in bootstrap.properties or bootstrap.yml/yaml..."); acmIntegrationProperties.setApplicationName(applicationName); acmIntegrationProperties.setApplicationGroup(applicationGroup); acmIntegrationProperties.setActiveProfiles(environment.getActiveProfiles()); acmIntegrationProperties.setAcmProperties(acmProperties); return acmIntegrationProperties; }
addPropertySourceIfNeeded( c -> PROPERTIES_TO_MAP.apply( yamlParserGenerator(environment.getActiveProfiles()).apply(c) ), content,
HttpServletResponse response = (HttpServletResponse) servletResponse; checkOutput: { if (ArrayUtils.isNotEmpty(environment.getActiveProfiles()) || useWhileInDefaultEnvironment) { String path = getResourcePath(request); String gzipPath = path + ".gz";
public ConfigClientProperties(Environment environment) { String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } this.setProfile(StringUtils.arrayToCommaDelimitedString(profiles)); }
protected void addKeystoneProvider() { boolean keystoneProfile = Arrays.asList(environment.getActiveProfiles()).contains(OriginKeys.KEYSTONE); if (keystoneConfig != null || keystoneProfile) { boolean active = keystoneProfile && keystoneConfig!=null; IdentityProvider provider = new IdentityProvider(); provider.setOriginKey(OriginKeys.KEYSTONE); provider.setType(OriginKeys.KEYSTONE); provider.setName("UAA Keystone Provider"); provider.setActive(active); provider.setConfig(getKeystoneDefinition(keystoneConfig)); providers.add(new IdentityProviderWrapper(provider)); } }
@Override public PropertySource<?> locate(Environment env) { ConfigService configService = nacosConfigProperties.configServiceInstance(); if (null == configService) { log.warn("no instance of config service found, can't load config from nacos"); return null; } long timeout = nacosConfigProperties.getTimeout(); nacosPropertySourceBuilder = new NacosPropertySourceBuilder(configService, timeout); String name = nacosConfigProperties.getName(); String nacosGroup = nacosConfigProperties.getGroup(); String dataIdPrefix = nacosConfigProperties.getPrefix(); if (StringUtils.isEmpty(dataIdPrefix)) { dataIdPrefix = name; } if (StringUtils.isEmpty(dataIdPrefix)) { dataIdPrefix = env.getProperty("spring.application.name"); } List<String> profiles = Arrays.asList(env.getActiveProfiles()); nacosConfigProperties.setActiveProfiles(profiles.toArray(new String[0])); String fileExtension = nacosConfigProperties.getFileExtension(); CompositePropertySource composite = new CompositePropertySource( NACOS_PROPERTY_SOURCE_NAME); loadSharedConfiguration(composite); loadExtConfiguration(composite); loadApplicationConfiguration(composite, nacosGroup, dataIdPrefix, fileExtension); return composite; }
protected void addLdapProvider() { boolean ldapProfile = Arrays.asList(environment.getActiveProfiles()).contains(LDAP); //the LDAP provider has to be there //and we activate, deactivate based on the `ldap` profile presence IdentityProvider provider = new IdentityProvider(); provider.setActive(ldapProfile); provider.setOriginKey(LDAP); provider.setType(LDAP); provider.setName("UAA LDAP Provider"); Map<String,Object> ldap = new HashMap<>(); ldap.put(LdapIdentityProviderDefinition.LDAP, ldapConfig); LdapIdentityProviderDefinition json = getLdapConfigAsDefinition(ldap); provider.setConfig(json); provider.setActive(ldapProfile && json.isConfigured()); /* LDAP is a bit tricky. We have a Flyway conversion (2.0.2) that always adds an LDAP provider. So we have to assume that if LDAP config == null, then we should override it */ boolean override = ldapConfig == null || ldapConfig.get("override") == null ? true : (boolean) ldapConfig.get("override"); if (!override) { IdentityProvider existing = getProviderByOrigin(LDAP, IdentityZone.getUaa().getId()); override = existing == null || existing.getConfig() == null; } IdentityProviderWrapper wrapper = new IdentityProviderWrapper(provider); wrapper.setOverride(override); providers.add(wrapper); }
@Bean(initMethod = "init", destroyMethod = "close") public DruidDataSource dataSource() throws SQLException { if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) { System.out.println("Your database connection pool configuration is incorrect!" + " Please check your Spring profile, current profiles are:" + Arrays.toString(environment.getActiveProfiles())); throw new ApplicationContextException( "Database connection pool is not configured correctly"); } DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name")); druidDataSource.setUrl(propertyResolver.getProperty("url")); druidDataSource.setUsername(propertyResolver.getProperty("username")); druidDataSource.setPassword(propertyResolver.getProperty("password")); druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize"))); druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle"))); druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive"))); druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait"))); druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis"))); druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis"))); druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery")); druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle"))); druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow"))); druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn"))); druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements"))); druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize"))); druidDataSource.setFilters(propertyResolver.getProperty("filters")); return druidDataSource; }
@Bean(initMethod = "init", destroyMethod = "close") public DruidDataSource dataSource() throws SQLException { if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) { System.out.println("Your database connection pool configuration is incorrect!" + " Please check your Spring profile, current profiles are:" + Arrays.toString(environment.getActiveProfiles())); throw new ApplicationContextException( "Database connection pool is not configured correctly"); } DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name")); druidDataSource.setUrl(propertyResolver.getProperty("url")); druidDataSource.setUsername(propertyResolver.getProperty("username")); druidDataSource.setPassword(propertyResolver.getProperty("password")); druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize"))); druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle"))); druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive"))); druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait"))); druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis"))); druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis"))); druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery")); druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle"))); druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow"))); druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn"))); druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements"))); druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize"))); druidDataSource.setFilters(propertyResolver.getProperty("filters")); return druidDataSource; }
private boolean hasKubernetesProfile(Environment environment) { for (String activeProfile : environment.getActiveProfiles()) { if (KUBERNETES_PROFILE.equalsIgnoreCase(activeProfile)) { return true; } } return false; }
@Bean public StormCLIWrapper stormCLIClientWrapper() { if (Arrays.asList(environment.getActiveProfiles()).contains(DOCKER_PROFILE)) { return new DockerStormCLIWrapper(environment); } else { return new StormCLIWrapper(); } } }
private EnvironmentEntryDescriptor getEnvironmentEntryDescriptor( String propertyName) { Map<String, PropertyValueDescriptor> descriptors = getPropertySourceDescriptors( propertyName); PropertySummaryDescriptor summary = getPropertySummaryDescriptor(descriptors); return new EnvironmentEntryDescriptor(summary, Arrays.asList(this.environment.getActiveProfiles()), toPropertySourceDescriptors(descriptors)); }