Search in sources :

Example 21 with StringUtils.isNotBlank

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);
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PasswordEncoderUtils(org.apereo.cas.authentication.support.password.PasswordEncoderUtils) AcceptAuthenticationProperties(org.apereo.cas.configuration.model.support.generic.AcceptAuthenticationProperties) HttpClient(org.apereo.cas.util.http.HttpClient) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ServicesManager(org.apereo.cas.services.ServicesManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) Collectors(java.util.stream.Collectors) HttpBasedServiceCredentialsAuthenticationHandler(org.apereo.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) PasswordPolicyConfiguration(org.apereo.cas.authentication.support.password.PasswordPolicyConfiguration) List(java.util.List) Stream(java.util.stream.Stream) JaasAuthenticationHandler(org.apereo.cas.authentication.handler.support.JaasAuthenticationHandler) PrincipalNameTransformerUtils(org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils) Bean(org.springframework.context.annotation.Bean) Pattern(java.util.regex.Pattern) AuthenticationEventExecutionPlanConfigurer(org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) ProxyingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ProxyingPrincipalResolver) Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap)

Example 22 with StringUtils.isNotBlank

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;
}
Also used : ListObjectAttributesResult(com.amazonaws.services.clouddirectory.model.ListObjectAttributesResult) ListIndexRequest(com.amazonaws.services.clouddirectory.model.ListIndexRequest) DateTimeUtils(org.apereo.cas.util.DateTimeUtils) ObjectReference(com.amazonaws.services.clouddirectory.model.ObjectReference) ListObjectAttributesRequest(com.amazonaws.services.clouddirectory.model.ListObjectAttributesRequest) TypedAttributeValue(com.amazonaws.services.clouddirectory.model.TypedAttributeValue) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ListIndexResult(com.amazonaws.services.clouddirectory.model.ListIndexResult) StandardCharsets(java.nio.charset.StandardCharsets) Slf4j(lombok.extern.slf4j.Slf4j) Pair(org.apache.commons.lang3.tuple.Pair) IndexAttachment(com.amazonaws.services.clouddirectory.model.IndexAttachment) CloudDirectoryProperties(org.apereo.cas.configuration.model.support.clouddirectory.CloudDirectoryProperties) Map(java.util.Map) AmazonCloudDirectory(com.amazonaws.services.clouddirectory.AmazonCloudDirectory) AllArgsConstructor(lombok.AllArgsConstructor) ListObjectAttributesResult(com.amazonaws.services.clouddirectory.model.ListObjectAttributesResult) ListObjectAttributesRequest(com.amazonaws.services.clouddirectory.model.ListObjectAttributesRequest) TypedAttributeValue(com.amazonaws.services.clouddirectory.model.TypedAttributeValue) IndexAttachment(com.amazonaws.services.clouddirectory.model.IndexAttachment)

