В дополнение к стандартной логике проверки прав, для пары сущностный требуется реализовать кстомную логику проверки прав на редактирование нескольких атрибутов.
На данном этапе мы можем “пока обойтись” setEnable(false) в контроллере экрана для соответсвующих контролов, но в перспективе потребуется REST API.
Поэтому, пытаюсь сразу воткнуться в SecurityImpl, переопределить его метод isEntityAttrUpdatePermitted и добавив в дополнительную проверку.
Создал тестовый проект, в нем создан новый класс ExtSecurityImpl:
package com.company.testcustonsecur.core;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.sys.SecurityImpl;
public class ExtSecurityImpl extends SecurityImpl{
@Override
public boolean isEntityAttrUpdatePermitted(MetaClass metaClass, String propertyPath) {
return super.isEntityAttrUpdatePermitted(metaClass, propertyPath);
}
}
Зарегистрировал класс ExtSecurityImpl в spring.xml модуля core проекта:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- Annotation-based beans -->
<context:component-scan base-package="com.company.testcustonsecur"/>
<bean id="cuba_Security" class="com.company.testcustonsecur.core.ExtSecurityImpl"/>
</beans>
Уже на этом этапе, при попытке запуска приложения сыпятся ошибки:
<....>
22:34:06.550 WARN c.h.c.c.s.CubaCoreApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_UserManagementService': Unsatisfied dependency expressed through field 'security'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Security': Unsatisfied dependency expressed through field 'security'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.haulmont.cuba.core.PersistenceSecurity' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}
22:34:06.571 ERROR c.h.c.c.s.AbstractWebAppContextLoader - Error initializing application
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_UserManagementService': Unsatisfied dependency expressed through field 'security'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Security': Unsatisfied dependency expressed through field 'security'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.haulmont.cuba.core.PersistenceSecurity' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
<....>
К сожалению, в документации информации о возможностях и тонкостях переопределения SecurityImpl не нашел.
Может есть сампл, в котором можно подсмотреть реализацию подобной задачи с SecurityImpl??