Search in sources :

Example 16 with Configured

use of org.jvnet.hk2.config.Configured in project Payara by payara.

the class BasePersistenceStrategyBuilder method readInstanceLevelParams.

public void readInstanceLevelParams(ServerConfigLookup serverConfigLookup) {
    org.glassfish.web.config.serverbeans.SessionManager smBean = serverConfigLookup.getInstanceSessionManager();
    if (smBean != null) {
        // The persistence-type controls what properties of the
        // session manager can be configured
        org.glassfish.web.config.serverbeans.ManagerProperties mgrBean = smBean.getManagerProperties();
        if (mgrBean != null) {
            // manager reap-interval-in-seconds
            String reapIntervalInSecondsString = mgrBean.getReapIntervalInSeconds();
            if (reapIntervalInSecondsString != null) {
                try {
                    reapInterval = Integer.parseInt(reapIntervalInSecondsString);
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, LogFacade.MANAGER_REAP_INTERVAL_SET, reapInterval);
                    }
                } catch (NumberFormatException e) {
                // XXX need error message
                }
            } else {
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_MGR_REAP_INTERVAL);
                }
            }
            // max-sessions
            String maxSessionsString = mgrBean.getMaxSessions();
            if (maxSessionsString != null) {
                try {
                    maxSessions = Integer.parseInt(maxSessionsString);
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, LogFacade.MAX_SESSIONS_SET, maxSessions);
                    }
                } catch (NumberFormatException e) {
                // XXX need error message
                }
            } else {
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_MAX_SESSIONS);
                }
            }
            // session-file-name
            String sessionFilenameString = mgrBean.getSessionFileName();
            if (sessionFilenameString != null) {
                sessionFilename = sessionFilenameString;
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, LogFacade.SESSION_FILENAME_SET, sessionFilename);
                }
            }
            // START CR 6275709
            sessionIdGeneratorClassname = mgrBean.getSessionIdGeneratorClassname();
            if (sessionIdGeneratorClassname != null && _logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, LogFacade.SESSION_ID_GENERATOR_CLASSNAME_SET, sessionIdGeneratorClassname);
            }
            // END CR 6275709
            // Now do properties under <manager-properties> element
            List<Property> props = mgrBean.getProperty();
            if (props != null) {
                for (Property prop : props) {
                    String name = prop.getName();
                    String value = prop.getValue();
                    // maxIdleBackupSeconds
                    if (name.equalsIgnoreCase("maxIdleBackupSeconds")) {
                        try {
                            maxIdleBackup = Integer.parseInt(value);
                        } catch (NumberFormatException e) {
                        // XXX need error message
                        }
                    } else if (name.equalsIgnoreCase(MIN_IDLE_SWAP_PROPERTY)) {
                        try {
                            minIdleSwap = Integer.parseInt(value);
                        } catch (NumberFormatException e) {
                        // XXX need error message
                        }
                    } else if (name.equalsIgnoreCase(MAX_IDLE_SWAP_PROPERTY)) {
                        try {
                            maxIdleSwap = Integer.parseInt(value);
                        } catch (NumberFormatException e) {
                        // XXX need error message
                        }
                    }
                }
            }
        }
        org.glassfish.web.config.serverbeans.StoreProperties storeBean = smBean.getStoreProperties();
        if (storeBean != null) {
            // Store reap-interval-in-seconds
            String reapIntervalInSecondsString = storeBean.getReapIntervalInSeconds();
            if (reapIntervalInSecondsString != null) {
                try {
                    storeReapInterval = Integer.parseInt(reapIntervalInSecondsString);
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, LogFacade.STORE_REAP_INTERVAL_SET, storeReapInterval);
                    }
                } catch (NumberFormatException e) {
                // XXX need error message
                }
            }
            // Directory
            String directoryString = storeBean.getDirectory();
            if (directoryString != null) {
                directory = directoryString;
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, LogFacade.DIRECTORY_SET, directoryString);
                }
            }
        }
    }
    SessionProperties spBean = serverConfigLookup.getInstanceSessionProperties();
    if (spBean != null) {
        // session timeout-in-seconds
        String timeoutSecondsString = spBean.getTimeoutInSeconds();
        if (timeoutSecondsString != null) {
            try {
                sessionMaxInactiveInterval = Integer.parseInt(timeoutSecondsString);
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, LogFacade.SESSION_MAX_INACTIVE_INTERVAL_SET, sessionMaxInactiveInterval);
                }
            } catch (NumberFormatException e) {
            // XXX need error message
            }
        } else {
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_SESSION_MAX_INACTIVE_INTERVAL);
            }
        }
    }
}
Also used : SessionProperties(org.glassfish.web.config.serverbeans.SessionProperties) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Property(org.jvnet.hk2.config.types.Property)

Example 17 with Configured

use of org.jvnet.hk2.config.Configured in project Payara by payara.

the class ConfigApiTest method getHabitat.

