1 package com.atlassian.seraph.util; 2 3 import com.atlassian.seraph.config.SecurityConfigFactory; 4 import com.opensymphony.user.User; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import java.util.Collection ; 8 import java.util.Collections ; 9 import java.security.Principal ; 10 11 14 public class GroupCache 15 { 16 public static final String GROUP_CACHE_KEY = "atlassian.core.util.groups.cache.key"; 17 18 23 public static Collection getGroups(HttpServletRequest request) 24 { 25 if (request == null) 26 return Collections.EMPTY_LIST; 27 28 Collection groups = (Collection ) request.getAttribute(GROUP_CACHE_KEY); 29 30 if (groups != null) 31 return groups; 32 33 User remoteUser = (User) SecurityConfigFactory.getInstance().getAuthenticator().getUser(request); 34 35 if (remoteUser == null) 36 return Collections.EMPTY_LIST; 37 38 groups = remoteUser.getGroups(); 39 request.setAttribute(GROUP_CACHE_KEY, groups); 40 return groups; 41 } 42 } 43 | Popular Tags |