Search in sources :

Example 1 with EvaluationContextExtension

use of org.springframework.data.spel.spi.EvaluationContextExtension in project CzechIdMng by bcvsolutions.

the class WebSecurityConfig method securityExtension.

/**
 * Support hasAuthority etc. in search queries
 *
 * @return
 */
@Bean
public EvaluationContextExtension securityExtension() {
    return new EvaluationContextExtension() {

        @Override
        public String getExtensionId() {
            return "security";
        }

        @Override
        public SecurityExpressionRoot getRootObject() {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication == null) {
                // not authenticated
                return null;
            }
            SecurityExpressionRoot root = new SecurityExpressionRoot(authentication) {
            };
            root.setRoleHierarchy(roleHierarchy);
            return root;
        }
    };
}
Also used : EvaluationContextExtension(org.springframework.data.spel.spi.EvaluationContextExtension) Authentication(org.springframework.security.core.Authentication) SecurityExpressionRoot(org.springframework.security.access.expression.SecurityExpressionRoot) MethodInvokingFactoryBean(org.springframework.beans.factory.config.MethodInvokingFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MethodInvokingFactoryBean (org.springframework.beans.factory.config.MethodInvokingFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1 EvaluationContextExtension (org.springframework.data.spel.spi.EvaluationContextExtension)1 SecurityExpressionRoot (org.springframework.security.access.expression.SecurityExpressionRoot)1 Authentication (org.springframework.security.core.Authentication)1