当前位置: 首页>>代码示例>>Java>>正文


Java SubjectDomainCombiner类代码示例

本文整理汇总了Java中javax.security.auth.SubjectDomainCombiner的典型用法代码示例。如果您正苦于以下问题:Java SubjectDomainCombiner类的具体用法?Java SubjectDomainCombiner怎么用?Java SubjectDomainCombiner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SubjectDomainCombiner类属于javax.security.auth包,在下文中一共展示了SubjectDomainCombiner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCallerPrincipal

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
@Override
public Principal getCallerPrincipal() {
    Principal principal = sessionContext.getCallerPrincipal();
    if (principal.getName().equalsIgnoreCase(ANONYMOUS)) {
        AccessControlContext accessControlContext = AccessController.getContext();
        DomainCombiner dc = accessControlContext.getDomainCombiner();
        if (dc instanceof SubjectDomainCombiner) {
            SubjectDomainCombiner sdc = (SubjectDomainCombiner) dc;
            Set<Principal> principals = sdc.getSubject().getPrincipals();
            if (principals != null && principals.size() > 0) {
                return principals.iterator().next();
            }
        }
    }
    return principal;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:17,代码来源:UserContextBean.java

示例2: test_Constructor_01

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests javax.security.auth.SubjectDomainCombiner#SubjectDomainCombiner(Subject subject)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "SubjectDomainCombiner",
    args = {Subject.class}
)
public void test_Constructor_01() {
    Subject s = new Subject();
    SubjectDomainCombiner c = new SubjectDomainCombiner(s);

    try {
        assertEquals(s, c.getSubject());
    } catch(SecurityException se) {

    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:SubjectDomainCombinerTest.java

示例3: testContextUsage_0

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * Tests context usage.
 * Case 0: If no Config provided by user, then LoginContext uses 
 * its own context to invoke LoginModule's methods.
 */
public void testContextUsage_0() throws Exception {
    Subject dummySubj = new Subject();
    final DomainCombiner dc = new SubjectDomainCombiner(dummySubj);
    AccessControlContext acc = new AccessControlContext(AccessController
            .getContext(), dc);
    PrivilegedExceptionAction<Void> action = new PrivilegedExceptionAction<Void>() {
        public Void run() throws Exception {
            implTestContextUsage(true, dc);
            return null;
        }
    };
    AccessController.doPrivileged(action, acc);
    // additional cleanup to make it PerfTests compatible
    clear();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:LoginContext1Test.java

示例4: testContextUsage_1

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * Tests context usage.
 * Case 1: If Config was provided by user, then LoginContext 
 * uses stored user's context and performs all call to LoginModule's 
 * methods in that context.
 */
public void testContextUsage_1() throws Exception {
    Subject dummySubj = new Subject();
    final DomainCombiner dc = new SubjectDomainCombiner(dummySubj);
    AccessControlContext acc = new AccessControlContext(AccessController
            .getContext(), dc);
    PrivilegedExceptionAction<Void> action = new PrivilegedExceptionAction<Void>() {
        public Void run() throws Exception {
            implTestContextUsage(false, dc);
            return null;
        }
    };
    AccessController.doPrivileged(action, acc);
    // additional cleanup to make it PerfTests compatible
    clear();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:LoginContext1Test.java

示例5: test_ConstructorLjavax_security_auth_Subject

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests javax.security.auth.SubjectDomainCombiner#SubjectDomainCombiner(
 *        javax.security.auth.Subject)
 */
public final void test_ConstructorLjavax_security_auth_Subject() {

    Subject subject = new Subject();

    SubjectDomainCombiner combiner = new SubjectDomainCombiner(subject);

    assertSame("Subject", subject, combiner.getSubject());

    try {
        // Regression for HARMONY-219
        new SubjectDomainCombiner(null);
        fail("Constructor should throw NullPointerException");
    } catch (NullPointerException e) {
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SubjectDomainCombinerTest.java

示例6: 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");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:Optimize.java

示例7: processAsyncRequestMessage

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * Processes a request message.
 * 
 * @param requestMessage
 *            request to process
 */
protected void processAsyncRequestMessage(final AsyncRequestMessage requestMessage) {
    Principal userPrincipal = requestMessage.getUserPrincipal();
    logger.debug("user principal: " + userPrincipal);
    logger.debug("request id: " + requestMessage.getRequestId());
    AsyncRequest request = asyncRequestDaoBean.findById(requestMessage.getRequestId());
    if (request == null) {
        logger.debug("No such request: " + requestMessage.getRequestId());
        return;
    }
    if (request.getResult() != null) {
        logger.debug("There is already prepared a result for this request: " + requestMessage.getRequestId());
        return;
    }
    Set<Principal> principals = new HashSet<Principal>();
    principals.add(userPrincipal);
    Subject subject = new Subject(false, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
    AccessControlContext ctx = new AccessControlContext(AccessController.getContext(), new SubjectDomainCombiner(
            subject));
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

            public Void run() {
                dispatchMessage(requestMessage);
                return null;
            }
        }, ctx);
    } catch (PrivilegedActionException e) {
        logger.error("Dispatching the result as a user " + userPrincipal + " failed!", e);
        throw new WrdzRuntimeException(e);
    }

}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:39,代码来源:AsyncMessageDrivenBean.java

示例8: 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");
        }
    }
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:30,代码来源:Optimize.java

示例9: createContext

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
private static AccessControlContext createContext(
    Subject subject, AccessControlContext context
) {
  return AccessController.doPrivileged((PrivilegedAction<AccessControlContext>) () -> {
    AccessControlContext accessControlContext;
    if (subject == null) {
      accessControlContext = new AccessControlContext(context, null);
    } else {
      accessControlContext = new AccessControlContext(context,
          new CustomCombiner(new SubjectDomainCombiner(subject), subject)
      );
    }
    return accessControlContext;
  });
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:16,代码来源:SecurityUtil.java

示例10: test_getDomainCombiner

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests java.security.AccessControlException#getDomainCombiner()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    method = "getDomainCombiner",
    args = {}
)
public void test_getDomainCombiner() {
    AccessControlContext context = AccessController.getContext();

    AccessControlContext acc1 = new AccessControlContext(context, null);

    AccessControlContext acc2 = new AccessControlContext(context,
            new SubjectDomainCombiner(new Subject()));

    final Permission perm1 = new PropertyPermission("java.class.path",
            "read");

    PermissionCollection col1 = perm1.newPermissionCollection();
    col1.add(perm1);
    final ProtectionDomain pd1 = new ProtectionDomain(null, col1);
    AccessControlContext acc3 = new AccessControlContext(
            new ProtectionDomain[] { pd1 });

    assertNull(acc1.getDomainCombiner());
    assertNotNull(acc2.getDomainCombiner());
    assertNull(acc3.getDomainCombiner());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:30,代码来源:AccessControlContextTest.java

示例11: test_getSubject_01

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests javax.security.auth.SubjectDomainCombiner#getSubject()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Verifies that Subject associated with this SubjectDomainCombiner is returned",
    method = "getSubject",
    args = {}
)
public void test_getSubject_01() {
    Subject s = new Subject();
    SubjectDomainCombiner c = new SubjectDomainCombiner(s);

    assertEquals(s, c.getSubject());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:16,代码来源:SubjectDomainCombinerTest.java

示例12: testSecurityException

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
public final void testSecurityException() {

        denyPermission(new AuthPermission("getSubjectFromDomainCombiner"));

        try {
            new SubjectDomainCombiner(new Subject()).getSubject();
        } catch (AccessControlException e) {
            assertEquals(e, AuthPermission.class);
        }
    }
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:SubjectDomainCombinerTest.java

示例13: test_equals

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests java.security.AccessControlException#equals()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "equals",
    args = {java.lang.Object.class}
)
public void test_equals() {
    final Permission perm1 = new PropertyPermission("java.class.path",
            "read");
    final Permission perm2 = new PropertyPermission("java.path", "write");

    PermissionCollection col1 = perm1.newPermissionCollection();
    col1.add(perm1);
    final ProtectionDomain pd1 = new ProtectionDomain(null, col1);
    AccessControlContext acc1 = new AccessControlContext(
            new ProtectionDomain[] { pd1 });

    AccessControlContext acc2 = new AccessControlContext(
            new ProtectionDomain[] { pd1 });

    PermissionCollection col2 = perm2.newPermissionCollection();
    col2.add(perm2);
    col2.add(perm2);
    final ProtectionDomain pd2 = new ProtectionDomain(null, col2);
    AccessControlContext acc3 = new AccessControlContext(
            new ProtectionDomain[] { pd2 });

    assertFalse(acc1.equals(null));
    assertFalse(acc2.equals(null));
    assertFalse(acc3.equals(null));

    assertTrue(acc1.equals(acc2));
    assertTrue(acc2.equals(acc1));
    assertFalse(acc1.equals(acc3));
    assertFalse(acc2.equals(acc3));

    AccessControlContext context = AccessController.getContext();

    AccessControlContext acc4 = new AccessControlContext(context, null);
    AccessControlContext acc5 = new AccessControlContext(context,
            new SubjectDomainCombiner(new Subject()));

    AccessControlContext acc6 = new AccessControlContext(context, null);

    assertFalse(acc4.equals(null));
    assertFalse(acc5.equals(null));

    assertFalse(acc4.equals(acc5));
    assertFalse(acc5.equals(acc4));

    assertTrue(acc4.equals(acc6));
    assertTrue(acc6.equals(acc4));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:57,代码来源:AccessControlContextTest.java

示例14: test_hashCode

import javax.security.auth.SubjectDomainCombiner; //导入依赖的package包/类
/**
 * @tests java.security.AccessControlException#hashCode()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "hashCode",
    args = {}
)
public void test_hashCode() {
    final Permission perm1 = new PropertyPermission("java.class.path",
            "read");
    final Permission perm2 = new PropertyPermission("java.path", "write");

    PermissionCollection col1 = perm1.newPermissionCollection();
    col1.add(perm1);
    final ProtectionDomain pd1 = new ProtectionDomain(null, col1);
    AccessControlContext acc1 = new AccessControlContext(
            new ProtectionDomain[] { pd1 });

    AccessControlContext acc2 = new AccessControlContext(
            new ProtectionDomain[] { pd1 });

    PermissionCollection col2 = perm2.newPermissionCollection();
    col2.add(perm2);
    col2.add(perm2);
    final ProtectionDomain pd2 = new ProtectionDomain(null, col2);
    AccessControlContext acc3 = new AccessControlContext(
            new ProtectionDomain[] { pd2 });

    assertTrue(acc1.hashCode() == acc1.hashCode());
    assertTrue(acc2.hashCode() == acc2.hashCode());
    assertTrue(acc3.hashCode() == acc3.hashCode());

    assertTrue(acc1.hashCode() == acc2.hashCode());
    assertTrue(acc2.hashCode() != acc3.hashCode());
    assertTrue(acc3.hashCode() != acc1.hashCode());

    AccessControlContext context = AccessController.getContext();

    AccessControlContext acc4 = new AccessControlContext(context, null);
    AccessControlContext acc5 = new AccessControlContext(context,
            new SubjectDomainCombiner(new Subject()));

    AccessControlContext acc6 = new AccessControlContext(context, null);

    assertTrue(acc4.hashCode() == acc4.hashCode());
    assertTrue(acc5.hashCode() == acc5.hashCode());
    assertTrue(acc6.hashCode() == acc6.hashCode());

    assertTrue(acc4.hashCode() == acc5.hashCode());
    assertTrue(acc5.hashCode() == acc6.hashCode());
    assertTrue(acc6.hashCode() == acc4.hashCode());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:55,代码来源:AccessControlContextTest.java

示例15: 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);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:82,代码来源:SubjectDomainCombinerTest.java


注:本文中的javax.security.auth.SubjectDomainCombiner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。