Skip to content
GMSClient.java 42 KiB
Newer Older
        // lazy init
        if (this.mySocketFactory == null)
        {
            log.debug("getSSLSocketFactory: " + s);
            this.mySocketFactory = SSLUtil.getSocketFactory(s);
            this.subjectHashCode = s.hashCode();
        }
        else
            int c = s.hashCode();
            if (c != subjectHashCode)
                throw new IllegalStateException("Illegal use of "
                        + this.getClass().getSimpleName()
                        + ": subject change not supported for internal SSLSocketFactory");
    protected void clearCache()
    {
        AccessControlContext acContext = AccessController.getContext();
        Subject subject = Subject.getSubject(acContext);
        if (subject != null)
        {
            subject.getPrivateCredentials().remove(new GroupMemberships());
    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;

            // 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() + "]");
    protected Group getCachedGroup(Principal userID, String groupID, Role role)
        List<Group> groups = getCachedGroups(userID, role, false);
        if (groups == null)
            return null; // no cache
        for (Group g : groups)
        {
            if (g.getID().getName().equals(groupID))
        }
        return null;
    }
    protected List<Group> getCachedGroups(Principal userID, Role role, boolean complete)
        GroupMemberships mems = getGroupCache(userID);
        Boolean cacheState = mems.isComplete(role);
        if (!complete || Boolean.TRUE.equals(cacheState))
    protected void addCachedGroup(Principal userID, Group group, Role role)
        GroupMemberships mems = getGroupCache(userID);
Patrick Dowler's avatar
Patrick Dowler committed
        mems.add(group, role);
    protected void setCachedGroups(Principal userID, List<Group> groups, Role role)
        GroupMemberships mems = getGroupCache(userID);
Patrick Dowler's avatar
Patrick Dowler committed
        mems.add(groups, role);
    protected boolean userIsSubject(Principal userID, Subject subject)
    {
        if (userID == null || subject == null)
        {
            return false;
        }
Dustin Jenkins's avatar
Dustin Jenkins committed
        for (Principal subjectPrincipal : subject.getPrincipals())
            if (AuthenticationUtil.equals(subjectPrincipal, userID))
        return false;
    protected RegistryClient getRegistryClient()
    {
        return new RegistryClient();
    }

Dustin Jenkins's avatar
Dustin Jenkins committed
    private AuthMethod getAuthMethod()
    {
        Subject subject = AuthenticationUtil.getCurrentSubject();
        if (subject != null)
        {
            for (Object o : subject.getPublicCredentials())
            {
                if (o instanceof X509CertificateChain)
                    return AuthMethod.CERT;
                if (o instanceof SSOCookieCredential)
                    return AuthMethod.COOKIE;
                // AuthMethod.PASSWORD not supported
                // AuthMethod.TOKEN not supported
            }
        }
        return AuthMethod.ANON;
    }