Search in sources :

Example 6 with AuthRealm

use of com.sun.enterprise.config.serverbeans.AuthRealm 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 7 with AuthRealm

use of com.sun.enterprise.config.serverbeans.AuthRealm 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 8 with AuthRealm

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

the class EmbeddedSecurityUtil method getKeyFileNames.

public List<String> getKeyFileNames(SecurityService securityService) {
    List<String> keyFileNames = new ArrayList<String>();
    List<AuthRealm> authRealms = securityService.getAuthRealm();
    for (AuthRealm authRealm : authRealms) {
        String className = authRealm.getClassname();
        if ("com.sun.enterprise.security.auth.realm.file.FileRealm".equals(className)) {
            List<Property> props = authRealm.getProperty();
            for (Property prop : props) {
                if ("file".equals(prop.getName())) {
                    keyFileNames.add(prop.getValue());
                }
            }
        }
    }
    return keyFileNames;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) ArrayList(java.util.ArrayList) Property(org.jvnet.hk2.config.types.Property)

Example 9 with AuthRealm

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

the class SecureAdminHelperImpl method adminRealm.

private FileRealm adminRealm() throws BadRealmException, NoSuchRealmException {
    final AuthRealm ar = as.getAssociatedAuthRealm();
    if (FileRealm.class.getName().equals(ar.getClassname())) {
        String adminKeyFilePath = ar.getPropertyValue("file");
        FileRealm fr = new FileRealm(adminKeyFilePath);
        return fr;
    }
    return null;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) FileRealm(com.sun.enterprise.security.auth.realm.file.FileRealm)

Example 10 with AuthRealm

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

the class RealmConfig method createRealms.

public static void createRealms(String defaultRealm, List<AuthRealm> realms, String configName) {
    assert (realms != null);
    // need at least one good realm
    String goodRealm = null;
    for (AuthRealm aRealm : realms) {
        String realmName = aRealm.getName();
        String realmClass = aRealm.getClassname();
        assert (realmName != null);
        assert (realmClass != null);
        try {
            List<Property> realmProps = aRealm.getProperty();
            /*V3 Commented ElementProperty[] realmProps =
                    aRealm.getElementProperty();*/
            Properties props = new Properties();
            for (Property realmProp : realmProps) {
                props.setProperty(realmProp.getName(), realmProp.getValue());
            }
            Realm.instantiate(realmName, realmClass, props, configName);
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Configured realm: " + realmName);
            }
            if (goodRealm == null) {
                goodRealm = realmName;
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, SecurityLoggerInfo.realmConfigDisabledError, realmName);
            logger.log(Level.WARNING, SecurityLoggerInfo.securityExceptionError, e);
        }
    }
    if (goodRealm == null) {
        logger.severe(SecurityLoggerInfo.noRealmsError);
    } else {
        try {
            Realm.getInstance(defaultRealm);
        } catch (Exception e) {
            defaultRealm = goodRealm;
        }
        Realm.setDefaultRealm(defaultRealm);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Default realm is set to: " + defaultRealm);
        }
    }
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property)

Aggregations

AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)18 Property (org.jvnet.hk2.config.types.Property)10 Properties (java.util.Properties)6 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)3 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)3 FileRealm (com.sun.enterprise.security.auth.realm.file.FileRealm)3 ArrayList (java.util.ArrayList)3 ActionReport (org.glassfish.api.ActionReport)3 Config (com.sun.enterprise.config.serverbeans.Config)2 Realm (com.sun.enterprise.security.auth.realm.Realm)2 IOException (java.io.IOException)2 ServerNotActiveException (java.rmi.server.ServerNotActiveException)2 LoginException (javax.security.auth.login.LoginException)2 RemoteAdminAccessException (org.glassfish.internal.api.RemoteAdminAccessException)2 Domain (com.sun.enterprise.config.serverbeans.Domain)1 FileRealmUser (com.sun.enterprise.security.auth.realm.file.FileRealmUser)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1