當前位置: 首頁>>代碼示例>>Java>>正文


Java AccessController.checkPermission方法代碼示例

本文整理匯總了Java中java.security.AccessController.checkPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java AccessController.checkPermission方法的具體用法?Java AccessController.checkPermission怎麽用?Java AccessController.checkPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.AccessController的用法示例。


在下文中一共展示了AccessController.checkPermission方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.security.AccessController; //導入方法依賴的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: checkRemoveCallerContext

import java.security.AccessController; //導入方法依賴的package包/類
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SubjectDelegator.java

示例3: main

import java.security.AccessController; //導入方法依賴的package包/類
public static void main(String args[]) throws Throwable {
    // ExtensiblePolicyTest1.policy: policy file grants permission to
    // watch TVChannel 3-6
    // ExtensiblePolicyTest2.policy: policy file grants permission to
    // watch TVChanel 4
    // ExtensiblePolicyTest3.policy: policy file grants permission signed
    // by duke2 to watch TVChanel 5

    TVPermission perm = new TVPermission("channel:5", "watch");
    boolean getException = false;
    String exceptionMessage = null;
    boolean expectException = Boolean.parseBoolean(args[0]);
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        getException = true;
        exceptionMessage = se.getMessage();
    }

    if (expectException ^ getException) {
        throw new RuntimeException("Test Failed: expectException = "
                + expectException + " getException = " + getException
                + "\n" + exceptionMessage);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:ExtensiblePolicyTest.java

示例4: requireCurrent

import java.security.AccessController; //導入方法依賴的package包/類
public static ServletRequestContext requireCurrent() {
    if(System.getSecurityManager() != null) {
        AccessController.checkPermission(GET_CURRENT_REQUEST);
    }
    ServletRequestContext attachments = CURRENT.get();
    if (attachments == null) {
        throw UndertowMessages.MESSAGES.noRequestActive();
    }
    return attachments;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:ServletRequestContext.java

示例5: main

import java.security.AccessController; //導入方法依賴的package包/類
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:FailureDebugOption.java

示例6: main

import java.security.AccessController; //導入方法依賴的package包/類
public static void main(String[] args) {
    try {
        AccessController.checkPermission(new FilePermission(".", "read"));
    } catch (AccessControlException e) {
        throw new RuntimeException("Invalid policy settings!", e);
    }

    instance = new ClientBuilder().withToken(args[0]).login();

    instance.getDispatcher().registerListener(new MCBot());
    instance.getDispatcher().registerListener(CommandListener.INSTANCE);

    // Handle "stop" and any future commands
    Thread consoleThread = new Thread(() -> {
        Scanner scan = new Scanner(System.in);
        while (true) {
            while (scan.hasNextLine()) {
                if (scan.nextLine().equals("stop")) {
                    scan.close();
                    System.exit(0);
                }
            }
            Threads.sleep(100);
        }
    });

    // Make sure shutdown things are run, regardless of where shutdown came from
    // The above System.exit(0) will trigger this hook
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        CommandRegistrar.INSTANCE.onShutdown();
    }));
    
    consoleThread.start();

    if(args.length > 1)
        new MCBotIRC(args[1]);
}
 
開發者ID:tterrag1098,項目名稱:MCBot,代碼行數:38,代碼來源:MCBot.java

示例7: delegatedContext

import java.security.AccessController; //導入方法依賴的package包/類
public AccessControlContext
    delegatedContext(AccessControlContext authenticatedACC,
                     Subject delegatedSubject,
                     boolean removeCallerContext)
        throws SecurityException {

    if (System.getSecurityManager() != null && authenticatedACC == null) {
        throw new SecurityException("Illegal AccessControlContext: null");
    }

    // Check if the subject delegation permission allows the
    // authenticated subject to assume the identity of each
    // principal in the delegated subject
    //
    Collection<Principal> ps = getSubjectPrincipals(delegatedSubject);
    final Collection<Permission> permissions = new ArrayList<>(ps.size());
    for(Principal p : ps) {
        final String pname = p.getClass().getName() + "." + p.getName();
        permissions.add(new SubjectDelegationPermission(pname));
    }
    PrivilegedAction<Void> action =
        new PrivilegedAction<Void>() {
            public Void run() {
                for (Permission sdp : permissions) {
                    AccessController.checkPermission(sdp);
                }
                return null;
            }
        };
    AccessController.doPrivileged(action, authenticatedACC);

    return getDelegatedAcc(delegatedSubject, removeCallerContext);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:34,代碼來源:SubjectDelegator.java

示例8: main

import java.security.AccessController; //導入方法依賴的package包/類
public static void main(String args[]) {
    TVPermission perm = new TVPermission("channel:5", "watch");
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        throw new RuntimeException(se);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:ExtensiblePolicyWithJarTest.java

示例9: run

import java.security.AccessController; //導入方法依賴的package包/類
@Override public Void run() {
    AccessController.checkPermission(permission);
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:WildcardPrincipalName.java

示例10: setCurrentRequestContext

import java.security.AccessController; //導入方法依賴的package包/類
public static void setCurrentRequestContext(ServletRequestContext servletRequestContext) {
    if(System.getSecurityManager() != null) {
        AccessController.checkPermission(SET_CURRENT_REQUEST);
    }
    CURRENT.set(servletRequestContext);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:ServletRequestContext.java

示例11: clearCurrentServletAttachments

import java.security.AccessController; //導入方法依賴的package包/類
public static void clearCurrentServletAttachments() {
    if(System.getSecurityManager() != null) {
        AccessController.checkPermission(SET_CURRENT_REQUEST);
    }
    CURRENT.remove();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:ServletRequestContext.java

示例12: current

import java.security.AccessController; //導入方法依賴的package包/類
public static ServletRequestContext current() {
    if(System.getSecurityManager() != null) {
        AccessController.checkPermission(GET_CURRENT_REQUEST);
    }
    return CURRENT.get();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:ServletRequestContext.java

示例13: setSecurityContext

import java.security.AccessController; //導入方法依賴的package包/類
public void setSecurityContext(SecurityContext securityContext) {
    if(System.getSecurityManager() != null) {
        AccessController.checkPermission(SET_SECURITY_CONTEXT);
    }
    this.securityContext = securityContext;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:HttpServerExchange.java


注:本文中的java.security.AccessController.checkPermission方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。