use of com.sun.enterprise.security.auth.login.common.LoginException in project Payara by payara.
the class LoginContextDriver method doClientLogin.
/**
* Perform login on the client side.
* It just simulates the login on the client side.
* The method uses the callback handlers and generates correct
* credential information that will be later sent to the server
* @param int type whether it is <i> username_password</i> or
* <i> certificate </i> based login.
* @param CallbackHandler the callback handler to gather user information.
* @exception LoginException the exception thrown by the callback handler.
*/
public static Subject doClientLogin(int type, javax.security.auth.callback.CallbackHandler jaasHandler) throws LoginException {
final javax.security.auth.callback.CallbackHandler handler = jaasHandler;
// the subject will actually be filled in with a PasswordCredential
// required by the csiv2 layer in the LoginModule.
// we create the dummy credential here and call the
// set security context. Thus, we have 2 credentials, one each for
// the csiv2 layer and the other for the RI.
final Subject subject = new Subject();
if (type == SecurityConstants.USERNAME_PASSWORD) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
lg.login();
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
postClientAuth(subject, PasswordCredential.class);
return subject;
} else if (type == SecurityConstants.CERTIFICATE) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_CERTIFICATE, subject, handler);
lg.login();
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
postClientAuth(subject, X509CertificateCredential.class);
return subject;
} else if (type == SecurityConstants.ALL) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lgup = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
LoginContext lgc = new LoginContext(SecurityConstants.CLIENT_JAAS_CERTIFICATE, subject, handler);
lgup.login();
postClientAuth(subject, PasswordCredential.class);
lgc.login();
postClientAuth(subject, X509CertificateCredential.class);
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
return subject;
} else {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
lg.login();
postClientAuth(subject, PasswordCredential.class);
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
return subject;
}
}
use of com.sun.enterprise.security.auth.login.common.LoginException in project Payara by payara.
the class LoginContextDriver method doCertificateLogin.
/**
* A special case login for handling X509CertificateCredential.
* This does not get triggered based on current RI code. See X500Login.
*/
private static void doCertificateLogin(Subject s) throws LoginException {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Processing X509 certificate login.");
}
String realm = CertificateRealm.AUTH_TYPE;
String user = null;
try {
Object obj = getPublicCredentials(s, X509CertificateCredential.class);
X509CertificateCredential xp = (X509CertificateCredential) obj;
user = xp.getAlias();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Set security context as user: " + user);
}
setSecurityContext(user, s, realm);
if (getAuditManager().isAuditOn()) {
getAuditManager().authentication(user, realm, true);
}
} catch (LoginException le) {
if (getAuditManager().isAuditOn()) {
getAuditManager().authentication(user, realm, false);
}
throw le;
}
}
use of com.sun.enterprise.security.auth.login.common.LoginException 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.login.common.LoginException in project Payara by payara.
the class LoginContextDriver method jmacLogin.
public static Subject jmacLogin(Subject subject, String identityAssertion, String realm) throws LoginException {
if (subject == null) {
subject = new Subject();
}
final Subject fs = subject;
String userName = identityAssertion;
try {
if (realm == null || "".equals(realm)) {
realm = Realm.getDefaultRealm();
}
Realm realmInst = Realm.getInstance(realm);
final Enumeration groups = realmInst.getGroupNames(userName);
if (groups != null && groups.hasMoreElements()) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
while (groups.hasMoreElements()) {
String grp = (String) groups.nextElement();
fs.getPrincipals().add(new Group(grp));
}
return fs;
}
});
}
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Exception when trying to populate groups for CallerPrincipal " + identityAssertion, ex);
}
}
return subject;
}
use of com.sun.enterprise.security.auth.login.common.LoginException in project Payara by payara.
the class J2EEKeyManager method doClientLogin.
/**
* Perform login on the client side.
* It just simulates the login on the client side.
* The method uses the callback handlers and generates correct
* credential information that will be later sent to the server
* @param int type whether it is <i> username_password</i> or
* <i> certificate </i> based login.
* @param CallbackHandler the callback handler to gather user information.
* @exception LoginException the exception thrown by the callback handler.
*/
public static Subject doClientLogin(int type, javax.security.auth.callback.CallbackHandler jaasHandler) throws LoginException {
final javax.security.auth.callback.CallbackHandler handler = jaasHandler;
// the subject will actually be filled in with a PasswordCredential
// required by the csiv2 layer in the LoginModule.
// we create the dummy credential here and call the
// set security context. Thus, we have 2 credentials, one each for
// the csiv2 layer and the other for the RI.
final Subject subject = new Subject();
// V3:Commented : TODO uncomment later for Appcontainer
if (type == SecurityConstants.USERNAME_PASSWORD) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
lg.login();
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
postClientAuth(subject, PasswordCredential.class);
return subject;
} else if (type == SecurityConstants.CERTIFICATE) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_CERTIFICATE, subject, handler);
lg.login();
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
postClientAuth(subject, X509CertificateCredential.class);
return subject;
} else if (type == SecurityConstants.ALL) {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lgup = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
LoginContext lgc = new LoginContext(SecurityConstants.CLIENT_JAAS_CERTIFICATE, subject, handler);
lgup.login();
postClientAuth(subject, PasswordCredential.class);
lgc.login();
postClientAuth(subject, X509CertificateCredential.class);
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
return subject;
} else {
AppservAccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
try {
LoginContext lg = new LoginContext(SecurityConstants.CLIENT_JAAS_PASSWORD, subject, handler);
lg.login();
postClientAuth(subject, PasswordCredential.class);
} catch (javax.security.auth.login.LoginException e) {
throw (LoginException) new LoginException(e.toString()).initCause(e);
}
return null;
}
});
return subject;
}
}
Aggregations