Search in sources :

Example 16 with AuthRealm

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

the class RealmsImpl method getAnonymousUser.

public String getAnonymousUser() {
    final Domain domain = InjectedValues.getInstance().getHabitat().getService(Domain.class);
    final List<Config> configs = domain.getConfigs().getConfig();
    // find the ADMIN_REALM
    AuthRealm adminFileAuthRealm = null;
    for (final Config config : configs) {
        if (config.getSecurityService() == null)
            continue;
        for (final 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
    final 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;
    }
    Property keyfileProp = adminFileAuthRealm.getProperty("file");
    if (keyfileProp == null) {
        throw new IllegalStateException("Cannot find property 'file'");
    }
    final String keyFile = keyfileProp.getValue();
    if (keyFile == null) {
        throw new IllegalStateException("Cannot find key file");
    }
    // System.out.println( "############### keyFile: " + keyFile);
    String user = null;
    final String[] usernames = getUserNames(adminFileAuthRealm.getName());
    if (usernames.length == 1) {
        try {
            InjectedValues.getInstance().getHabitat().getService(com.sun.enterprise.security.SecurityLifecycle.class);
            LoginContextDriver.login(usernames[0], new char[0], ADMIN_REALM);
            user = usernames[0];
        } catch (final Exception e) {
        // e.printStackTrace();
        }
    }
    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 17 with AuthRealm

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

the class RealmsImpl method getConfiguredRealmNames.

/**
 * realm names as found in configuration; some might be defective and unable to be loaded
 */
private Set<String> getConfiguredRealmNames() {
    Set<String> names = new HashSet<String>();
    List<AuthRealm> realms = getAuthRealms();
    for (AuthRealm realm : realms) {
        names.add(realm.getName());
    }
    return names;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) HashSet(java.util.HashSet)

Example 18 with AuthRealm

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

the class SecurityUtil method _loadRealms.

private void _loadRealms() {
    List<AuthRealm> authRealmConfigs = getSecurityService().getAuthRealm();
    List<String> goodRealms = new ArrayList<String>();
    for (AuthRealm authRealm : authRealmConfigs) {
        List<Property> propConfigs = authRealm.getProperty();
        Properties props = new Properties();
        for (Property p : propConfigs) {
            String value = p.getValue();
            props.setProperty(p.getName(), value);
        }
        try {
            Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props);
            goodRealms.add(authRealm.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (!goodRealms.isEmpty()) {
        // not used String goodRealm = goodRealms.iterator().next();
        try {
            String defaultRealm = getSecurityService().getDefaultRealm();
            /*Realm r = */
            Realm.getInstance(defaultRealm);
            Realm.setDefaultRealm(defaultRealm);
        } catch (Exception e) {
            Realm.setDefaultRealm(goodRealms.iterator().next());
            e.printStackTrace();
        }
    }
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) ArrayList(java.util.ArrayList) 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