/** Constructor. */ public ValidateUsernamePasswordAgainstJAAS() { // For compatibility with V2. loginConfigurations = Collections.singletonList(new Pair<String,Subject>("ShibUserPassAuth", null)); }
/** {@inheritDoc} */ @Override @Nullable public List<String> apply(@Nullable final Pair<ProfileRequestContext, List<String>> input) { if (input == null || input.getFirst() == null || input.getSecond() == null) { return null; } try { final ProfileRequestContext profileRequestContext = input.getFirst(); final List<String> storageKeys = input.getSecond(); final Map<String, Long> keyToCounterMap = getStorageKeyCounters(profileRequestContext, storageKeys); final Comparator<String> comparator = new CounterStorageKeyComparator(storageKeys, keyToCounterMap); Collections.sort(storageKeys, comparator); return storageKeys; } catch (final ConstraintViolationException e) { log.warn("Unable to apply counter storage key function", e); return input.getSecond(); } }
/** {@inheritDoc} */ @Override public Pair<Long, StorageRecord> read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Positive final long version) throws IOException { Constraint.isGreaterThan(0, version, "Version must be positive"); final StorageRecord record = read(context, key); if (record == null) { return new Pair<>(); } final Pair<Long, StorageRecord> result = new Pair<>(record.getVersion(), null); if (version != record.getVersion()) { // Only set the record if it's not the same as the version requested result.setSecond(record); } return result; }
/** * Set the JAAS application name(s) to use, along with an optional collection of custom principals to * apply to the result. * * @param configs list of JAAS application names and custom principals to use */ public void setLoginConfigurations(@Nullable final Collection<Pair<String,Collection<Principal>>> configs) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); if (configs != null) { loginConfigurations = new ArrayList<>(configs.size()); for (final Pair<String,Collection<Principal>> config : configs) { final String trimmed = StringSupport.trimOrNull(config.getFirst()); if (trimmed != null) { if (config.getSecond() == null || config.getSecond().isEmpty()) { loginConfigurations.add(new Pair<String,Subject>(trimmed, null)); } else { final Subject subject = new Subject(); subject.getPrincipals().addAll(config.getSecond()); loginConfigurations.add(new Pair<String,Subject>(trimmed, subject)); } } } } }
/** {@inheritDoc} */ @Override @Nullable public String apply(@Nullable final Pair<ProfileRequestContext, HttpServletRequest> input) { if (input == null) { log.debug("Input Pair<ProfileRequestContext,HttpServletRequest> was null"); return null; } if (input.getSecond() != null) { final HttpServletRequest request = input.getSecond(); return String.format("https://%s:%s%s", request.getServerName(), LibertyConstants.DEFAULT_SSOS_ENDPOINT_URL_PORT, request.getServletContext().getContextPath() + LibertyConstants.DEFAULT_SSOS_ENDPOINT_URL_RELATIVE_PATH); } else { log.debug("Input HttpServletRequest was null"); return null; } } }
/** {@inheritDoc} */ @Override protected void doInitialize() throws ComponentInitializationException { super.doInitialize(); if (pipelineAndStrategies.isEmpty()) { throw new ComponentInitializationException( "Pipeline and selection strategy collection can not be null or empty"); } Pipeline<T> pipeline; for (Pair<Pipeline<T>, Predicate<Item<T>>> pipelineAndStrategy : pipelineAndStrategies) { pipeline = pipelineAndStrategy.getFirst(); if (!pipeline.isInitialized()) { pipeline.initialize(); } } } }
/** * Sets the pipeline and item selection strategies used to demultiplex item collections within this stage. * * @param passes pipeline and item selection strategies used to demultiplex item collections within this stage */ public synchronized void setPipelineAndSelectionStrategies( @Nonnull @NonnullElements final List<Pair<Pipeline<T>, Predicate<Item<T>>>> passes) { ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); if (passes == null || passes.isEmpty()) { pipelineAndStrategies = Collections.emptyList(); return; } final Builder<Pair<Pipeline<T>, Predicate<Item<T>>>> checkedPasses = new Builder<>(); for (Pair<Pipeline<T>, Predicate<Item<T>>> pass : passes) { Constraint.isNotNull(pass.getFirst(), "Pipeline can not be null"); Constraint.isNotNull(pass.getSecond(), "Predicate can not be null"); checkedPasses.add(new Pair<>(pass)); } pipelineAndStrategies = checkedPasses.build(); }
/** {@inheritDoc} */ @Override @Nullable public StorageRecord read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { return readImpl(context, key, null).getSecond(); }
setDirty(!keyStrategy.getDefaultKey().getFirst().equals(keyAliasUsed.toString())); } catch (final KeyException e) { log.error("Exception while accessing default key during stale key detection", e);
/** {@inheritDoc} */ @Override @Nullable public List<String> apply(@Nullable final Pair<ProfileRequestContext, List<String>> input) { if (input == null || input.getFirst() == null || input.getSecond() == null) { return null; } try { final ProfileRequestContext profileRequestContext = input.getFirst(); final List<String> storageKeys = input.getSecond(); final Map<String, Long> keyToCounterMap = getStorageKeyCounters(profileRequestContext, storageKeys); final Comparator<String> comparator = new CounterStorageKeyComparator(storageKeys, keyToCounterMap); Collections.sort(storageKeys, comparator); return storageKeys; } catch (final ConstraintViolationException e) { log.warn("Unable to apply counter storage key function", e); return input.getSecond(); } }
/** {@inheritDoc} */ public Iterable<Pair<String, T>> listAll() throws IOException { ArrayList<Pair<String,T>> list = new ArrayList<>(); for (String key : listKeys()) { list.add(new Pair<>(key, load(key))); } return list; }
/** * A collection of regular expression and replacement pairs. * * @param newTransforms collection of replacement transforms */ public void setTransforms(@Nonnull @NonnullElements final Collection<Pair<String,String>> newTransforms) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotNull(newTransforms, "Transforms collection cannot be null"); transforms = new ArrayList(); for (final Pair<String,String> p : newTransforms) { final Pattern pattern = Pattern.compile(StringSupport.trimOrNull(p.getFirst())); transforms.add(new Pair(pattern, Constraint.isNotNull( StringSupport.trimOrNull(p.getSecond()), "Replacement expression cannot be null"))); } }
/** {@inheritDoc} */ @Override @Nullable public StorageRecord read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { return readImpl(context, key, null).getSecond(); }
if (!keyStrategy.getDefaultKey().getFirst().equals(keyAliasUsed.toString())) { storageObject.setDirty(true);
/** * Apply configured transforms to input identifier. * * @param id the identifier to transform * @return transformed value */ @Nullable protected String decode(@Nonnull @NotEmpty final String id) { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); String s = id; for (final Pair<Pattern,String> p : transforms) { final Matcher m = p.getFirst().matcher(s); log.debug("Applying replacement expression '{}' against input '{}'", p.getFirst().pattern(), s); s = m.replaceAll(p.getSecond()); log.debug("Result of replacement is '{}'", s); } return s; }
/** {@inheritDoc} */ public Iterable<Pair<String, T>> listAll() throws IOException { ArrayList<Pair<String,T>> list = new ArrayList<>(); for (String key : listKeys()) { list.add(new Pair<>(key, load(key))); } return list; }
/** * A collection of regular expression and replacement pairs. * * @param newTransforms collection of replacement transforms */ public void setTransforms(@Nonnull @NonnullElements final Collection<Pair<String, String>> newTransforms) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotNull(newTransforms, "Transforms collection cannot be null"); transforms = new ArrayList(); for (final Pair<String,String> p : newTransforms) { final Pattern pattern = Pattern.compile(StringSupport.trimOrNull(p.getFirst())); transforms.add(new Pair(pattern, Constraint.isNotNull( StringSupport.trimOrNull(p.getSecond()), "Replacement expression cannot be null"))); } }
/** * Conditionally starts one or more timers based on the supplied object identifier. * * <p>The configured state of the context is used to determine whether, and which, * timers to start, further influenced by the runtime state of the system with regard * to enabling of metrics.</p> * * @param objectId ID of the object being timed */ public void start(@Nonnull @NotEmpty final String objectId) { for (final Pair<String,String> timer : timerMap.get(objectId)) { if (timer != null) { timerContextMap.put(timer.getSecond(), MetricsSupport.getMetricRegistry().timer(timer.getFirst()).time()); } } }
/** * Resolve and store the effective Liberty SSOS endpoint URL to use. * * @param profileRequestContext the current request context * */ //CheckStyle: ReturnCount OFF private void resolveLibertySSOSEndpointURL(final ProfileRequestContext profileRequestContext) { if (libertySSOSEndpointURL != null) { log.debug("Using explicitly configured Liberty SSOS endpoint URL: {}", libertySSOSEndpointURL); return; } if (libertySSOSEndpointURLLookupStrategy != null) { libertySSOSEndpointURL = libertySSOSEndpointURLLookupStrategy.apply( new Pair<>(profileRequestContext, getHttpServletRequest())); if (libertySSOSEndpointURL != null) { log.debug("Using Liberty SSOS endpoint URL resolved via strategy: {}", libertySSOSEndpointURL); return; } else { log.debug("Liberty SSOS endpoint URL strategy was unable to resolve a value"); } } log.debug("No effective Liberty SSOS endpoint URL could be determined"); } //CheckStyle: ReturnCount ON
/** * A collection of regular expression and replacement pairs. * * @param newTransforms collection of replacement transforms */ public void setTransforms(@Nonnull @NonnullElements final Collection<Pair<String, String>> newTransforms) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotNull(newTransforms, "Transforms collection cannot be null"); transforms = new ArrayList(); for (final Pair<String,String> p : newTransforms) { final Pattern pattern = Pattern.compile(StringSupport.trimOrNull(p.getFirst())); transforms.add(new Pair(pattern, Constraint.isNotNull( StringSupport.trimOrNull(p.getSecond()), "Replacement expression cannot be null"))); } }