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