本文整理匯總了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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) {
}
}
示例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]);
}
示例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);
}
示例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);
}
}
示例9: run
import java.security.AccessController; //導入方法依賴的package包/類
@Override public Void run() {
AccessController.checkPermission(permission);
return null;
}
示例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);
}
示例11: clearCurrentServletAttachments
import java.security.AccessController; //導入方法依賴的package包/類
public static void clearCurrentServletAttachments() {
if(System.getSecurityManager() != null) {
AccessController.checkPermission(SET_CURRENT_REQUEST);
}
CURRENT.remove();
}
示例12: current
import java.security.AccessController; //導入方法依賴的package包/類
public static ServletRequestContext current() {
if(System.getSecurityManager() != null) {
AccessController.checkPermission(GET_CURRENT_REQUEST);
}
return CURRENT.get();
}
示例13: setSecurityContext
import java.security.AccessController; //導入方法依賴的package包/類
public void setSecurityContext(SecurityContext securityContext) {
if(System.getSecurityManager() != null) {
AccessController.checkPermission(SET_SECURITY_CONTEXT);
}
this.securityContext = securityContext;
}