package org.jboss.as.console.client.rbac;

import com.allen_sauer.gwt.log.client.Log;
import com.google.inject.Inject;
import org.jboss.as.console.client.widgets.forms.ApplicationMetaData;
import org.jboss.as.console.client.widgets.forms.BeanMetaData;
import org.jboss.as.console.client.widgets.forms.PropertyBinding;
import org.jboss.ballroom.client.rbac.SecurityContext;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Heiko Braun
 * @date 8/12/13
 */
public class MetaDataAdapter {

    private ApplicationMetaData metaData;

    @Inject
    public MetaDataAdapter(ApplicationMetaData metaData) {
        this.metaData = metaData;
    }

    public Set<String> getReadOnlyJavaNames(Class<?> type, SecurityContext securityContext) {
        final Set<String> readonlyJavaNames = new HashSet<String>();
        try {
            BeanMetaData beanMetaData = metaData.getBeanMetaData(type);
            for(PropertyBinding propBinding : beanMetaData.getProperties())
            {
                if(!securityContext.getAttributeWritePriviledge(propBinding.getDetypedName()).isGranted())
                    readonlyJavaNames.add(propBinding.getJavaName());
            }
        } catch (Exception e) {
            Log.warn("No meta data for "+type);
        }
        return readonlyJavaNames;
    }
}

@@ -1095,17 +1095,90 @@
 ranted()
-)
+%0A                        && !propBinding.isKey()) // HAL-202: exclude keys
 %0A       

Fix HAL-202