Example 23 with StringUtils.isNotBlank

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);
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) RelaxedNames(org.springframework.boot.bind.RelaxedNames) RequestParam(org.springframework.web.bind.annotation.RequestParam) BaseCasMvcEndpoint(org.apereo.cas.web.BaseCasMvcEndpoint) HttpServletResponse(javax.servlet.http.HttpServletResponse) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) RegexUtils(org.apereo.cas.util.RegexUtils) ArrayList(java.util.ArrayList) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) ModelAndView(org.springframework.web.servlet.ModelAndView) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseEntity(org.springframework.http.ResponseEntity) StreamSupport(java.util.stream.StreamSupport) Pattern(java.util.regex.Pattern) ConfigurationMetadataGroup(org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup) Collections(java.util.Collections) Pattern(java.util.regex.Pattern) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 24 with StringUtils.isNotBlank

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);
    }
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) BaseOAuth20Controller(org.apereo.cas.support.oauth.web.endpoints.BaseOAuth20Controller) OAuth20Validator(org.apereo.cas.support.oauth.validator.OAuth20Validator) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Model(org.springframework.ui.Model) HttpServletRequest(javax.servlet.http.HttpServletRequest) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) CookieRetrievingCookieGenerator(org.apereo.cas.web.support.CookieRetrievingCookieGenerator) GetMapping(org.springframework.web.bind.annotation.GetMapping) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Resource(org.springframework.core.io.Resource) Unchecked(org.jooq.lambda.Unchecked) ResourceLoader(org.springframework.core.io.ResourceLoader) OAuth20ProfileScopeToAttributesFilter(org.apereo.cas.support.oauth.profile.OAuth20ProfileScopeToAttributesFilter) NonNull(lombok.NonNull) OidcConstants(org.apereo.cas.oidc.OidcConstants) JsonWebKey(org.jose4j.jwk.JsonWebKey) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) AccessTokenFactory(org.apereo.cas.ticket.accesstoken.AccessTokenFactory) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) ResponseEntity(org.springframework.http.ResponseEntity) ResponseEntity(org.springframework.http.ResponseEntity) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) Resource(org.springframework.core.io.Resource) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 25 with StringUtils.isNotBlank

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);
    });
}
Also used : Pac4jBaseClientProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jBaseClientProperties) WindowsLiveClient(org.pac4j.oauth.client.WindowsLiveClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) BitbucketClient(org.pac4j.oauth.client.BitbucketClient) SneakyThrows(lombok.SneakyThrows) Google2Client(org.pac4j.oauth.client.Google2Client) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SAML2Client(org.pac4j.saml.client.SAML2Client) WordPressClient(org.pac4j.oauth.client.WordPressClient) StringUtils(org.apache.commons.lang3.StringUtils) YahooClient(org.pac4j.oauth.client.YahooClient) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) LinkedIn2Client(org.pac4j.oauth.client.LinkedIn2Client) OidcClient(org.pac4j.oidc.client.OidcClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PayPalClient(org.pac4j.oauth.client.PayPalClient) LinkedHashSet(java.util.LinkedHashSet) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) FacebookClient(org.pac4j.oauth.client.FacebookClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) Verb(com.github.scribejava.core.model.Verb) Collection(java.util.Collection) Pac4jDelegatedAuthenticationProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jDelegatedAuthenticationProperties) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) Slf4j(lombok.extern.slf4j.Slf4j) BaseClient(org.pac4j.core.client.BaseClient) TwitterClient(org.pac4j.oauth.client.TwitterClient) Pac4jOidcProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jOidcProperties) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) CasProtocol(org.pac4j.cas.config.CasProtocol) FoursquareClient(org.pac4j.oauth.client.FoursquareClient) GitHubClient(org.pac4j.oauth.client.GitHubClient) OrcidClient(org.pac4j.oauth.client.OrcidClient) DropBoxClient(org.pac4j.oauth.client.DropBoxClient) SAML2ClientConfiguration(org.pac4j.saml.client.SAML2ClientConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)24 Slf4j (lombok.extern.slf4j.Slf4j)16 Set (java.util.Set)13 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)13 ServicesManager (org.apereo.cas.services.ServicesManager)13 Collection (java.util.Collection)12 List (java.util.List)11 Map (java.util.Map)11 Verb (com.github.scribejava.core.model.Verb)8 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)8 LinkedHashSet (java.util.LinkedHashSet)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 CasClient (org.pac4j.cas.client.CasClient)8 CasConfiguration (org.pac4j.cas.config.CasConfiguration)8 BaseClient (org.pac4j.core.client.BaseClient)8 BitbucketClient (org.pac4j.oauth.client.BitbucketClient)8 DropBoxClient (org.pac4j.oauth.client.DropBoxClient)8 FacebookClient (org.pac4j.oauth.client.FacebookClient)8 FoursquareClient (org.pac4j.oauth.client.FoursquareClient)8 GenericOAuth20Client (org.pac4j.oauth.client.GenericOAuth20Client)8