private boolean allFeaturesAreEnabled(String[] featureKeys) { for (String featureKey : featureKeys) { if (!darkFeatureManager.isFeatureEnabledForCurrentUser(featureKey)) { return false; } } return true; } }
@Override public boolean isEnabled() { return this.darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_PROGRAMMATIC_ANALYTICS); } }
@Override public boolean isEnabled() { return featureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_PROGRAMMATIC_ANALYTICS); } }
public boolean isFeatureEnabledForCurrentUser(String key) { return darkFeatureManager.isFeatureEnabledForCurrentUser(key); } }
private boolean impersonationIsEnabled() { return !darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_DISABLE_OAUTH2_IMPERSONATION); }
private boolean impersonationIsEnabled() { return !darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_DISABLED_OAUTH2_IMPERSONATION); }
private boolean isEventAlwaysWhitelisted(final String eventName, final boolean isOnDemand) { // If the dark feature is enabled, whitelist "grow"-prefixed events automatically, even in BTF if (autoWhitelistGrow == null) { autoWhitelistGrow = darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_AUTO_WHITELIST_GROW_EVENTS_KEY); } // Always whitelist experiment events final boolean isGrowthExperimentAllowed = (isOnDemand || autoWhitelistGrow) && EXPERIMENT_PATTERN.matcher(eventName).find(); // MAU events are always allowed through and we already hash properties on these events to make them safe. final boolean isMauEvent = isMauEventAvailable.get() && MauEvent.EVENT_NAME.equals(eventName); return isGrowthExperimentAllowed || isMauEvent; }
private <T> T returnOneOf(String methodName, final Supplier<T> settingsSupplier, final Supplier<T> dbTableSupplier, BiFunction<T, T, Boolean> testEquality) { if(fetchOnlyPostgres()) { return dbTableSupplier.get(); } else { final boolean trustDbTable = darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_TRUST_POSTGRES); final T settingsObj = settingsSupplier.get(); final T dbTableObj = dbTableSupplier.get(); validateConsistency(methodName, settingsObj, dbTableObj, testEquality, trustDbTable); return trustDbTable ? dbTableObj : settingsObj; } }
@Test public void systemFeatureEnabledForCurrentUser() { assertFeatureEnabled(darkFeatureManager.isFeatureEnabledForCurrentUser(ENABLED_FEATURE)); }
@Test public void invalidFeatureKeyIsNeverEnabledForCurrentUser() { assertInvalidFeatureDisabled(darkFeatureManager.isFeatureEnabledForCurrentUser(INVALID_FEATURE_KEY)); }
@Test public void systemFeatureDisabledForCurrentUser() { assertFeatureDisabled(darkFeatureManager.isFeatureEnabledForCurrentUser(DISABLED_FEATURE)); }
if (!darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_TRUST_POSTGRES)) { log.info("Starting migration of AddonSettings from PluginSettings to DB Tables");
@Override public void storeAddonSettings(String addonKey, AddonSettings settings, Optional<ShallowConnectAddon> maybeConnectAddonBean) { defaultConnectAddonPersister.storeAddonSettings(addonKey, settings, maybeConnectAddonBean); try { cachingPersister.storeAddonSettings(addonKey, settings, maybeConnectAddonBean); } catch (Exception ex) { if (fetchOnlyPostgres() || darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_TRUST_POSTGRES)) { throw ex; } else { // We don't trust it anyways, so don't make such a big deal out of it. log.error("[HOT-60751]: Failed to store addon setting in the Postgres DB (stored in PluginSetting ok)", ex); } } }
@Override public boolean isEnabled(@Nonnull ApplinksFeatures feature) { checkNotNull(feature, "feature"); if (userManager.getRemoteUserKey() == null) { return false; } if (feature.isSystem()) { // system features - read from system property, otherwise use default value // NOTE: can't use MoreObjects until Confluence upgrades their Guava version Boolean b = toBooleanObject(System.getProperty(ATLASSIAN_DARKFEATURE_PREFIX + feature.featureKey)); return b == null ? feature.getDefaultValue() : b; } else { // standard features - use DarkFeatureManager return darkFeatureManager.isFeatureEnabledForCurrentUser(feature.featureKey); } }
@Override public Optional<Principal> authorize(@Nonnull SessionClaimSet claims) throws IllegalArgumentException, AuthorizationException { if (log.isTraceEnabled()) { log.trace("ConnectAccessTokenAuthorizationServiceImpl.authorize: claimSet is " + claims); } final String impersonatedUserId = claims.getImpersonatedUserId(); final String oauthClientId = claims.getOauthClientId(); if (impersonatedUserId == null) { throw new IllegalStateException("Non impersonation not currently supported via OAuth2. Missing sub claim"); } else { // impersonation case if (darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_OAUTH2_IMPERSONATION)) { log.debug("Allowing add-on '{}' to impersonate the user because the dark feature '{}' is enabled.", getAddonKey(oauthClientId), impersonatedUserId, DARK_FEATURE_OAUTH2_IMPERSONATION); final Optional<ImpersonatedPrincipal<AddonPrincipal>> principalOpt = addonPrincipalService.lookupImpersonatingPrincipal(impersonatedUserId, oauthClientId); if (!principalOpt.isPresent()) { throw new AuthorizationException(String.format( "Add-on '%s' disallowed to impersonate the user because '%s'", getAddonKey(oauthClientId), "no valid active user exists")); } return principalOpt.flatMap(Optional::<Principal>of); } else { log.debug("NOT allowing add-on '{}' to impersonate the user because the dark feature '{}' is disabled.", getAddonKey(oauthClientId), DARK_FEATURE_OAUTH2_IMPERSONATION); return Optional.empty(); } } }
private String createEventDataInternal(String pluginKey, String eventType, Optional<OAuthClient> oauthClient) { final Consumer consumer = checkNotNull(consumerService.getConsumer()); // checkNotNull() otherwise we NPE below ConnectAddonEventDataBuilder dataBuilder = newConnectAddonEventData(); String baseUrl = applicationProperties.getBaseUrl(UrlMode.CANONICAL); dataBuilder.withBaseUrl(nullToEmpty(baseUrl)) .withPluginKey(pluginKey) .withClientKey(nullToEmpty(consumer.getKey())) .withPublicKey(nullToEmpty(RSAKeys.toPemEncoding(consumer.getPublicKey()))) .withPluginsVersion(nullToEmpty(getConnectPluginVersion())) .withServerVersion(nullToEmpty(applicationProperties.getBuildNumber())) .withServiceEntitlementNumber(nullToEmpty(licenseRetriever.getServiceEntitlementNumber(pluginKey))) .withProductType(nullToEmpty(productAccessor.getKey())) .withDescription(nullToEmpty(consumer.getDescription())) .withEventType(eventType); if (darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_OAUTH2_IMPERSONATION)) { dataBuilder.withOauthClient(oauthClient); } else { dataBuilder.withSharedSecret(oauthClient.map(OAuthClient::getSharedSecret).orElse(null)); } ConnectAddonEventData data = dataBuilder.build(); return ConnectModulesGsonFactory.toJson(data); }
private boolean mayProceed(HttpServletRequest request, HttpServletResponse response) { if (darkFeatureName.isPresent() && !darkFeatureManager.isFeatureEnabledForCurrentUser(darkFeatureName.get())) { return true;
private boolean mayProceed(HttpServletRequest request, HttpServletResponse response) { if (disablementFlagName.isPresent() && darkFeatureManager.isFeatureEnabledForCurrentUser(disablementFlagName.get())) { return true;