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


Java Subject.doAsPrivileged方法代码示例

本文整理汇总了Java中javax.security.auth.Subject.doAsPrivileged方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.doAsPrivileged方法的具体用法?Java Subject.doAsPrivileged怎么用?Java Subject.doAsPrivileged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.security.auth.Subject的用法示例。


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

示例1: main

import javax.security.auth.Subject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        for (Permission perm : perms) {
            AccessController.checkPermission(perm);
        }

        Permission princPerm = new java.util.PropertyPermission("user.home",
                                                                "read");
        Set<Principal> princSet = new HashSet<>(Arrays.asList(princs));
        Subject subject = new Subject(true, princSet, Collections.emptySet(),
                                      Collections.emptySet());
        PrivilegedAction<Void> pa = () -> {
            AccessController.checkPermission(princPerm);
            return null;
        };
        Subject.doAsPrivileged(subject, pa, null);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Modules.java

示例2: main

import javax.security.auth.Subject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Subject s = new Subject();
    s.getPrincipals().add
            (new javax.security.auth.x500.X500Principal("CN=test"));
    s.getPrivateCredentials().add(new String("test"));
    try {
        Subject.doAsPrivileged(s, new PrivilegedAction() {
            public Object run() {
                java.util.Iterator i = Subject.getSubject
                            (AccessController.getContext
                            ()).getPrivateCredentials().iterator();
                return i.next();
            }
        }, null);
        System.out.println("Test succeeded");
    } catch (Exception e) {
        System.out.println("Test failed");
        e.printStackTrace();
        throw e;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SelfExpansion.java

示例3: main

import javax.security.auth.Subject; //导入方法依赖的package包/类
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    try {
        Subject.doAsPrivileged(get("CN=joe"), new PrivilegedAction() {
            public Object run() {
                return Subject.doAs(null, new PrivilegedAction() {
                    public Object run() {
                    return System.getProperty("foobar");
                    }
                });
            }
        }, null);
    throw new RuntimeException
             ("Access control exception should have occcured");
    } catch (java.security.AccessControlException e) {
            // Expected exception occured
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:Test.java

示例4: main

import javax.security.auth.Subject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

            // try setting the local hostname
            InetAddress localHost = InetAddress.getLocalHost();
            if (localHost.isLoopbackAddress()) {
                System.err.println("Local host name is resolved into a loopback address. Quit now!");
                return;
            }
            System.setProperty("host.name", localHost.
                                            getHostName());
            String policyFileName = System.getProperty("test.src", ".") +
                          "/" + "policy.file";
            System.setProperty("java.security.policy", policyFileName);
            System.setSecurityManager(new SecurityManager());

            InetAddress localHost1 = null;
            InetAddress localHost2 = null;

            localHost1 = InetAddress.getLocalHost();

            Subject mySubject = new Subject();
            MyPrincipal userPrincipal = new MyPrincipal("test");
            mySubject.getPrincipals().add(userPrincipal);
            localHost2 = (InetAddress)Subject.doAsPrivileged(mySubject,
                                new MyAction(), null);

            if (localHost1.equals(localHost2)) {
                System.out.println("localHost1 = " + localHost1);
                throw new RuntimeException("InetAddress.getLocalHost() test " +
                                           " fails. localHost2 should be " +
                                           " the real address instead of " +
                                           " the loopback address."+localHost2);
            }
        }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:GetLocalHostWithSM.java

示例5: run

import javax.security.auth.Subject; //导入方法依赖的package包/类
@Override public Void run() {
    Set<Principal> principals = new HashSet<>();
    Set<Object> publicCredentials = new HashSet<>();
    Set<Object> privateCredentials = new HashSet<>();

    principals.add(principal);
    Subject subject = new Subject(true,
                                  principals,
                                  publicCredentials,
                                  privateCredentials);

    Subject.doAsPrivileged(subject, action, null);
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:WildcardPrincipalName.java

示例6: main

import javax.security.auth.Subject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String foo = Subject.doAs(new Subject(),
                            new A1<String>("foo"));

    Integer one = Subject.doAs(new Subject(),
                            new A2<Integer>(new Integer("1")));

    Boolean troo = Subject.doAsPrivileged(new Subject(),
                            new A1<Boolean>(new Boolean("true")),
                            AccessController.getContext());

    Generic gen = Subject.doAsPrivileged(new Subject(),
                            new A2<Generic>(new Generic()),
                            AccessController.getContext());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Generic.java


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