當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。