Search in sources :

Example 61 with Domain

use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.

the class ServerRemoteRestAdminCommand method completeInit.

private synchronized void completeInit(final ServiceLocator habitat) {
    this.habitat = habitat;
    final Domain domain = habitat.getService(Domain.class);
    secureAdmin = domain.getSecureAdmin();
    serverEnv = habitat.getService(ServerEnvironment.class);
    this.secure = SecureAdmin.Util.isEnabled(secureAdmin);
    domainPasswordAliasStore = habitat.getService(DomainScopedPasswordAliasStore.class);
    setInteractive(false);
}
Also used : DomainScopedPasswordAliasStore(com.sun.enterprise.security.store.DomainScopedPasswordAliasStore) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 62 with Domain

use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.

the class NodeAgentConfigUpgrade method postConstruct.

@Override
public void postConstruct() {
    final NodeAgents nodeAgents = domain.getNodeAgents();
    if (nodeAgents == null) {
        createDefaultNodeList();
        return;
    }
    final List<NodeAgent> agList = nodeAgents.getNodeAgent();
    if (agList.isEmpty()) {
        createDefaultNodeList();
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            @Override
            public Object run(Domain d) throws PropertyVetoException, TransactionFailure {
                Nodes nodes = d.createChild(Nodes.class);
                Transaction t = Transaction.getTransaction(d);
                if (t == null)
                    return null;
                for (NodeAgent na : agList) {
                    String host = null;
                    Node node = nodes.createChild(Node.class);
                    node.setName(na.getName());
                    node.setType("CONFIG");
                    JmxConnector jc = na.getJmxConnector();
                    if (jc != null) {
                        // get the properties and see if host name is specified
                        List<Property> agentProp = jc.getProperty();
                        for (Property p : agentProp) {
                            String name = p.getName();
                            if (name.equals("client-hostname")) {
                                // create the node with a host name
                                node.setNodeHost(p.getValue());
                                node.setInstallDir("${com.sun.aas.productRoot}");
                            }
                        }
                    }
                    nodes.getNode().add(node);
                }
                // Now add the builtin localhost node
                createDefaultNode(d, nodes);
                d.setNodes(nodes);
                List<Server> serverList = servers.getServer();
                if (serverList.isEmpty())
                    return null;
                for (Server s : serverList) {
                    s = t.enroll(s);
                    s.setNodeRef(s.getNodeAgentRef());
                    s.setNodeAgentRef(null);
                }
                // remove the node-agent element by setting to null
                d.setNodeAgents(null);
                return null;
            }
        }, domain);
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading node-agent from V2 to V3", e);
        throw new RuntimeException(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) NodeAgent(com.sun.enterprise.config.serverbeans.NodeAgent) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) NodeAgents(com.sun.enterprise.config.serverbeans.NodeAgents) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property)

Example 63 with Domain

use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.

the class UniqueResourceNameValidator method isValid.

@Override
public boolean isValid(final Resource resource, final ConstraintValidatorContext constraintValidatorContext) {
    if (domain != null) {
        if (resource.getParent().getParent() instanceof Domain) {
            for (Resource res : domain.getResources().getResources()) {
                if (resource.getIdentity().equals(res.getIdentity())) {
                    Class[] resourceInterfaces = resource.getClass().getInterfaces();
                    Class[] resInterfaces = res.getClass().getInterfaces();
                    for (Class resourceClass : resourceInterfaces) {
                        for (Class resClass : resInterfaces) {
                            if (resClass.isAssignableFrom(resourceClass)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Resource(com.sun.enterprise.config.serverbeans.Resource) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 64 with Domain

use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.

the class RealmsImpl method getAnonymousUser.

public String getAnonymousUser() {
    Domain domain = InjectedValues.getInstance().getHabitat().getService(Domain.class);
    List<Config> configs = domain.getConfigs().getConfig();
    // find the ADMIN_REALM
    AuthRealm adminFileAuthRealm = null;
    for (Config config : configs) {
        if (config.getSecurityService() == null)
            continue;
        for (AuthRealm auth : config.getSecurityService().getAuthRealm()) {
            if (auth.getName().equals(ADMIN_REALM)) {
                adminFileAuthRealm = auth;
                break;
            }
        }
    }
    if (adminFileAuthRealm == null) {
        // There must always be an admin realm
        throw new IllegalStateException("Cannot find admin realm");
    }
    // Get FileRealm class name
    String fileRealmClassName = adminFileAuthRealm.getClassname();
    if (!fileRealmClassName.equals(FILE_REALM_CLASSNAME)) {
        // we treat this as an error and instead of throwing exception return false;
        return null;
    }
    Property keyfileProp = adminFileAuthRealm.getProperty("file");
    if (keyfileProp == null) {
        throw new IllegalStateException("Cannot find property 'file'");
    }
    String keyFile = keyfileProp.getValue();
    if (keyFile == null) {
        throw new IllegalStateException("Cannot find key file");
    }
    String user = null;
    String[] usernames = getUserNames(adminFileAuthRealm.getName());
    if (usernames.length == 1) {
        try {
            InjectedValues.getInstance().getHabitat().getService(SecurityLifecycle.class);
            WebAndEjbToJaasBridge.login(usernames[0], new char[0], ADMIN_REALM);
            user = usernames[0];
        } catch (final Exception e) {
        // 
        }
    }
    return user;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Config(com.sun.enterprise.config.serverbeans.Config) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property)

Example 65 with Domain

use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.

the class ReferenceConstrainTest method doChangeToValidPool.

// @Ignore
@Test
public void doChangeToValidPool() throws TransactionFailure {
    Domain domain = habitat.getService(Domain.class);
    // Find JdbcResource to chenge its values
    Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
    JdbcResource jdbc = null;
    while (iterator.hasNext()) {
        JdbcResource res = iterator.next();
        if ("__TimerPool".equals(res.getPoolName())) {
            jdbc = res;
            break;
        }
    }
    assertNotNull(jdbc);
    ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("pool-name", "H2Pool");
    changes.put(poolConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
    } catch (TransactionFailure tf) {
        fail();
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) ConfigBean(org.jvnet.hk2.config.ConfigBean) Domain(com.sun.enterprise.config.serverbeans.Domain) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(org.glassfish.jdbcruntime.config.ConfigApiTest) Test(org.junit.Test)

Aggregations

Domain (com.sun.enterprise.config.serverbeans.Domain)70 Test (org.junit.Test)21 Server (com.sun.enterprise.config.serverbeans.Server)15 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)12 Dom (org.jvnet.hk2.config.Dom)11 PropertyVetoException (java.beans.PropertyVetoException)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)7 Resources (com.sun.enterprise.config.serverbeans.Resources)7 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)7 ServerContext (org.glassfish.internal.api.ServerContext)7 Config (com.sun.enterprise.config.serverbeans.Config)6 Resource (com.sun.enterprise.config.serverbeans.Resource)6 ParameterMap (org.glassfish.api.admin.ParameterMap)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Before (org.junit.Before)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 PropsFileActionReporter (com.sun.enterprise.admin.report.PropsFileActionReporter)4