Group subjectRoles = getGroupFromSubject(subject);
boolean emptyContextRoles = false;
RoleGroup userRoles = sc.getUtil().getRoles();
//Group userRoles = (Group)sc.getData().get(ROLES_IDENTIFIER);
if(userRoles == null || "true".equalsIgnoreCase(SubjectActions.getRefreshSecurityContextRoles()))
emptyContextRoles = true;
userRoles = copyGroups(userRoles, subjectRoles);
/**
* Update the roles in the SecurityContext and
* allow mapping rules be applied only if the SC roles
* and the subject roles are not the same
*/
if(subjectRoles != userRoles || emptyContextRoles)
{
MappingManager mm = sc.getMappingManager();
MappingContext<RoleGroup> mc = mm.getMappingContext(RoleGroup.class);
RoleGroup mappedUserRoles = userRoles;
if(mc != null && mc.hasModules())
{
Map<String,Object> contextMap = new HashMap<String,Object>();
contextMap.put(SecurityConstants.ROLES_IDENTIFIER, userRoles);
if(principal != null)