/** * Produce error view model and view. * * @param e the e * @return the model and view */ public static ModelAndView produceErrorView(final Exception e) { return new ModelAndView(OAuth20Constants.ERROR_VIEW, CollectionUtils.wrap("rootCauseException", e)); }
/** * Instantiates a new argument extractor. * * @param serviceFactory the service factory */ public DefaultArgumentExtractor(final ServiceFactory<? extends WebApplicationService> serviceFactory) { super(CollectionUtils.wrapList(serviceFactory)); }
public RejectResultCodePasswordPolicyHandlingStrategy() { this(CollectionUtils.wrapSet(DEFAULT_REJECTED_RESULT_CODE)); }
/** * As multi value map. * * @param key1 the key 1 * @param value1 the value 1 * @param key2 the key 2 * @param value2 the value 2 * @return the multi value map */ public static MultiValueMap asMultiValueMap(final String key1, final Object value1, final String key2, final Object value2) { val wrap = (Map) wrap(key1, wrapList(value1), key2, wrapList(value2)); return org.springframework.util.CollectionUtils.toMultiValueMap(wrap); }
@Override public boolean hasAttribute(final String name, final Predicate<Object> predicate) { if (this.attributes.containsKey(name)) { val value = this.attributes.get(name); val valueCol = CollectionUtils.toCollection(value); return valueCol.stream().anyMatch(predicate); } return false; }
@Override public void authorize(final HttpServletRequest request, final Service service, final Assertion assertion) { val registeredService = this.servicesManager.findServiceBy(service); RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService); LOGGER.debug("Evaluating service [{}] for delegated authentication policy", service); val policy = registeredService.getAccessStrategy().getDelegatedAuthenticationPolicy(); if (policy != null) { val attributes = assertion.getPrimaryAuthentication().getAttributes(); if (attributes.containsKey(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME)) { val clientNameAttr = attributes.get(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME); val value = CollectionUtils.firstElement(clientNameAttr); if (value.isPresent()) { val client = value.get().toString(); LOGGER.debug("Evaluating delegated authentication policy [{}] for client [{}] and service [{}]", policy, client, registeredService); val context = AuditableContext.builder() .registeredService(registeredService) .properties(CollectionUtils.wrap(Client.class.getSimpleName(), client)) .build(); val result = delegatedAuthenticationPolicyEnforcer.execute(context); result.throwExceptionIfNeeded(); } } } } }
val convertedAttributes = new LinkedHashMap<String, Object>(); attributes.forEach((key, attrValue) -> { val values = CollectionUtils.toCollection(attrValue, ArrayList.class); LOGGER.debug("Found attribute [{}] with value(s) [{}]", key, values); if (values.size() == 1) { val value = CollectionUtils.firstElement(values).get(); convertedAttributes.put(key, value); } else { val values = result.get(); if (!values.isEmpty()) { principalId = CollectionUtils.firstElement(values).get().toString(); LOGGER.debug("Found principal id attribute value [{}] and removed it from the collection of attributes", principalId);
private static Optional<Object> getFirstAttributeByName(final Principal principal, final String attribute) { val value = principal.getAttributes().get(attribute); return CollectionUtils.firstElement(value); }
private static <T> void addToCollection(final Collection<T> list, final T[] source) { if (source != null) { Arrays.stream(source).forEach(s -> { val col = toCollection(s); list.addAll((Collection) col); }); } } }
if (attributes.containsKey(idAttribute)) { LOGGER.debug("Extracting principal id from attribute [{}]", this.configuration.getIdentityAttribute()); val idAttributeAsList = CollectionUtils.toCollection(attributes.get(this.configuration.getIdentityAttribute())); if (idAttributeAsList.size() > 1) { LOGGER.warn("Found multiple values for id attribute [{}].", idAttribute); val result = CollectionUtils.firstElement(idAttributeAsList); if (result.isPresent()) { val principalId = result.get().toString();
/** * Get alternate principal if alternate attribute configured. * @param certificate X509 Certificate of user * @return principal using alternate attribute or null if none configured */ protected String getAlternatePrincipal(final X509Certificate certificate) { if (alternatePrincipalAttribute == null) { return null; } val attributes = extractPersonAttributes(certificate); val attribute = attributes.get(alternatePrincipalAttribute); if (attribute == null) { LOGGER.debug("Attempt to get alternate principal with attribute {} was unsuccessful.", alternatePrincipalAttribute); return null; } val optionalAttribute = CollectionUtils.firstElement(attribute); if (optionalAttribute.isEmpty()) { LOGGER.debug("Alternate attribute list for {} was empty.", alternatePrincipalAttribute); return null; } val alternatePrincipal = optionalAttribute.get().toString(); if (StringUtils.isNotEmpty(alternatePrincipal)) { LOGGER.debug("Using alternate principal attribute {} ", alternatePrincipal); return alternatePrincipal; } LOGGER.debug("Returning null principal id..."); return null; }
/** * Produce error view model and view. * * @param e the e * @return the model and view */ public static ModelAndView produceErrorView(final Exception e) { return new ModelAndView(CasWebflowConstants.VIEW_ID_SERVICE_ERROR, CollectionUtils.wrap("rootCauseException", e)); }
@Override public X509Certificate[] getAcceptedIssuers() { val certificates = new ArrayList<X509Certificate>(); this.trustManagers.forEach(trustManager -> certificates.addAll(CollectionUtils.wrapList(trustManager.getAcceptedIssuers()))); return certificates.toArray(X509Certificate[]::new); } }
protected Collection<String> getCandidateStatesForMultifactorAuthentication() { return CollectionUtils.wrapSet(CasWebflowConstants.STATE_ID_REAL_SUBMIT); } }
/** * Converts the provided object into a collection * and return the first element, or empty. * * @param obj the obj * @return the optional */ public static Optional<Object> firstElement(final Object obj) { val object = CollectionUtils.toCollection(obj); if (object.isEmpty()) { return Optional.empty(); } return Optional.of(object.iterator().next()); }
val attributes = authentication.getAttributes(); val ctxAttr = attributes.get(this.authenticationContextAttribute); val contexts = CollectionUtils.toCollection(ctxAttr); LOGGER.trace("Attempting to match requested authentication context [{}] against [{}]", requestedContext, contexts); val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext); val isBypass = Boolean.class.cast(CollectionUtils.firstElement(attributes.get(MultifactorAuthenticationProviderBypass.AUTHENTICATION_ATTRIBUTE_BYPASS_MFA)).get()); val bypassedId = CollectionUtils.firstElement(attributes.get(MultifactorAuthenticationProviderBypass.AUTHENTICATION_ATTRIBUTE_BYPASS_MFA_PROVIDER)).get().toString(); LOGGER.trace("Found multifactor authentication bypass attributes for provider [{}]", bypassedId); if (isBypass && StringUtils.equals(bypassedId, requestedContext)) {
@Override public String generate(final Principal principal, final Service service) { val attributes = principal.getAttributes(); LOGGER.debug("Found principal attributes [{}] to use when generating persistent identifiers", attributes); val principalId = FunctionUtils.doIf( StringUtils.isNotBlank(this.attribute) && attributes.containsKey(this.attribute), () -> { val attributeValue = attributes.get(this.attribute); LOGGER.debug("Using attribute [{}] to establish principal id", this.attribute); return CollectionUtils.firstElement(attributeValue).get().toString(); }, () -> { LOGGER.debug("Using principal id [{}] to generate persistent identifier", principal.getId()); return principal.getId(); } ).get(); return generate(principalId, service != null ? service.getId() : null); }
@Override protected Collection<X509CRL> getCRLs(final X509Certificate cert) { val principal = cert.getIssuerX500Principal(); if (this.crlIssuerMap.containsKey(principal)) { return CollectionUtils.wrap(this.crlIssuerMap.get(principal)); } LOGGER.warn("Could not locate CRL for issuer principal [{}]", principal); return new ArrayList<>(0); }
/** * sets the signing certs. * * @param signingCertificateResources a list of certificate files to read in. */ public void setSigningCertificateResources(final Resource... signingCertificateResources) { this.signingCertificateResources = CollectionUtils.wrapList(signingCertificateResources); createSigningWallet(this.signingCertificateResources); }
public ByCredentialTypeAuthenticationHandlerResolver(final Class<? extends Credential>... credentials) { this(CollectionUtils.wrapSet(credentials)); }