@@ -0,0 +1,2716 @@
+package de.terrestris.shogun2.security.acl;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Aimport org.apache.log4j.Logger;%0Aimport org.springframework.security.access.hierarchicalroles.NullRoleHierarchy;%0Aimport org.springframework.security.access.hierarchicalroles.RoleHierarchy;%0Aimport org.springframework.security.acls.domain.GrantedAuthoritySid;%0Aimport org.springframework.security.acls.domain.PrincipalSid;%0Aimport org.springframework.security.acls.domain.SidRetrievalStrategyImpl;%0Aimport org.springframework.security.acls.model.Sid;%0Aimport org.springframework.security.acls.model.SidRetrievalStrategy;%0Aimport org.springframework.security.core.Authentication;%0Aimport org.springframework.security.core.GrantedAuthority;%0Aimport org.springframework.util.Assert;%0A%0Aimport de.terrestris.shogun2.model.User;%0A%0A/**%0A * This class can be used with Spring ACL as the strategy to build a SID from%0A * the current authentication object, where the principal is a SHOGun2-User%0A * object.%0A * %0A * If the principal (of the current authentication) is NOT a SHOGun2 user%0A * object, this class behaves like the default implementation%0A * %7B@link SidRetrievalStrategyImpl%7D.%0A * %0A * @author Nils B%C3%BChner%0A * %0A */%0Apublic class Shogun2SidRetrievalStrategyImpl implements SidRetrievalStrategy %7B%0A%0A%09/**%0A%09 * The Logger%0A%09 */%0A%09private static final Logger LOG = Logger%0A%09%09%09.getLogger(Shogun2SidRetrievalStrategyImpl.class);%0A%0A%09/**%0A%09 * RoleHierarchy that may be passed in.%0A%09 */%0A%09private RoleHierarchy roleHierarchy = new NullRoleHierarchy();%0A%0A%09/**%0A%09 * Default constructor%0A%09 */%0A%09public Shogun2SidRetrievalStrategyImpl() %7B%0A%09%7D%0A%0A%09public Shogun2SidRetrievalStrategyImpl(RoleHierarchy roleHierarchy) %7B%0A%09%09Assert.notNull(roleHierarchy, %22RoleHierarchy must not be null%22);%0A%09%09this.roleHierarchy = roleHierarchy;%0A%09%7D%0A%0A%09@Override%0A%09public List%3CSid%3E getSids(Authentication authentication) %7B%0A%09%09Collection%3C? extends GrantedAuthority%3E authorities = roleHierarchy%0A%09%09%09%09.getReachableGrantedAuthorities(authentication.getAuthorities());%0A%09%09List%3CSid%3E sids = new ArrayList%3CSid%3E(authorities.size() + 1);%0A%0A%09%09Object principal = authentication.getPrincipal();%0A%09%09// check if the principal is a SHOGun2 user%0A%09%09if (principal instanceof User) %7B%0A%09%09%09User shogun2User = (User) principal;%0A%09%09%09String accountName = shogun2User.getAccountName();%0A%09%09%09LOG.trace(%22Using shogun2-user's accountName to build SID: %22%0A%09%09%09%09%09+ accountName);%0A%09%09%09sids.add(new PrincipalSid(accountName));%0A%09%09%7D else %7B%0A%09%09%09// fallback to default behaviour of the default implementation%0A%09%09%09// (SidRetrievalStrategyImpl)%0A%09%09%09sids.add(new PrincipalSid(authentication));%0A%09%09%7D%0A%0A%09%09for (GrantedAuthority authority : authorities) %7B%0A%09%09%09sids.add(new GrantedAuthoritySid(authority));%0A%09%09%7D%0A%0A%09%09return sids;%0A%09%7D%0A%0A%7D%0A

Add custom SidRetrievalStrategy implementation.