本文整理匯總了Java中org.apereo.cas.util.CollectionUtils類的典型用法代碼示例。如果您正苦於以下問題:Java CollectionUtils類的具體用法?Java CollectionUtils怎麽用?Java CollectionUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CollectionUtils類屬於org.apereo.cas.util包,在下文中一共展示了CollectionUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: equals
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof Authentication)) {
return false;
}
if (obj == this) {
return true;
}
final Authentication other = (Authentication) obj;
final EqualsBuilder builder = new EqualsBuilder();
builder.append(this.principal, other.getPrincipal());
builder.append(this.credentials, other.getCredentials());
builder.append(this.successes, other.getSuccesses());
builder.append(this.authenticationDate, other.getAuthenticationDate());
builder.append(CollectionUtils.wrap(this.attributes), other.getAttributes());
builder.append(CollectionUtils.wrap(this.failures), other.getFailures());
return builder.isEquals();
}
示例2: getSatisfiedAuthenticationProviders
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
private Collection<MultifactorAuthenticationProvider> getSatisfiedAuthenticationProviders(final Authentication authentication,
final Collection<MultifactorAuthenticationProvider> providers) {
final Collection<Object> contexts = CollectionUtils.toCollection(
authentication.getAttributes().get(this.authenticationContextAttribute));
if (contexts == null || contexts.isEmpty()) {
LOGGER.debug("No authentication context could be determined based on authentication attribute [{}]",
this.authenticationContextAttribute);
return null;
}
contexts.stream().forEach(context ->
providers.removeIf(provider -> !provider.getId().equals(context))
);
LOGGER.debug("Found [{}] providers that may satisfy the context", providers.size());
return providers;
}
示例3: getPersonAttributesFromMultivaluedAttributes
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
public Map<String, List<Object>> getPersonAttributesFromMultivaluedAttributes(final Map<String, List<Object>> attributes) {
if (attributes.containsKey("username")) {
final List<Object> username = attributes.get("username");
if (!username.isEmpty()) {
final Map<String, List<Object>> results = new HashMap<>();
final Map<String, Object> attrs = getAttributesForUser(username.get(0).toString());
LOGGER.debug("Groovy-based attributes found are [{}]", attrs);
attrs.forEach((k, v) -> {
final List<Object> values = new ArrayList<>(CollectionUtils.toCollection(v));
LOGGER.debug("Adding Groovy-based attribute [{}] with value(s) [{}]", k, values);
results.put(k, values);
});
return results;
}
}
return new HashMap<>();
}
示例4: equals
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof DefaultHandlerResult)) {
return false;
}
if (obj == this) {
return true;
}
final DefaultHandlerResult other = (DefaultHandlerResult) obj;
final EqualsBuilder builder = new EqualsBuilder();
builder.append(this.handlerName, other.handlerName);
builder.append(this.credentialMetaData, other.credentialMetaData);
builder.append(this.principal, other.principal);
builder.append(CollectionUtils.wrap(this.warnings), CollectionUtils.wrap(other.warnings));
return builder.isEquals();
}
示例5: verifyChainingResolverOverwrite
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Test
public void verifyChainingResolverOverwrite() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Map<String, Object> attributes = new HashMap<>();
attributes.put("cn", "changedCN");
attributes.put(ATTR_1, "value1");
final Principal p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(),
CoreAuthenticationTestUtils.getPrincipal(CoreAuthenticationTestUtils.CONST_USERNAME, attributes),
new SimpleTestUsernamePasswordAuthenticationHandler());
assertEquals(p.getAttributes().size(), CoreAuthenticationTestUtils.getAttributeRepository().getPossibleUserAttributeNames().size() + 1);
assertTrue(p.getAttributes().containsKey(ATTR_1));
assertTrue(p.getAttributes().containsKey("cn"));
assertTrue(CollectionUtils.toCollection(p.getAttributes().get("cn")).contains("changedCN"));
}
示例6: shouldApplyRegisteredServiceMultifactorPolicy
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
private static boolean shouldApplyRegisteredServiceMultifactorPolicy(final RegisteredServiceMultifactorPolicy policy, final Principal principal) {
final String attrName = policy.getPrincipalAttributeNameTrigger();
final String attrValue = policy.getPrincipalAttributeValueToMatch();
// Principal attribute name and/or value is not defined
if (!StringUtils.hasText(attrName) || !StringUtils.hasText(attrValue)) {
return true;
}
// no Principal, we should enforce policy
if (principal == null) {
return true;
}
// check to see if any of the specified attributes match the attrValue pattern
final Predicate<String> attrValuePredicate = Pattern.compile(attrValue).asPredicate();
return StreamSupport.stream(ATTR_NAMES.split(attrName).spliterator(), false)
.map(principal.getAttributes()::get)
.filter(Objects::nonNull)
.map(CollectionUtils::toCollection)
.flatMap(Set::stream)
.filter(String.class::isInstance)
.map(String.class::cast)
.anyMatch(attrValuePredicate);
}
示例7: common
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
private boolean common(final Map<String, Object> principalAttributes, final Map<String, Set<String>> attributes) {
final Set<String> difference = attributes.keySet().stream()
.filter(a -> principalAttributes.keySet().contains(a))
.collect(Collectors.toSet());
if (this.requireAllAttributes && difference.size() < attributes.size()) {
return false;
}
return difference.stream().anyMatch(key -> {
final Set<String> values = attributes.get(key);
final Set<Object> availableValues = CollectionUtils.toCollection(principalAttributes.get(key));
final Pattern pattern = RegexUtils.concatenate(values, this.caseInsensitive);
if (pattern != RegexUtils.MATCH_NOTHING_PATTERN) {
return availableValues.stream().map(Object::toString).anyMatch(pattern.asPredicate());
}
return availableValues.stream().anyMatch(values::contains);
});
}
示例8: buildConsentDecision
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
/**
* Build consent decision consent decision.
*
* @param service the service
* @param registeredService the registered service
* @param authentication the authentication
* @return the consent decision
*/
public static ConsentDecision buildConsentDecision(final Service service,
final RegisteredService registeredService,
final Authentication authentication) {
final ConsentDecision consent = new ConsentDecision();
consent.setPrincipal(authentication.getPrincipal().getId());
consent.setService(service.getId());
final Map<String, Object> attributes =
registeredService.getAttributeReleasePolicy().getAttributes(authentication.getPrincipal(),
service, registeredService);
final String names = DigestUtils.sha512(attributes.keySet().stream().collect(Collectors.joining("|")));
consent.setAttributeNames(names);
final String values = DigestUtils.sha512(attributes.values().stream()
.map(CollectionUtils::toCollection)
.map(c -> {
final String value = c.stream().map(Object::toString).collect(Collectors.joining());
return value;
})
.collect(Collectors.joining("|")));
consent.setAttributeValues(values);
consent.setDate(LocalDateTime.now());
return consent;
}
示例9: putCasResponseAttributesIntoModel
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
/**
* Put cas response attributes into model.
*
* @param model the model
* @param attributes the attributes
* @param registeredService the registered service
*/
protected void putCasResponseAttributesIntoModel(final Map<String, Object> model,
final Map<String, Object> attributes,
final RegisteredService registeredService) {
LOGGER.debug("Beginning to encode attributes for the response");
final Map<String, Object> encodedAttributes = this.protocolAttributeEncoder.encodeAttributes(attributes, registeredService);
LOGGER.debug("Encoded attributes for the response are [{}]", encodedAttributes);
super.putIntoModel(model, CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES, encodedAttributes);
final List<String> formattedAttributes = new ArrayList<>(encodedAttributes.size());
LOGGER.debug("Beginning to format/render attributes for the response");
encodedAttributes.forEach((k, v) -> {
final Set<Object> values = CollectionUtils.toCollection(v);
values.forEach(value -> {
final String fmt = new StringBuilder()
.append("<cas:".concat(k).concat(">"))
.append(StringEscapeUtils.escapeXml10(value.toString().trim()))
.append("</cas:".concat(k).concat(">"))
.toString();
LOGGER.debug("Formatted attribute for the response: [{}]", fmt);
formattedAttributes.add(fmt);
});
});
super.putIntoModel(model, CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_FORMATTED_ATTRIBUTES, formattedAttributes);
}
示例10: mergeAttribute
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
public AuthenticationBuilder mergeAttribute(final String key, final Object value) {
final Object currentValue = this.attributes.get(key);
if (currentValue == null) {
return addAttribute(key, value);
}
final Collection collection = CollectionUtils.toCollection(currentValue);
collection.addAll(CollectionUtils.toCollection(value));
return addAttribute(key, collection);
}
示例11: hasAttribute
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
public boolean hasAttribute(final String name, final Predicate<Object> predicate) {
if (this.attributes.containsKey(name)) {
final Object value = this.attributes.get(name);
final Collection valueCol = CollectionUtils.toCollection(value);
return valueCol.stream().filter(predicate).count() > 0;
}
return false;
}
示例12: sms
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
/**
* Sms.
*
* @param principal the principal
* @param attribute the attribute
* @param text the text
* @param from the from
* @return the boolean
*/
public boolean sms(final Principal principal,
final String attribute,
final String text, final String from) {
if (StringUtils.isNotBlank(attribute) && principal.getAttributes().containsKey(attribute) && isSmsSenderDefined()) {
final String to = CollectionUtils.toCollection(principal.getAttributes().get(attribute)).iterator().next().toString();
return sms(from, to, text);
}
return false;
}
示例13: verifyPatternFilter
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Test
public void verifyPatternFilter() {
this.filter.setPatterns(Collections.singletonMap("memberOf", "^m"));
final Map<String, Object> attrs = this.filter.filter(this.givenAttributesMap);
assertEquals(attrs.size(), this.givenAttributesMap.size());
assertEquals(CollectionUtils.toCollection(attrs.get("memberOf")).size(), 2);
}
示例14: verifyPatternFilterExcludeUnmatched
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Test
public void verifyPatternFilterExcludeUnmatched() {
this.filter.setPatterns(Collections.singletonMap("memberOf", "^m"));
this.filter.setExcludeUnmappedAttributes(true);
final Map<String, Object> attrs = this.filter.filter(this.givenAttributesMap);
assertEquals(attrs.size(), 1);
assertEquals(CollectionUtils.toCollection(attrs.get("memberOf")).size(), 2);
}
示例15: prepareResponse
import org.apereo.cas.util.CollectionUtils; //導入依賴的package包/類
@Override
protected void prepareResponse(final Response response, final Map<String, Object> model) {
final ZonedDateTime issuedAt = DateTimeUtils.zonedDateTimeOf(response.getIssueInstant());
final Service service = getAssertionFrom(model).getService();
LOGGER.debug("Preparing SAML response for service [{}]", service);
final Authentication authentication = getPrimaryAuthenticationFrom(model);
final Collection<Object> authnMethods = CollectionUtils.toCollection(authentication.getAttributes()
.get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD));
LOGGER.debug("Authentication methods found are [{}]", authnMethods);
final Principal principal = getPrincipal(model);
final AuthenticationStatement authnStatement = this.samlObjectBuilder.newAuthenticationStatement(
authentication.getAuthenticationDate(), authnMethods, principal.getId());
LOGGER.debug("Built authentication statement for [{}] dated at [{}]", principal, authentication.getAuthenticationDate());
final Assertion assertion = this.samlObjectBuilder.newAssertion(authnStatement, this.issuer, issuedAt,
this.samlObjectBuilder.generateSecureRandomId());
LOGGER.debug("Built assertion for issuer [{}] dated at [{}]", this.issuer, issuedAt);
final Conditions conditions = this.samlObjectBuilder.newConditions(issuedAt, service.getId(), this.skewAllowance);
assertion.setConditions(conditions);
LOGGER.debug("Built assertion conditions for issuer [{}] and service [{}] ", this.issuer, service.getId());
final Subject subject = this.samlObjectBuilder.newSubject(principal.getId());
LOGGER.debug("Built subject for principal [{}]", principal);
final Map<String, Object> attributesToSend = prepareSamlAttributes(model, service);
LOGGER.debug("Authentication statement shall include these attributes [{}]", attributesToSend);
if (!attributesToSend.isEmpty()) {
assertion.getAttributeStatements().add(this.samlObjectBuilder.newAttributeStatement(
subject, attributesToSend, this.defaultAttributeNamespace));
}
response.setStatus(this.samlObjectBuilder.newStatus(StatusCode.SUCCESS, null));
LOGGER.debug("Set response status code to [{}]", response.getStatus());
response.getAssertions().add(assertion);
}