Search in sources :

Example 1 with NoSuchRealmException

use of com.sun.enterprise.security.auth.realm.NoSuchRealmException 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 r = realmsManager.getFromLoadedRealms(config.getName(), realmName);
    if (r != null) {
        return getGroupNames(r, 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);
            }
            r = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
            return getGroupNames(r, userName);
        }
    }
    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 2 with NoSuchRealmException

use of com.sun.enterprise.security.auth.realm.NoSuchRealmException 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 3 with NoSuchRealmException

use of com.sun.enterprise.security.auth.realm.NoSuchRealmException 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 4 with NoSuchRealmException

use of com.sun.enterprise.security.auth.realm.NoSuchRealmException in project Payara by payara.

the class SynchronizeRealmFromConfig method execute.

@Override
public void execute(AdminCommandContext context) {
    Config realConfig = null;
    try {
        realConfig = configs.getConfigByName(target);
    } catch (Exception ex) {
    }
    if (realConfig == null) {
        Server targetServer = domain.getServerNamed(target);
        if (targetServer != null) {
            realConfig = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            realConfig = domain.getConfigNamed(cluster.getConfigRef());
        }
    }
    ActionReport report = context.getActionReport();
    try {
        // TODO: can i use realConfig.equals(config) instead
        if (realConfig.getName().equals(config.getName())) {
            this.setRestartRequired(report);
            return;
        }
        // this is not an active config so try and update the backend
        // directly
        Realm r = realmsManager.getFromLoadedRealms(realConfig.getName(), realmName);
        if (r == null) {
            // realm is not loaded yet
            report.setMessage(_localStrings.getLocalString("REALM_SYNCH_SUCCESSFUL", "Synchronization of Realm {0} from Configuration Successful.", new Object[] { realmName }));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return;
        }
        // now we really need to update the realm in the backend from the config.
        realmsManager.removeFromLoadedRealms(realConfig.getName(), realmName);
        boolean done = this.instantiateRealm(realConfig, realmName);
        if (done) {
            report.setMessage(_localStrings.getLocalString("REALM_SYNCH_SUCCESSFUL", "Synchronization of Realm {0} from Configuration Successful.", new Object[] { realmName }));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return;
        }
    } catch (BadRealmException ex) {
        // throw new RuntimeException(ex);
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (NoSuchRealmException ex) {
        // throw new RuntimeException(ex);
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (Exception ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Realm(com.sun.enterprise.security.auth.realm.Realm)

Example 5 with NoSuchRealmException

use of com.sun.enterprise.security.auth.realm.NoSuchRealmException in project Payara by payara.

the class UpdateFileUser method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // 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("update.file.user.realmnotsupported", "Configured file realm {0} is not supported.", fileRealmClassName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // 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("update.file.user.keyfilenotfound", "There is no physical file associated with file realm {0}", authRealmName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    boolean exists = (new File(keyFile)).exists();
    if (!exists) {
        report.setMessage(localStrings.getLocalString("file.realm.keyfilenonexistent", "The specified physical file {0} associated with the file realm {1} does not exist.", new Object[] { keyFile, authRealmName }));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Now get all inputs ready. userid and groups are straightforward but
    // password is tricky. It is stored in the file passwordfile passed
    // through the CLI options. It is stored under the name
    // AS_ADMIN_USERPASSWORD. Fetch it from there.
    // fetchPassword(report);
    String password = userpassword;
    if (password == null && groups == null) {
        report.setMessage(localStrings.getLocalString("update.file.user.keyfilenotreadable", "None of password or groups have been specified for update," + "Password for user {0} has to be specified" + "through AS_ADMIN_USERPASSWORD property in the file specified " + "in --passwordfile option", userName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Issue 17525 Fix - Check for null passwords for admin-realm if secureadmin is enabled
    if (password != null) {
        secureAdmin = domain.getSecureAdmin();
        if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (adminService.getAuthRealmName().equals(authRealmName))) {
            if ((password.isEmpty())) {
                report.setMessage(localStrings.getLocalString("null_empty_password", "The admin user password is empty"));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // even though update-file-user is not an update to the security-service
    // do we need to make it transactional by referncing the securityservice
    // hypothetically ?.
    // TODO: check and enclose the code below inside ConfigSupport.apply(...)
    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("update.file.user.realmnotsupported", "Configured file realm {0} does not exist.", authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    // now updating user
    try {
        CreateFileUser.handleAdminGroup(authRealmName, groups);
        String[] groups1 = (groups == null) ? null : groups.toArray(new String[groups.size()]);
        fr.updateUser(userName, userName, password, groups1);
        fr.persist();
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("update.file.user.userupdatefailed", "Updating user {0} in file realm {1} failed", userName, authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) ActionReport(org.glassfish.api.ActionReport) FileRealm(com.sun.enterprise.security.auth.realm.file.FileRealm) Property(org.jvnet.hk2.config.types.Property) File(java.io.File) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException)

Aggregations

NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)13 Property (org.jvnet.hk2.config.types.Property)7 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)5 Properties (java.util.Properties)5 ActionReport (org.glassfish.api.ActionReport)5 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)4 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)4 Realm (com.sun.enterprise.security.auth.realm.Realm)4 FileRealm (com.sun.enterprise.security.auth.realm.file.FileRealm)4 Config (com.sun.enterprise.config.serverbeans.Config)3 Server (com.sun.enterprise.config.serverbeans.Server)3 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)3 Enumeration (java.util.Enumeration)3 File (java.io.File)2 LoginException (javax.security.auth.login.LoginException)2 GSSUPName (com.sun.enterprise.common.iiop.security.GSSUPName)1 DigestAlgorithmParameter (com.sun.enterprise.security.auth.digest.api.DigestAlgorithmParameter)1 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)1 CertificateRealm (com.sun.enterprise.security.auth.realm.certificate.CertificateRealm)1 DigestRealm (com.sun.enterprise.security.ee.auth.realm.DigestRealm)1