Search in sources :

Example 1 with InvalidOperationException

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

the class LoginContextDriver method loginPrincipal.

/**
 * This method is used for logging in a run As principal. It creates
 * a JAAS subject whose credential is to type GSSUPName.
 * This is used primarily for runas
 */
public static void loginPrincipal(String username, String realmName) throws LoginException {
    // no realm provided, assuming default
    if (realmName == null || realmName.length() == 0) {
        realmName = Realm.getDefaultRealm();
    }
    final Subject s = new Subject();
    final org.glassfish.security.common.PrincipalImpl p = new org.glassfish.security.common.PrincipalImpl(username);
    final GSSUPName name = new GSSUPName(username, realmName);
    AppservAccessController.doPrivileged(new PrivilegedAction() {

        public java.lang.Object run() {
            s.getPrincipals().add(p);
            s.getPublicCredentials().add(name);
            return null;
        }
    });
    try {
        Realm realm = Realm.getInstance(realmName);
        Enumeration en = realm.getGroupNames(username);
        Set<Principal> principalSet = s.getPrincipals();
        while (en.hasMoreElements()) {
            principalSet.add(new Group((String) en.nextElement()));
        }
    } catch (InvalidOperationException ex) {
        _logger.log(Level.WARNING, SecurityLoggerInfo.invalidOperationForRealmError, new Object[] { username, realmName, ex.toString() });
    } catch (NoSuchUserException ex) {
        _logger.log(Level.WARNING, SecurityLoggerInfo.noSuchUserInRealmError, new Object[] { username, realmName, ex.toString() });
    } catch (NoSuchRealmException ex) {
        LoginException lex = new LoginException(ex.toString());
        lex.initCause(ex);
        throw lex;
    }
    setSecurityContext(username, s, realmName);
}
Also used : Group(org.glassfish.security.common.Group) Enumeration(java.util.Enumeration) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) Subject(javax.security.auth.Subject) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) GSSUPName(com.sun.enterprise.common.iiop.security.GSSUPName) PrivilegedAction(java.security.PrivilegedAction) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) LoginException(com.sun.enterprise.security.auth.login.common.LoginException) Realm(com.sun.enterprise.security.auth.realm.Realm) CertificateRealm(com.sun.enterprise.security.auth.realm.certificate.CertificateRealm) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal)

Example 2 with InvalidOperationException

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

the class GetGroupNamesCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    Config tmp = null;
    try {
        tmp = configs.getConfigByName(target);
    } catch (Exception ex) {
    }
    if (tmp != null) {
        config = tmp;
    }
    if (tmp == null) {
        Server targetServer = domain.getServerNamed(target);
        if (targetServer != null) {
            config = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            config = domain.getConfigNamed(cluster.getConfigRef());
        }
    }
    ActionReporter report = (ActionReporter) context.getActionReport();
    try {
        String[] list = getGroupNames(realmName, userName);
        List<String> ret = Arrays.asList(list);
        report.setActionExitCode(ExitCode.SUCCESS);
        Properties props = new Properties();
        props.put("groups", ret);
        report.setExtraProperties(props);
        report.setMessage("" + ret);
    } catch (NoSuchRealmException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (BadRealmException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (InvalidOperationException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (NoSuchUserException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) Properties(java.util.Properties) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) ActionReporter(com.sun.enterprise.v3.common.ActionReporter)

Aggregations

InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)2 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)2 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)2 GSSUPName (com.sun.enterprise.common.iiop.security.GSSUPName)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Server (com.sun.enterprise.config.serverbeans.Server)1 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)1 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)1 Realm (com.sun.enterprise.security.auth.realm.Realm)1 CertificateRealm (com.sun.enterprise.security.auth.realm.certificate.CertificateRealm)1 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)1 Principal (java.security.Principal)1 PrivilegedAction (java.security.PrivilegedAction)1 Enumeration (java.util.Enumeration)1 Properties (java.util.Properties)1 Subject (javax.security.auth.Subject)1 X500Principal (javax.security.auth.x500.X500Principal)1 Group (org.glassfish.security.common.Group)1