/**
 * Returns a configured Habitat with the configuration.
 *
 * @return a configured Habitat
 */
public ServiceLocator getHabitat() {
    ServiceLocator habitat = Utils.instance.getHabitat(this);
    assertNotNull("Transactions service from Configuration subsystem is null", habitat.getService(Transactions.class));
    return habitat;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Transactions(org.jvnet.hk2.config.Transactions)

Example 18 with Configured

use of org.jvnet.hk2.config.Configured in project Payara by payara.

the class LDAPAdminAccessConfigurator method pingLDAP.

private boolean pingLDAP(StringBuilder sb) {
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    if (url != null && url.startsWith(LDAPS_URL)) {
        env.put(LDAP_SOCKET_FACTORY, DEFAULT_SSL_LDAP_SOCKET_FACTORY);
    }
    try {
        new InitialContext(env);
        appendNL(sb, lsm.getString("ldap.ok", url));
        return true;
    } catch (AuthenticationNotSupportedException anse) {
        // CR 6944776
        // If the server throws this error, it is up
        // and is configured with Anonymous bind disabled.
        // Ignore this error while configuring ldap for admin
        appendNL(sb, lsm.getString("ldap.ok", url));
        return true;
    } catch (Exception e) {
        appendNL(sb, lsm.getString("ldap.na", url, e.getClass().getName(), e.getMessage()));
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, StringUtils.getStackTrace(e));
        }
        return false;
    }
}
Also used : AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) PropertyVetoException(java.beans.PropertyVetoException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) RetryableException(org.jvnet.hk2.config.RetryableException)

Example 19 with Configured

use of org.jvnet.hk2.config.Configured in project Payara by payara.

the class ConfigBeanJMXSupport method getTypesImplementing.

/**
 * works only for @Configured types
 */
public static Class[] getTypesImplementing(final Class<?> clazz) {
    final DomDocument domDoc = new DomDocument(InjectedValues.getInstance().getHabitat());
    try {
        final List<ConfigModel> models = domDoc.getAllModelsImplementing(clazz);
        final Class[] interfaces = new Class[models == null ? 0 : models.size()];
        if (models != null) {
            int i = 0;
            for (final ConfigModel model : models) {
                final String classname = model.targetTypeName;
                final Class<?> intf = model.classLoaderHolder.loadClass(classname);
                interfaces[i] = intf;
                ++i;
            }
        }
        return interfaces;
    } catch (final Exception e) {
        AMXLoggerInfo.getLogger().log(Level.INFO, AMXLoggerInfo.cantGetTypesImplementing, new Object[] { clazz, e.getLocalizedMessage() });
        throw new RuntimeException(e);
    }
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 20 with Configured

use of org.jvnet.hk2.config.Configured in project Payara by payara.

the class ListFileGroup method getFileRealm.

private FileRealm getFileRealm(final SecurityService securityService, AuthRealm fileAuthRealm, ActionReport report) {
    // Get FileRealm class name, match it with what is expected.
    String fileRealmClassName = fileAuthRealm.getClassname();
    // Report error if provided impl is not the one expected
    if (fileRealmClassName != null && !fileRealmClassName.equals("com.sun.enterprise.security.auth.realm.file.FileRealm")) {
        report.setMessage(localStrings.getLocalString("list.file.user.realmnotsupported", "Configured file realm {0} is not supported.", fileRealmClassName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    }
    // ensure we have the file associated with the authrealm
    String keyFile = null;
    for (Property fileProp : fileAuthRealm.getProperty()) {
        if (fileProp.getName().equals("file"))
            keyFile = fileProp.getValue();
    }
    if (keyFile == null) {
        report.setMessage(localStrings.getLocalString("list.file.user.keyfilenotfound", "There is no physical file associated with this file realm {0} ", authRealmName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    }
    // We have the right impl so let's try to remove one
    FileRealm fr = null;
    try {
        realmsManager.createRealms(config);
        fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
        if (fr == null) {
            throw new NoSuchRealmException(authRealmName);
        }
    } catch (NoSuchRealmException e) {
        report.setMessage(localStrings.getLocalString("list.file.user.realmnotsupported", "Configured file realm {0} is not supported.", authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    return fr;
}
Also used : NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) FileRealm(com.sun.enterprise.security.auth.realm.file.FileRealm) Property(org.jvnet.hk2.config.types.Property)

Aggregations

Property (org.jvnet.hk2.config.types.Property)12 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)10 ActionReport (org.glassfish.api.ActionReport)8 PropertyVetoException (java.beans.PropertyVetoException)7 FileRealm (com.sun.enterprise.security.auth.realm.file.FileRealm)6 Resources (com.sun.enterprise.config.serverbeans.Resources)5 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)5 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)5 Resource (com.sun.enterprise.config.serverbeans.Resource)4 File (java.io.File)4 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)4 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)3 List (java.util.List)3 Properties (java.util.Properties)3 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)2 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2