use of org.glassfish.security.common.PrincipalImpl 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;
}
use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.
the class SubjectUtil method getGroupnamesFromSubject.
/**
* Utility method to find the group names from a subject. The method assumes the group name is
* represented by {@link org.glassfish.security.common.Group Group } inside the Subject's principal set.
* @param subject the subject from which to find the username
* @return a list of strings representing the group names. The list may have more than one entry if the subject's principal set
* contains more than one Group instances, or empty entry if the subject's principal set contains no Group instances.
*/
public static List<String> getGroupnamesFromSubject(Subject subject) {
List<String> groupList = new ArrayList<String>();
Set<Group> princSet = null;
if (subject != null) {
princSet = subject.getPrincipals(Group.class);
for (PrincipalImpl g : princSet) {
String gName = g.getName();
groupList.add(gName);
}
}
return groupList;
}
use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.
the class ImpersonationServiceImpl method impersonate.
@Override
public Subject impersonate(String user, String[] groups, Subject subject, boolean virtual) throws LoginException {
// Use the supplied Subject or create a new Subject
final Subject _subject = (subject != null) ? subject : new Subject();
if (user == null || user.isEmpty()) {
return _subject;
}
// is available in open source
if (!virtual) {
throw new UnsupportedOperationException("Use of non-virtual parameter is not supported");
} else {
// Build the Subject
Set<Principal> principals = _subject.getPrincipals();
principals.add(new PrincipalImpl(user));
if (groups != null) {
for (String group : groups) {
principals.add(new Group(group));
}
}
}
// Return the impersonated Subject
return _subject;
}
use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.
the class SimpleRoleProviderTest method adminSubject.
private Subject adminSubject() {
Subject result = new Subject();
result.getPrincipals().add(new PrincipalImpl("admin"));
result.getPrincipals().add(new Group("asadmin"));
return result;
}
use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.
the class SimpleRoleProviderTest method nonAdminSubject.
private Subject nonAdminSubject() {
Subject result = new Subject();
result.getPrincipals().add(new PrincipalImpl("joe"));
result.getPrincipals().add(new Group("myGroup"));
return result;
}
Aggregations