本文整理汇总了Java中javax.security.auth.SubjectDomainCombiner.combine方法的典型用法代码示例。如果您正苦于以下问题:Java SubjectDomainCombiner.combine方法的具体用法?Java SubjectDomainCombiner.combine怎么用?Java SubjectDomainCombiner.combine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.SubjectDomainCombiner
的用法示例。
在下文中一共展示了SubjectDomainCombiner.combine方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
public static void main(String[] args) {
ProtectionDomain pd1 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions(),
null, null);
ProtectionDomain pd2 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions(),
null, null);
ProtectionDomain pd3 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions(),
null, null);
ProtectionDomain[] current = new ProtectionDomain[] {pd1, pd2};
ProtectionDomain[] assigned = new ProtectionDomain[] {pd3, pd2};
SubjectDomainCombiner sdc = new SubjectDomainCombiner(new Subject());
ProtectionDomain[] combined = sdc.combine(current, assigned);
// this depends on current SubjectDomainCombiner implementation
// (ordering of returned domains)
if (combined.length == 4 &&
combined[0] != pd1 && combined[1] != pd2 &&
combined[2] == pd3 && combined[3] == pd2) {
System.out.println("test passed");
} else {
System.out.println("test failed");
throw new SecurityException("Test Failed");
}
}
示例2: main
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
public static void main(String[] args) {
ProtectionDomain pd1 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions());
ProtectionDomain pd2 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions());
ProtectionDomain pd3 = new ProtectionDomain(
new CodeSource(null, (java.security.cert.Certificate[]) null),
new Permissions());
ProtectionDomain[] current = new ProtectionDomain[] {pd1, pd2};
ProtectionDomain[] assigned = new ProtectionDomain[] {pd3, pd2};
SubjectDomainCombiner sdc = new SubjectDomainCombiner(new Subject());
ProtectionDomain[] combined = sdc.combine(current, assigned);
// this depends on current SubjectDomainCombiner implementation
// (ordering of returned domains)
if (combined.length == 4 &&
combined[0] != pd1 && combined[1] != pd2 &&
combined[2] == pd3 && combined[3] == pd2) {
System.out.println("test passed");
} else {
System.out.println("test failed");
throw new SecurityException("Test Failed");
}
}
示例3: test_combine_02
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
/**
* @tests javax.security.auth.SubjectDomainCombiner#combine()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "assignedDomains is null",
method = "combine",
args = {ProtectionDomain[].class, ProtectionDomain[].class}
)
public void test_combine_02() {
URL url;
try {
url = new URL(locationUrl);
} catch (MalformedURLException mue) {
throw new Error(mue);
}
CodeSource cs = new CodeSource(url, (java.security.cert.Certificate[])null);
class MyClassLoader extends ClassLoader {
public MyClassLoader() {
super();
}
}
ClassLoader current_pd_cl = new MyClassLoader() ;
ClassLoader assigned_pd_cl = new MyClassLoader() ;
// current domains
ProtectionDomain[] current_pd = createProtectionDomains(cs, current_pd_cl, currentDomainX500names, currentDomainPerms);
// assigned domains
ProtectionDomain[] assigned_pd = null;
// subject
Subject s = createSubject();
// combine
SubjectDomainCombiner c = new SubjectDomainCombiner(s);
ProtectionDomain[] r_pd = c.combine(current_pd, assigned_pd);
if(DEBUG) {
System.out.println("=========== c_pd");
dumpPD(current_pd);
System.out.println("=========== a_pd");
dumpPD(assigned_pd);
System.out.println("=========== r_pd");
dumpPD(r_pd);
System.out.println("===========");
}
for(int i = 0; i < r_pd.length; i++) {
ProtectionDomain pd = r_pd[i];
// check CodeSource
assertTrue("code source mismatch", pd.getCodeSource().equals(cs));
// check ClassLoader
assertTrue("class loader mismatch", pd.getClassLoader().equals(current_pd_cl));
// check principals
Principal[] principals = pd.getPrincipals();
for(int j = 0; j < principals.length; j++) {
if(contains(SubjectX500names, principals[j].getName()) == false)
fail("principal mismatch (" + j +") " + principals[j].getName());
}
// check permissions
PermissionCollection perms = pd.getPermissions();
Enumeration<Permission> p = perms.elements();
while(p.hasMoreElements()) {
Permission pp = p.nextElement();
String pn = pp.getName();
if(contains(currentDomainPerms, pn) == false)
fail("current domains permissions mismatch " + pn);
}
}
}
示例4: test_combine_03
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
/**
* @tests javax.security.auth.SubjectDomainCombiner#combine()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "currentDomains is null",
method = "combine",
args = {ProtectionDomain[].class, ProtectionDomain[].class}
)
public void test_combine_03() {
URL url;
try {
url = new URL(locationUrl);
} catch (MalformedURLException mue) {
throw new Error(mue);
}
CodeSource cs = new CodeSource(url, (java.security.cert.Certificate[])null);
class MyClassLoader extends ClassLoader {
public MyClassLoader() {
super();
}
}
ClassLoader current_pd_cl = new MyClassLoader() ;
ClassLoader assigned_pd_cl = new MyClassLoader() ;
// current domains
ProtectionDomain[] current_pd = null;
// assigned domains
ProtectionDomain[] assigned_pd = createProtectionDomains(cs, assigned_pd_cl, assignedDomainX500names, assignedDomainPerms);
// subject
Subject s = createSubject();
// combine
SubjectDomainCombiner c = new SubjectDomainCombiner(s);
ProtectionDomain[] r_pd = c.combine(current_pd, assigned_pd);
if(DEBUG) {
System.out.println("=========== c_pd");
dumpPD(current_pd);
System.out.println("=========== a_pd");
dumpPD(assigned_pd);
System.out.println("=========== r_pd");
dumpPD(r_pd);
System.out.println("===========");
}
for(int i = 0; i < r_pd.length; i++) {
ProtectionDomain pd = r_pd[i];
// check CodeSource
assertTrue("code source mismatch", pd.getCodeSource().equals(cs));
// check ClassLoader
assertTrue("class loader mismatch", pd.getClassLoader().equals(assigned_pd_cl));
// check principals
Principal[] principals = pd.getPrincipals();
for(int j = 0; j < principals.length; j++) {
if(contains(assignedDomainX500names, principals[j].getName()) == false)
fail("principal mismatch (" + j +") " + principals[j].getName());
}
// check permissions
PermissionCollection perms = pd.getPermissions();
Enumeration<Permission> p = perms.elements();
while(p.hasMoreElements()) {
Permission pp = p.nextElement();
String pn = pp.getName();
if(contains(assignedDomainPerms, pn) == false)
fail("assigned domains permissions mismatch " + pn);
}
}
}
示例5: testCombine
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
/**
* @tests javax.security.auth.SubjectDomainCombiner#combine(ProtectionDomain[],
* ProtectionDomain[])
*/
public final void testCombine() throws Exception {
Principal principal = new Principal() {
public String getName() {
return "principal";
}
};
Subject subject = new Subject();
subject.getPrincipals().add(principal);
SubjectDomainCombiner combiner = new SubjectDomainCombiner(subject);
ProtectionDomain[] pd;
// test case: both parameters are null
assertNull(combiner.combine(null, null));
// test case: check assigned principals
URL url = new URL("file://foo.txt");
CodeSource source = new CodeSource(url, (Certificate[]) null);
PermissionCollection permissions = new Permissions();
ClassLoader classLoader = new URLClassLoader(new URL[] { url });
Principal p = new Principal() {
public String getName() {
return "p";
}
};
Principal[] principals = new Principal[] { p };
ProtectionDomain domain = new ProtectionDomain(source, permissions,
classLoader, principals);
pd = combiner.combine(new ProtectionDomain[] { domain }, null);
assertSame("CodeSource", source, pd[0].getCodeSource());
assertSame("PermissionCollection", permissions, pd[0]
.getPermissions());
assertSame("ClassLoader", classLoader, pd[0].getClassLoader());
assertEquals("Size", 1, pd[0].getPrincipals().length);
assertSame("Principal", principal, (pd[0].getPrincipals())[0]);
// test case: check inherited domains
pd = combiner.combine(null, new ProtectionDomain[] { domain });
assertSame("Inherited domain", domain, pd[0]);
//Regression for HARMONY-1129
assertNotNull(new SubjectDomainCombiner(new Subject()).combine(new ProtectionDomain[] {null}, new ProtectionDomain[] {null}));
}
示例6: testCombine
import javax.security.auth.SubjectDomainCombiner; //导入方法依赖的package包/类
/**
* @tests javax.security.auth.SubjectDomainCombiner#combine(ProtectionDomain[],
* ProtectionDomain[])
*/
public final void testCombine() throws Exception {
Principal principal = new Principal() {
public String getName() {
return "principal";
}
};
Subject subject = new Subject();
subject.getPrincipals().add(principal);
SubjectDomainCombiner combiner = new SubjectDomainCombiner(subject);
ProtectionDomain[] pd;
// test case: both parameters are null
assertNull(combiner.combine(null, null));
// test case: check assigned principals
URL url = new URL("file://foo.txt");
CodeSource source = new CodeSource(url, (Certificate[]) null);
PermissionCollection permissions = new Permissions();
ClassLoader classLoader = new URLClassLoader(new URL[] { url });
Principal p = new Principal() {
public String getName() {
return "p";
}
};
Principal[] principals = new Principal[] { p };
ProtectionDomain domain = new ProtectionDomain(source, permissions,
classLoader, principals);
pd = combiner.combine(new ProtectionDomain[] { domain }, null);
assertSame("CodeSource", source, pd[0].getCodeSource());
assertSame("PermissionCollection", permissions, pd[0]
.getPermissions());
assertSame("ClassLoader", classLoader, pd[0].getClassLoader());
assertEquals("Size", 1, pd[0].getPrincipals().length);
assertSame("Principal", principal, (pd[0].getPrincipals())[0]);
// test case: check inherited domains
pd = combiner.combine(null, new ProtectionDomain[] { domain });
assertSame("Inherited domain", domain, pd[0]);
}