package br.com.test; import java.util.ArrayList; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import org.jboss.deployers.spi.management.ManagementView; import org.jboss.managed.api.ComponentType; import org.jboss.managed.api.ManagedComponent; import org.jboss.managed.api.ManagedProperty; import org.jboss.managed.plugins.ManagedObjectImpl; import org.jboss.metatype.api.types.SimpleMetaType; import org.jboss.metatype.api.values.CollectionValueSupport; import org.jboss.metatype.api.values.GenericValueSupport; import org.jboss.metatype.api.values.MetaValue; import org.jboss.metatype.api.values.MetaValueFactory; import org.jboss.metatype.api.values.SimpleValueSupport; import org.jboss.profileservice.spi.ProfileService; public class TeiidManagement { private static final String VDB = "TeiidPerfVDB.1"; private final static String TYPE = "teiid"; private final static String SUBTYPE = "vdb"; private final static ComponentType COMPONENT_TYPE = new ComponentType(TYPE, SUBTYPE); public static void main(String[] args) { try { ProfileService ps = (ProfileService) getContext().lookup("java:ProfileService"); ManagementView mView = ps.getViewManager(); ManagedComponent mComp = mView.getComponent(VDB, COMPONENT_TYPE); if(mComp == null){ System.out.println("comp null exiting"); System.exit(0); } for(String name : mComp.getPropertyNames()){ System.out.println("checking property: " + name); ManagedProperty mProp = mComp.getProperty(name); System.out.println("managedProperty: " + mProp); if(mProp == null) continue; MetaValue value = mProp.getValue(); if(value instanceof CollectionValueSupport){ System.out.println("managedProperty isCollection: " + mProp.getName()); for(MetaValue val : ((CollectionValueSupport)value).getElements()){ GenericValueSupport genValueSupport = (GenericValueSupport) val; ManagedObjectImpl managedObject = (ManagedObjectImpl) genValueSupport .getValue(); for(String dataRolesProp : managedObject.getPropertyNames()){ System.out.println("teiid checking property: " + dataRolesProp); ManagedProperty property = managedObject.getProperty(dataRolesProp); System.out.println("teiid managedProperty value: " + property.getValue()); if(mProp == null) continue; if("mappedRoleNames".equalsIgnoreCase(dataRolesProp)){ System.out.println("updating mappedRoleNames value..."); property.setValue(MetaValueFactory.getInstance().create(new ArrayList())); } else if("anyAuthenticated".equalsIgnoreCase(dataRolesProp)) { System.out.println("updating anyAuthenticated value..."); property.setValue(new SimpleValueSupport(SimpleMetaType.BOOLEAN, Boolean.TRUE)); } } } } else { System.out.println("value: " + value); } } mView.updateComponent(mComp); mView.load(); System.out.println("done"); System.exit(0); } catch (Throwable t) { t.printStackTrace(); } } private static Context getContext() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "localhost:1099"); return new InitialContext(p); } }