mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- add TenantService hooks to org.alfresco.repo.security services
- Authentication, Person, Permission, Authority - add user/tenant-based logging via log4j NDC (nested diagnostic context) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6399 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,7 +35,9 @@ import net.sf.acegisecurity.context.security.SecureContextImpl;
|
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import net.sf.acegisecurity.providers.dao.User;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.apache.log4j.NDC;
|
||||
|
||||
public abstract class AuthenticationUtil
|
||||
{
|
||||
@@ -151,8 +153,33 @@ public abstract class AuthenticationUtil
|
||||
}
|
||||
authentication.setAuthenticated(true);
|
||||
sc.setAuthentication(authentication);
|
||||
|
||||
// Support for logging tenant domain / username (via log4j NDC)
|
||||
String userName = SYSTEM_USER_NAME;
|
||||
if (authentication.getPrincipal() instanceof UserDetails)
|
||||
{
|
||||
userName = ((UserDetails) authentication.getPrincipal()).getUsername();
|
||||
}
|
||||
|
||||
logNDC(userName);
|
||||
|
||||
return authentication;
|
||||
}
|
||||
|
||||
public static void logNDC(String userName)
|
||||
{
|
||||
NDC.remove();
|
||||
|
||||
int idx = userName.indexOf(TenantService.SEPARATOR);
|
||||
if ((idx != -1) && (idx < (userName.length()-1)))
|
||||
{
|
||||
NDC.push("Tenant:"+userName.substring(idx+1)+" User:"+userName.substring(0,idx));
|
||||
}
|
||||
else
|
||||
{
|
||||
NDC.push("User:"+userName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current authentication context
|
||||
|
Reference in New Issue
Block a user