Search in sources :

Example 46 with Property

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

the class SecurityUtil method getAnonymousUser.

public String getAnonymousUser(ServiceLocator habitat) {
    String user = null;
    // find the ADMIN_REALM
    AuthRealm adminFileAuthRealm = null;
    for (AuthRealm auth : domain.getConfigNamed(DAS_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 != null && !fileRealmClassName.equals(FILE_REALM_CLASSNAME)) {
        // we treat this as an error and instead of throwing exception return false;
        return null;
    }
    List<Property> props = adminFileAuthRealm.getProperty();
    Property keyfileProp = null;
    for (Property prop : props) {
        if ("file".equals(prop.getName())) {
            keyfileProp = prop;
        }
    }
    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[] usernames = getUserNames(adminFileAuthRealm.getName());
    if (usernames.length == 1) {
        try {
            habitat.getService(com.sun.enterprise.security.SecurityLifecycle.class);
            LoginContextDriver.login(usernames[0], new char[0], ADMIN_REALM);
            user = usernames[0];
        } catch (Exception e) {
        }
    }
    return user;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Property(org.jvnet.hk2.config.types.Property)

Example 47 with Property

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

the class SupportsUserManagementCommand method supportsUserManagement.

private boolean supportsUserManagement(String realmName) throws BadRealmException, NoSuchRealmException {
    Realm r = realmsManager.getFromLoadedRealms(config.getName(), realmName);
    if (r != null) {
        return r.supportsUserManagement();
    }
    List<AuthRealm> authRealmConfigs = config.getSecurityService().getAuthRealm();
    for (AuthRealm authRealm : authRealmConfigs) {
        if (realmName.equals(authRealm.getName())) {
            List<Property> propConfigs = authRealm.getProperty();
            Properties props = new Properties();
            for (Property p : propConfigs) {
                String value = p.getValue();
                props.setProperty(p.getName(), value);
            }
            r = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
            return r.supportsUserManagement();
        }
    }
    throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", new Object[] { realmName }));
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) Properties(java.util.Properties) AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Realm(com.sun.enterprise.security.auth.realm.Realm) Property(org.jvnet.hk2.config.types.Property)

Example 48 with Property

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

the class SynchronizeRealmFromConfig method instantiateRealm.

private boolean instantiateRealm(Config cfg, String realmName) throws BadRealmException, NoSuchRealmException {
    List<AuthRealm> authRealmConfigs = cfg.getSecurityService().getAuthRealm();
    for (AuthRealm authRealm : authRealmConfigs) {
        if (realmName.equals(authRealm.getName())) {
            List<Property> propConfigs = authRealm.getProperty();
            Properties props = new Properties();
            for (Property p : propConfigs) {
                String value = p.getValue();
                props.setProperty(p.getName(), value);
            }
            Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, cfg.getName());
            return true;
        }
    }
    throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", new Object[] { realmName }));
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property)

Example 49 with Property

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

the class RealmsImpl method _loadRealms.

private void _loadRealms() {
    if (realmsLoaded)
        throw new IllegalStateException();
    final List<AuthRealm> authRealms = getAuthRealms();
    final List<String> goodRealms = new ArrayList<String>();
    for (final AuthRealm authRealm : authRealms) {
        final List<Property> propList = authRealm.getProperty();
        final Properties props = new Properties();
        for (final Property p : propList) {
            props.setProperty(p.getName(), p.getValue());
        }
        try {
            Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props);
            goodRealms.add(authRealm.getName());
        } catch (final Exception e) {
            AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(authRealm), e.getLocalizedMessage() });
        }
    }
    if (goodRealms.size() != 0) {
        final String goodRealm = goodRealms.iterator().next();
        try {
            final String defaultRealm = getSecurityService().getDefaultRealm();
            Realm.getInstance(defaultRealm);
            Realm.setDefaultRealm(defaultRealm);
        } catch (final Exception e) {
            AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(goodRealm), e.getLocalizedMessage() });
            Realm.setDefaultRealm(goodRealms.iterator().next());
        }
    }
    realmsLoaded = true;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property)

Example 50 with Property

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

the class ModuleInfo method save.

/**
 * Saves its state to the configuration. this method must be called within a transaction
 * to the configured module instance.
 *
 * @param module the module being persisted
 */
public void save(Module module) throws TransactionFailure, PropertyVetoException {
    // write out the module properties only for composite app
    if (Boolean.valueOf(moduleProps.getProperty(ServerTags.IS_COMPOSITE))) {
        moduleProps.remove(ServerTags.IS_COMPOSITE);
        for (Iterator itr = moduleProps.keySet().iterator(); itr.hasNext(); ) {
            String propName = (String) itr.next();
            Property prop = module.createChild(Property.class);
            module.getProperty().add(prop);
            prop.setName(propName);
            prop.setValue(moduleProps.getProperty(propName));
        }
    }
    for (EngineRef ref : _getEngineRefs()) {
        Engine engine = module.createChild(Engine.class);
        module.getEngines().add(engine);
        ref.save(engine);
    }
}
Also used : Iterator(java.util.Iterator) Property(org.jvnet.hk2.config.types.Property) Engine(com.sun.enterprise.config.serverbeans.Engine)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7