public int compareTo(Object t) { if (this.equals(t)) return 0; return -1; // wonder if this is sketchy } }
public GroupMemberships(String serviceURI, Principal userID) { this.serviceURI = serviceURI; this.userID = userID; init(); }
protected List<Group> getCachedGroups(Principal userID, Role role, boolean complete) { GroupMemberships mems = getGroupCache(userID); if (mems == null) return null; // no cache Boolean cacheState = mems.isComplete(role); if (!complete || Boolean.TRUE.equals(cacheState)) return mems.getMemberships(role); // caller wanted complete and we don't have that return null; }
protected GroupMemberships getGroupCache(Principal userID) { AccessControlContext acContext = AccessController.getContext(); Subject subject = Subject.getSubject(acContext); // only consult cache if the userID is of the calling subject if (userIsSubject(userID, subject)) { Set<GroupMemberships> gset = subject.getPrivateCredentials(GroupMemberships.class); if (gset == null || gset.isEmpty()) { GroupMemberships mems = new GroupMemberships(serviceID.toString(), userID); subject.getPrivateCredentials().add(mems); return mems; } GroupMemberships mems = gset.iterator().next(); // check to ensure they have the same service URI if (!serviceID.toString().equals(mems.getServiceURI())) { log.debug("Not using cache because of differing service URIs: " + "[" + serviceID.toString() + "][" + mems.getServiceURI() + "]"); return null; } return mems; } return null; // no cache }
protected void setCachedGroups(Principal userID, List<Group> groups, Role role) { GroupMemberships mems = getGroupCache(userID); if (mems == null) return; // no cache mems.add(groups, role); }
protected void clearCache() { AccessControlContext acContext = AccessController.getContext(); Subject subject = Subject.getSubject(acContext); if (subject != null) { subject.getPrivateCredentials().remove(new GroupMemberships()); } }
protected void addCachedGroup(Principal userID, Group group, Role role) { GroupMemberships mems = getGroupCache(userID); if (mems == null) return; // no cache mems.add(group, role); }
public GroupMemberships() { init(); }