Search in sources :

Example 1 with AuthRealm

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

the class GetGroupNamesCommand method getGroupNames.

private String[] getGroupNames(String realmName, String userName) throws NoSuchRealmException, BadRealmException, InvalidOperationException, NoSuchUserException {
    // account for updates to file-realm contents from outside this config
    // which are sharing the same keyfile
    realmsManager.refreshRealm(config.getName(), realmName);
    Realm realm = realmsManager.getFromLoadedRealms(config.getName(), realmName);
    if (realm != null) {
        return getGroupNames(realm, userName);
    }
    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);
            }
            realm = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
            return getGroupNames(realm, userName);
        }
    }
    throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", 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 2 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(WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(authRealm), e.getLocalizedMessage() });
        }
    }
    if (!goodRealms.isEmpty()) {
        String goodRealm = goodRealms.iterator().next();
        try {
            String defaultRealm = getSecurityService().getDefaultRealm();
            Realm.getInstance(defaultRealm);
            Realm.setDefaultRealm(defaultRealm);
        } catch (final Exception e) {
            AMXLoggerInfo.getLogger().log(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 3 with AuthRealm

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

the class GenericAdminAuthenticator method postConstruct.

@Override
public synchronized void postConstruct() {
    secureAdmin = domain.getSecureAdmin();
    // Ensure that the admin password is set as required
    if (as.usesFileRealm()) {
        try {
            AuthRealm ar = as.getAssociatedAuthRealm();
            if (FileRealm.class.getName().equals(ar.getClassname())) {
                String adminKeyFilePath = ar.getPropertyValue("file");
                FileRealm fr = new FileRealm(adminKeyFilePath);
                if (!fr.hasAuthenticatableUser()) {
                    ADMSEC_LOGGER.log(Level.SEVERE, AdminLoggerInfo.mSecureAdminEmptyPassword);
                    throw new IllegalStateException(ADMSEC_LOGGER.getResourceBundle().getString(AdminLoggerInfo.mSecureAdminEmptyPassword));
                }
            }
        } catch (Exception ex) {
            ADMSEC_LOGGER.log(Level.SEVERE, AdminLoggerInfo.mUnexpectedException, ex);
            throw new RuntimeException(ex);
        }
    }
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) FileRealm(com.sun.enterprise.security.auth.realm.file.FileRealm) LoginException(javax.security.auth.login.LoginException) ServerNotActiveException(java.rmi.server.ServerNotActiveException) RemoteAdminAccessException(org.glassfish.internal.api.RemoteAdminAccessException) IOException(java.io.IOException)

Example 4 with AuthRealm

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

the class VirtualServer method configureAuthRealm.

/**
 * Configures this virtual server with its authentication realm.
 *
 * Checks if this virtual server specifies any authRealm property, and if so, ensures that its value identifies a valid
 * realm.
 *
 * @param securityService The security-service element from domain.xml
 */
void configureAuthRealm(SecurityService securityService) {
    _logger.finest(() -> String.format("configureAuthRealm(securityService=%s)", securityService));
    List<Property> properties = vsBean.getProperty();
    if (properties != null && !properties.isEmpty()) {
        for (Property property : properties) {
            if (property != null && "authRealm".equals(property.getName())) {
                authRealmName = property.getValue();
                if (authRealmName != null) {
                    AuthRealm validAuthRealm = null;
                    List<AuthRealm> authRealms = securityService.getAuthRealm();
                    if (authRealms != null && authRealms.size() > 0) {
                        for (AuthRealm authRealm : authRealms) {
                            if (authRealm != null && authRealm.getName().equals(authRealmName)) {
                                _logger.config(() -> "Using realm '" + authRealmName + "' for the security service '" + securityService + "'");
                                validAuthRealm = authRealm;
                                break;
                            }
                        }
                    }
                    if (validAuthRealm == null) {
                        _logger.log(SEVERE, INVALID_AUTH_REALM, new Object[] { getID(), authRealmName });
                    }
                }
                break;
            }
        }
    }
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Property(org.jvnet.hk2.config.types.Property)

Example 5 with AuthRealm

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

the class SupportsUserManagementCommand method supportsUserManagement.

private boolean supportsUserManagement(String realmName) throws BadRealmException, NoSuchRealmException {
    Realm realm = realmsManager.getFromLoadedRealms(config.getName(), realmName);
    if (realm != null) {
        return realm.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);
            }
            realm = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
            return realm.supportsUserManagement();
        }
    }
    throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", 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)

Aggregations

AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)21 Property (org.jvnet.hk2.config.types.Property)11 Properties (java.util.Properties)6 ArrayList (java.util.ArrayList)4 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 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 LDAPRealm (com.sun.enterprise.security.auth.realm.ldap.LDAPRealm)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 Enumeration (java.util.Enumeration)1