Search in sources :

Example 6 with DefaultWebSecurityExpressionHandler

use of org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler in project oc-explorer by devgateway.

the class WebSecurityConfig method webExpressionHandler.

/**
 * Instantiates {@see DefaultWebSecurityExpressionHandler} and assigns to it role hierarchy.
 *
 * @return
 */
private SecurityExpressionHandler<FilterInvocation> webExpressionHandler() {
    DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
    handler.setRoleHierarchy(roleHierarchy());
    return handler;
}
Also used : DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler)

Example 7 with DefaultWebSecurityExpressionHandler

use of org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler in project CzechIdMng by bcvsolutions.

the class WebSecurityConfig method expressionHandler.

/**
 * Inject role hierarchy to HttpSecurity expressions
 *
 * @return
 */
private SecurityExpressionHandler<FilterInvocation> expressionHandler() {
    DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler();
    defaultWebSecurityExpressionHandler.setRoleHierarchy(roleHierarchy);
    return defaultWebSecurityExpressionHandler;
}
Also used : DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler)

Example 8 with DefaultWebSecurityExpressionHandler

use of org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler in project engine by craftercms.

the class ConfigAwareSecurityMetadataSource method getAttributes.

@Override
@SuppressWarnings("unchecked")
public Collection<ConfigAttribute> getAttributes(final Object object) throws IllegalArgumentException {
    Callback<SecurityMetadataSource> callback = () -> {
        HierarchicalConfiguration siteConfig = ConfigUtils.getCurrentConfig();
        if (siteConfig != null) {
            List<HierarchicalConfiguration> restrictionsConfig = siteConfig.configurationsAt(URL_RESTRICTION_KEY);
            if (CollectionUtils.isNotEmpty(restrictionsConfig)) {
                LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> map = new LinkedHashMap<>();
                for (HierarchicalConfiguration restrictionConfig : restrictionsConfig) {
                    String url = restrictionConfig.getString(URL_RESTRICTION_URL_KEY);
                    String expression = restrictionConfig.getString(URL_RESTRICTION_EXPRESSION_KEY);
                    if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(expression)) {
                        AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
                        map.put(matcher, singleton(new SecurityConfig(expression)));
                    }
                }
                return new ExpressionBasedFilterInvocationSecurityMetadataSource(map, new DefaultWebSecurityExpressionHandler());
            }
        }
        return new DefaultFilterInvocationSecurityMetadataSource(new LinkedHashMap<>());
    };
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        SecurityMetadataSource metadataSource = cacheTemplate.getObject(siteContext.getContext(), callback, URL_RESTRICTIONS_CACHE_KEY);
        return metadataSource.getAttributes(object);
    }
    return null;
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) SiteContext(org.craftercms.engine.service.context.SiteContext) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) ExpressionBasedFilterInvocationSecurityMetadataSource(org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource) LinkedHashMap(java.util.LinkedHashMap) DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler) DefaultFilterInvocationSecurityMetadataSource(org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource) SecurityMetadataSource(org.springframework.security.access.SecurityMetadataSource) FilterInvocationSecurityMetadataSource(org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource) ExpressionBasedFilterInvocationSecurityMetadataSource(org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource) SecurityConfig(org.springframework.security.access.SecurityConfig) List(java.util.List) DefaultFilterInvocationSecurityMetadataSource(org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource)

Example 9 with DefaultWebSecurityExpressionHandler

use of org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler in project zhcet-web by zhcet-amu.

the class SecurityBeans method webExpressionHandler.

@Bean
protected DefaultWebSecurityExpressionHandler webExpressionHandler(RoleHierarchy roleHierarchy) {
    DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler();
    defaultWebSecurityExpressionHandler.setRoleHierarchy(roleHierarchy);
    return defaultWebSecurityExpressionHandler;
}
Also used : DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler) MethodInvokingFactoryBean(org.springframework.beans.factory.config.MethodInvokingFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultWebSecurityExpressionHandler (org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler)9 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1 SiteContext (org.craftercms.engine.service.context.SiteContext)1 Test (org.junit.jupiter.api.Test)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 MethodInvokingFactoryBean (org.springframework.beans.factory.config.MethodInvokingFactoryBean)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 ConfigAttribute (org.springframework.security.access.ConfigAttribute)1 PermissionEvaluator (org.springframework.security.access.PermissionEvaluator)1 SecurityConfig (org.springframework.security.access.SecurityConfig)1 SecurityMetadataSource (org.springframework.security.access.SecurityMetadataSource)1 DefaultMethodSecurityExpressionHandler (org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler)1 RoleHierarchy (org.springframework.security.access.hierarchicalroles.RoleHierarchy)1 AffirmativeBased (org.springframework.security.access.vote.AffirmativeBased)1 AuthenticationTrustResolver (org.springframework.security.authentication.AuthenticationTrustResolver)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1