use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class CasCoreAuthenticationHandlersConfiguration method getParsedUsers.
private Map<String, String> getParsedUsers() {
final Pattern pattern = Pattern.compile("::");
final String usersProperty = casProperties.getAuthn().getAccept().getUsers();
if (StringUtils.isNotBlank(usersProperty) && usersProperty.contains(pattern.pattern())) {
return Stream.of(usersProperty.split(",")).map(pattern::split).collect(Collectors.toMap(userAndPassword -> userAndPassword[0], userAndPassword -> userAndPassword[1]));
}
return new HashMap<>(0);
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class DefaultCloudDirectoryRepository method getUserInfoFromIndexResult.
private Map<String, Object> getUserInfoFromIndexResult(final ListIndexResult indexResult) {
final IndexAttachment attachment = indexResult.getIndexAttachments().stream().findFirst().orElse(null);
if (attachment != null) {
final String identifier = attachment.getObjectIdentifier();
final ListObjectAttributesRequest listObjectAttributesRequest = CloudDirectoryUtils.getListObjectAttributesRequest(cloudDirectoryProperties.getDirectoryArn(), identifier);
final ListObjectAttributesResult attributesResult = amazonCloudDirectory.listObjectAttributes(listObjectAttributesRequest);
if (attributesResult != null && attributesResult.getAttributes() != null) {
return attributesResult.getAttributes().stream().map(a -> {
Object value = null;
final TypedAttributeValue attributeValue = a.getValue();
LOGGER.debug("Examining attribute [{}]", a);
if (StringUtils.isNotBlank(attributeValue.getNumberValue())) {
value = attributeValue.getNumberValue();
} else if (attributeValue.getDatetimeValue() != null) {
value = DateTimeUtils.zonedDateTimeOf(attributeValue.getDatetimeValue()).toString();
} else if (attributeValue.getBooleanValue() != null) {
value = attributeValue.getBooleanValue().toString();
} else if (attributeValue.getBinaryValue() != null) {
value = new String(attributeValue.getBinaryValue().array(), StandardCharsets.UTF_8);
} else if (StringUtils.isNotBlank(attributeValue.getStringValue())) {
value = attributeValue.getStringValue();
}
return Pair.of(a.getKey().getName(), value);
}).filter(p -> p.getValue() != null).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
}
}
return null;
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class CasConfigurationMetadataServerController method search.
/**
* Search for property.
*
* @param name the name
* @return the response entity
*/
@GetMapping(path = "/search")
public ResponseEntity<List<ConfigurationMetadataSearchResult>> search(@RequestParam(value = "name", required = false) final String name) {
List results = new ArrayList<>();
final Map<String, ConfigurationMetadataProperty> allProps = repository.getRepository().getAllProperties();
if (StringUtils.isNotBlank(name) && RegexUtils.isValidRegex(name)) {
final String names = StreamSupport.stream(RelaxedNames.forCamelCase(name).spliterator(), false).map(Object::toString).collect(Collectors.joining("|"));
final Pattern pattern = RegexUtils.createPattern(names);
results = allProps.entrySet().stream().filter(propEntry -> RegexUtils.find(pattern, propEntry.getKey())).map(propEntry -> new ConfigurationMetadataSearchResult(propEntry.getValue(), repository)).collect(Collectors.toList());
Collections.sort(results);
}
return ResponseEntity.ok(results);
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class OidcJwksEndpointController method handleRequestInternal.
/**
* Handle request for jwk set.
*
* @param request the request
* @param response the response
* @param model the model
* @return the jwk set
*/
@GetMapping(value = '/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.JWKS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response, final Model model) {
try {
final String jsonJwks = IOUtils.toString(this.jwksFile.getInputStream(), StandardCharsets.UTF_8);
final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(jsonJwks);
this.servicesManager.getAllServices().stream().filter(s -> s instanceof OidcRegisteredService && StringUtils.isNotBlank(((OidcRegisteredService) s).getJwks())).forEach(Unchecked.consumer(s -> {
final OidcRegisteredService service = (OidcRegisteredService) s;
final Resource resource = this.resourceLoader.getResource(service.getJwks());
final JsonWebKeySet set = new JsonWebKeySet(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
set.getJsonWebKeys().forEach(jsonWebKeySet::addJsonWebKey);
}));
final String body = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.PUBLIC_ONLY);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
return new ResponseEntity<>(body, HttpStatus.OK);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class DelegatedClientFactory method configureCasClient.
/**
* Configure cas client.
*
* @param properties the properties
*/
protected void configureCasClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
pac4jProperties.getCas().stream().filter(cas -> StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
final CasConfiguration cfg = new CasConfiguration(cas.getLoginUrl(), CasProtocol.valueOf(cas.getProtocol()));
final CasClient client = new CasClient(cfg);
final int count = index.intValue();
if (StringUtils.isBlank(cas.getClientName())) {
client.setName(client.getClass().getSimpleName() + count);
}
configureClient(client, cas);
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
Aggregations