List<IPentahoRole> userRoles = userRoleDao.getUserRoles( null, username );
int authsSize = userRoles != null ? userRoles.size() : 0;
GrantedAuthority[] auths = new GrantedAuthority[authsSize];
int i = 0;
for ( IPentahoRole role : userRoles ) {
auths[i++] = new GrantedAuthorityImpl( role.getName() );
}
List<GrantedAuthority> dbAuths = new ArrayList<GrantedAuthority>( Arrays.asList( auths ) );
addCustomAuthorities( user.getUsername(), dbAuths );
// Store the Tenant ID in the session
IPentahoSession session = PentahoSessionHolder.getSession();
String tenantId = (String) session.getAttribute( IPentahoSession.TENANT_ID_KEY );
if ( tenantId == null ) {
ITenant tenant = JcrTenantUtils.getTenant( username, true );
session.setAttribute( IPentahoSession.TENANT_ID_KEY, tenant.getId() );
}
if ( !StringUtils.isEmpty( defaultRoleString ) ) {
defaultRole = new GrantedAuthorityImpl( defaultRoleString );
}
if ( defaultRole != null && !dbAuths.contains( defaultRole ) ) {
dbAuths.add( defaultRole );
}