Principal userPrincipal = null;
boolean skipPropertyScopes = false;
Iterator propertiesIter = properties.iterator();
while ((userValue[0] == null) && propertiesIter.hasNext())
{
FragmentProperty fragmentProperty = (FragmentProperty)propertiesIter.next();
if (fragmentProperty.getName().equals(propName))
{
String fragmentPropertyScope = fragmentProperty.getScope();
if (fragmentPropertyScope != null)
{
if (!skipPropertyScopes)
{
// get principals
if (principals == null)
{
// get current request context subject for principals
Subject subject = JSSubject.getSubject(AccessController.getContext());
if (subject != null)
{
if (GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
{
principals = subject.getPrincipals();
}
else
{
userPrincipal = SubjectHelper.getBestPrincipal(subject, User.class);
}
}
else
{
skipPropertyScopes = true;
}
}
String fragmentPropertyScopeValue = fragmentProperty.getScopeValue();
if (userPrincipal != null)
{
// match user property scope and scope value with user principal
if (fragmentPropertyScope.equals(USER_PROPERTY_SCOPE) && userPrincipal.getName().equals(fragmentPropertyScopeValue))
{
userValue[0] = fragmentProperty.getValue();
valueFound = true;
}
}
else if (principals != null)
{
// match property scope and scope value with most specific
// principal without a value
Iterator principalsIter = principals.iterator();
while ((userValue[0] == null) && principalsIter.hasNext())
{
Principal principal = (Principal)principalsIter.next();
if (principal.getName().equals(fragmentPropertyScopeValue))
{
if (fragmentPropertyScope.equals(USER_PROPERTY_SCOPE) && (principal instanceof User))
{
userValue[0] = fragmentProperty.getValue();
valueFound = true;
}
else if (groupValue[0] == null)
{
if (fragmentPropertyScope.equals(GROUP_PROPERTY_SCOPE) && (principal instanceof Group))
{
groupValue[0] = fragmentProperty.getValue();
valueFound = true;
}
else if (roleValue[0] == null)
{
if (fragmentPropertyScope.equals(ROLE_PROPERTY_SCOPE) && (principal instanceof Role))
{
roleValue[0] = fragmentProperty.getValue();
valueFound = true;
}
}
}
}
}
}
}
}
else if ((groupValue[0] == null) && (roleValue[0] == null) && (globalValue[0] == null))
{
globalValue[0] = fragmentProperty.getValue();
valueFound = true;
}
}
}