FileDocCategorySizeDatePackage
SubjectDomainCombiner.javaAPI DocAndroid 1.5 API4294Wed May 06 22:41:02 BST 2009javax.security.auth

SubjectDomainCombiner

public class SubjectDomainCombiner extends Object implements DomainCombiner
Merges permissions based on code source and code signers with permissions granted to the specified {@link Subject}.
since
Android 1.0

Fields Summary
private Subject
subject
private static final AuthPermission
_GET
Constructors Summary
public SubjectDomainCombiner(Subject subject)
Creates a domain combiner for the entity provided in {@code subject}.

param
subject the entity to which this domain combiner is associated.

 //$NON-NLS-1$

                                           
       
        super();
        if (subject == null) {
            throw new NullPointerException();
        }
        this.subject = subject;
    
Methods Summary
public java.security.ProtectionDomain[]combine(java.security.ProtectionDomain[] currentDomains, java.security.ProtectionDomain[] assignedDomains)
Merges the {@code ProtectionDomain} with the {@code Principal}s associated with the subject of this {@code SubjectDomainCombiner}.

param
currentDomains the {@code ProtectionDomain}s associated with the context of the current thread. The domains must be sorted according to the execution order, the most recent residing at the beginning.
param
assignedDomains the {@code ProtectionDomain}s from the parent thread based on code source and signers.
return
a single {@code ProtectionDomain} array computed from the two provided arrays, or {@code null}.
see
ProtectionDomain

        // get array length for combining protection domains
        int len = 0;
        if (currentDomains != null) {
            len += currentDomains.length;
        }
        if (assignedDomains != null) {
            len += assignedDomains.length;
        }
        if (len == 0) {
            return null;
        }

        ProtectionDomain[] pd = new ProtectionDomain[len];

        // for each current domain substitute set of principal with subject's
        int cur = 0;
        if (currentDomains != null) {

            Set<Principal> s = subject.getPrincipals();
            Principal[] p = s.toArray(new Principal[s.size()]);

            for (cur = 0; cur < currentDomains.length; cur++) {
                ProtectionDomain newPD;
                newPD = new ProtectionDomain(currentDomains[cur].getCodeSource(),
                        currentDomains[cur].getPermissions(), currentDomains[cur]
                                .getClassLoader(), p);
                pd[cur] = newPD;
            }
        }

        // copy assigned domains
        if (assignedDomains != null) {
            System.arraycopy(assignedDomains, 0, pd, cur, assignedDomains.length);
        }

        return pd;
    
public javax.security.auth.SubjectgetSubject()
Returns the entity to which this domain combiner is associated.

return
the entity to which this domain combiner is associated.

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(_GET);
        }

        return subject;