Search in sources :

Example 1 with SetupAttributeAccessEvent

use of com.haulmont.cuba.core.app.events.SetupAttributeAccessEvent in project cuba by cuba-platform.

the class AttributeSecuritySupport method setupAttributeAccess.

@SuppressWarnings("unchecked")
public <T extends Entity> void setupAttributeAccess(T entity) {
    if (entity instanceof BaseGenericIdEntity || entity instanceof EmbeddableEntity) {
        SetupAttributeAccessEvent<T> event = new SetupAttributeAccessEvent<>(entity);
        boolean handled = false;
        Map<String, SetupAttributeAccessHandler> handlers = AppBeans.getAll(SetupAttributeAccessHandler.class);
        if (handlers != null) {
            for (SetupAttributeAccessHandler handler : handlers.values()) {
                MetaClass metaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(entity.getMetaClass());
                if (handler.supports(metaClass.getJavaClass())) {
                    handled = true;
                    handler.setupAccess(event);
                }
            }
        }
        if (event.getReadonlyAttributes() != null) {
            Set<String> attributes = event.getReadonlyAttributes();
            SecurityState state = getOrCreateSecurityState(entity);
            addReadonlyAttributes(state, attributes.toArray(new String[attributes.size()]));
        }
        if (event.getRequiredAttributes() != null) {
            Set<String> attributes = event.getRequiredAttributes();
            SecurityState state = getOrCreateSecurityState(entity);
            addRequiredAttributes(state, attributes.toArray(new String[attributes.size()]));
        }
        if (event.getHiddenAttributes() != null) {
            Set<String> attributes = event.getHiddenAttributes();
            SecurityState state = getOrCreateSecurityState(entity);
            addHiddenAttributes(state, attributes.toArray(new String[attributes.size()]));
        }
        if (handled) {
            securityTokenManager.writeSecurityToken(entity);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) SetupAttributeAccessEvent(com.haulmont.cuba.core.app.events.SetupAttributeAccessEvent)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)1 SetupAttributeAccessEvent (com.haulmont.cuba.core.app.events.SetupAttributeAccessEvent)1