use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.
the class DigestLoginModule method commit.
public final boolean commit() throws LoginException {
if (!_succeeded) {
_commitSucceeded = false;
return false;
}
PrincipalGroupFactory factory = Globals.getDefaultHabitat().getService(PrincipalGroupFactory.class);
_userPrincipal = factory.getPrincipalInstance(digestCredentials.getUserName(), digestCredentials.getRealmName());
java.util.Set principalSet = this.subject.getPrincipals();
if (!principalSet.contains(_userPrincipal)) {
principalSet.add(_userPrincipal);
}
java.util.Enumeration groupsList = getGroups(digestCredentials.getUserName());
while (groupsList.hasMoreElements()) {
java.lang.String value = (java.lang.String) groupsList.nextElement();
Group g = factory.getGroupInstance(value, digestCredentials.getRealmName());
if (!principalSet.contains(g)) {
principalSet.add(g);
}
// cleaning the slate
}
return true;
}
use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.
the class BaseCertificateLoginModule method commit.
public final boolean commit() throws LoginException {
if (!success) {
return false;
}
Set<Principal> principalSet = subject.getPrincipals();
for (int i = 0; i < groups.length; i++) {
if (groups[i] != null) {
Group g = Globals.getDefaultHabitat().<PrincipalGroupFactory>getService(PrincipalGroupFactory.class).getGroupInstance(groups[i], CertificateRealm.AUTH_TYPE);
principalSet.add(g);
}
groups[i] = null;
}
groups = null;
commitsuccess = true;
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "JAAS authentication committed.");
}
return true;
}
use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.
the class BasePasswordLoginModule method commit.
/**
* Commit the authentication.
*
* <P>Commit is called after all necessary login modules have succeeded.
* It adds (if not present) a PrincipalImpl principal and a
* LocalCredentials public credential to the Subject.
*
* @throws LoginException If commit fails.
*/
public boolean commit() throws LoginException {
if (_succeeded == false) {
return false;
}
// Add a Principal (authenticated identity) to the Subject
// Assume the user we authenticated is the PrincipalImpl [RI]
String realm_name = _currentRealm.getName();
PrincipalGroupFactory factory = Globals.getDefaultHabitat().getService(PrincipalGroupFactory.class);
if (factory != null)
_userPrincipal = factory.getPrincipalInstance(getUsername(), realm_name);
else
_userPrincipal = new PrincipalImpl(getUsername());
Set<Principal> principalSet = _subject.getPrincipals();
if (!principalSet.contains(_userPrincipal)) {
principalSet.add(_userPrincipal);
}
/* populate the group in the subject and clean out the slate at the same
* time
*/
for (int i = 0; i < _groupsList.length; i++) {
if (_groupsList[i] != null) {
Group g;
if (factory != null)
g = factory.getGroupInstance(_groupsList[i], realm_name);
else
g = new Group(_groupsList[i]);
if (!principalSet.contains(g)) {
principalSet.add(g);
}
// cleaning the slate
_groupsList[i] = null;
}
}
// In any case, clean out state.
_groupsList = null;
setUsername(null);
setPassword(null);
setPasswordChar(null);
_commitSucceeded = true;
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "JAAS authentication committed.");
}
return true;
}
Aggregations