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);
}
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);
}
}
Aggregations