use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.
the class PermissionServiceImpl method getDynamicAuthorities.
protected Set<String> getDynamicAuthorities(Authentication auth, NodeRef nodeRef, PermissionReference required) {
Set<String> dynAuths = new HashSet<String>(64);
User user = (User) auth.getPrincipal();
String username = user.getUsername();
nodeRef = tenantService.getName(nodeRef);
if (nodeRef != null) {
if (dynamicAuthorities != null) {
for (DynamicAuthority da : dynamicAuthorities) {
Set<PermissionReference> requiredFor = da.requiredFor();
if ((requiredFor == null) || (requiredFor.contains(required))) {
if (da.hasAuthority(nodeRef, username)) {
dynAuths.add(da.getAuthority());
}
}
}
}
}
return dynAuths;
}
use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.
the class TestAuthenticationServiceImpl method setCurrentUser.
/**
* Explicitly set the current user to be authenticated.
*
* @param userName
* String
* @return Authentication
*/
public Authentication setCurrentUser(String userName) throws AuthenticationException {
if (userName == null) {
throw new AuthenticationException("Null user name");
}
try {
UserDetails ud = null;
if (userName.equals(SYSTEM_USER_NAME)) {
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_SYSTEM");
ud = new User(SYSTEM_USER_NAME, "", true, true, true, true, gas);
} else if (userName.equalsIgnoreCase(AuthenticationUtil.getGuestUserName())) {
GrantedAuthority[] gas = new GrantedAuthority[0];
ud = new User(AuthenticationUtil.getGuestUserName().toLowerCase(), "", true, true, true, true, gas);
} else {
ud = getUserDetails(userName);
}
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
auth.setDetails(ud);
auth.setAuthenticated(true);
return setCurrentAuthentication(auth);
} catch (net.sf.acegisecurity.AuthenticationException ae) {
throw new AuthenticationException(ae.getMessage(), ae);
}
}
Aggregations