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}.
// 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;
|