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


Java AccessControlException类代码示例

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


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

示例1: run

import java.security.AccessControlException; //导入依赖的package包/类
public void run() throws Exception {
    boolean hasAccess = loader != null || hasAccess();
    try {
        proxyClass = Proxy.getProxyClass(loader, interfaces);
        if (!hasAccess) {
            throw new RuntimeException("should have no permission to create proxy class");
        }
    } catch (AccessControlException e) {
        if (hasAccess) {
            throw e;
        }
        if (e.getPermission().getClass() != RuntimePermission.class ||
                !e.getPermission().getName().equals("getClassLoader")) {
            throw e;
        }
        return;
    }

    if (Modifier.isPublic(proxyClass.getModifiers())) {
        throw new RuntimeException(proxyClass + " must be non-public");
    }
    newProxyInstance();
    newInstanceFromConstructor(proxyClass);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:NonPublicProxyClass.java

示例2: overrideWithSysProps

import java.security.AccessControlException; //导入依赖的package包/类
/**
 * Add all System properties to the given <code>props</code>.  Will override
 * any properties that already exist in the given <code>props</code>.
 */
private Properties overrideWithSysProps(Properties props) {
    Properties sysProps = null;
    try {
        sysProps = System.getProperties();
    } catch (AccessControlException e) {
        getLog().warn(
            "Skipping overriding quartz properties with System properties " +
            "during initialization because of an AccessControlException.  " +
            "This is likely due to not having read/write access for " +
            "java.util.PropertyPermission as required by java.lang.System.getProperties().  " +
            "To resolve this warning, either add this permission to your policy file or " +
            "use a non-default version of initialize().",
            e);
    }

    if (sysProps != null) {
        props.putAll(sysProps);
    }

    return props;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:StdSchedulerFactory.java

示例3: getStaticFields

import java.security.AccessControlException; //导入依赖的package包/类
private OrderedMap<String, Field> getStaticFields(Class type) {
    if (staticFields.containsKey(type))
        return staticFields.get(type);
    Field[] fields = ClassReflection.getDeclaredFields(type);
    OrderedMap<String, Field> nameToField = new OrderedMap(fields.length);
    for (Field field : fields) {
        if (!field.isStatic())
            continue;
        if (!field.isAccessible()) {
            try {
                field.setAccessible(true);
            } catch (AccessControlException ex) {
                continue;
            }
        }

        nameToField.put(field.getName(), field);
    }
    staticFields.put(type, nameToField);
    return nameToField;
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:22,代码来源:JsonFieldUpdater.java

示例4: checkSunClass

import java.security.AccessControlException; //导入依赖的package包/类
/**
 * Fix for 4179055: Need to assist resolving sun stubs; resolve
 * class locally if it is a "permitted" sun class
 */
private Class<?> checkSunClass(String className, AccessControlException e)
    throws AccessControlException
{
    // ensure that we are giving out a stub for the correct reason
    Permission perm = e.getPermission();
    String name = null;
    if (perm != null) {
        name = perm.getName();
    }

    Class<?> resolvedClass = permittedSunClasses.get(className);

    // if class not permitted, throw the SecurityException
    if ((name == null) ||
        (resolvedClass == null) ||
        ((!name.equals("accessClassInPackage.sun.rmi.server")) &&
        (!name.equals("accessClassInPackage.sun.rmi.registry"))))
    {
        throw e;
    }

    return resolvedClass;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:MarshalInputStream.java

示例5: test

import java.security.AccessControlException; //导入依赖的package包/类
void test(String[] args) {
    testPrivileged();

    final Policy policy = new Policy();
    Policy.setPolicy(policy);
    policy.setPermissions(new RuntimePermission("getClassLoader"),
                          new RuntimePermission("setContextClassLoader"),
                          new RuntimePermission("stopThread"));
    System.setSecurityManager(new SecurityManager());

    testPrivileged();

    policy.setPermissions(/* Nothing */);

    THROWS(AccessControlException.class,
           new F() {void f(){ privilegedCallableUsingCurrentClassLoader(realCaller); }},
           new F() {void f(){ privilegedThreadFactory(); }});

    policy.setPermissions(new RuntimePermission("setSecurityManager"));
    System.setSecurityManager(null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:PrivilegedCallables.java

示例6: main

import java.security.AccessControlException; //导入依赖的package包/类
public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();

    printDirContent(dir);

    System.setSecurityManager(new SecurityManager());

    // The next test cases use 'dir' obtained without SecurityManager

    try {
        printDirContent(dir);

        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
        // It's a successful situation
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:bug6484091.java

示例7: checkReservationACLs

import java.security.AccessControlException; //导入依赖的package包/类
private String checkReservationACLs(String queueName, String auditConstant)
    throws YarnException {
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    RMAuditLogger.logFailure("UNKNOWN", auditConstant, queueName,
        "ClientRMService", "Error getting UGI");
    throw RPCUtil.getRemoteException(ie);
  }
  // Check if user has access on the managed queue
  if (!queueACLsManager.checkAccess(callerUGI, QueueACL.SUBMIT_APPLICATIONS,
      queueName)) {
    RMAuditLogger.logFailure(
        callerUGI.getShortUserName(),
        auditConstant,
        "User doesn't have permissions to "
            + QueueACL.SUBMIT_APPLICATIONS.toString(), "ClientRMService",
        AuditConstants.UNAUTHORIZED_USER);
    throw RPCUtil.getRemoteException(new AccessControlException("User "
        + callerUGI.getShortUserName() + " cannot perform operation "
        + QueueACL.SUBMIT_APPLICATIONS.name() + " on queue" + queueName));
  }
  return callerUGI.getShortUserName();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:ClientRMService.java

示例8: testMoveRejectedByPermissions

import java.security.AccessControlException; //导入依赖的package包/类
@Test
public void testMoveRejectedByPermissions() throws Exception {
  failMove = true;
  
  // Submit application
  final Application application = new Application("user1", resourceManager);
  application.submit();

  final ClientRMService clientRMService = resourceManager.getClientRMService();
  try {
    UserGroupInformation.createRemoteUser("otheruser").doAs(
        new PrivilegedExceptionAction<MoveApplicationAcrossQueuesResponse>() {
          @Override
          public MoveApplicationAcrossQueuesResponse run() throws Exception {
            return clientRMService.moveApplicationAcrossQueues(
                MoveApplicationAcrossQueuesRequest.newInstance(
                    application.getApplicationId(), "newqueue"));
          }
          
        });
    fail("Should have hit exception");
  } catch (Exception ex) {
    assertEquals(AccessControlException.class, ex.getCause().getCause().getClass());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestMoveApplication.java

示例9: test

import java.security.AccessControlException; //导入依赖的package包/类
public static void test(Permission perm, boolean expectException) {
    boolean getException = (Boolean) AccessController.doPrivileged((PrivilegedAction) () -> {
        try {
            AccessController.checkPermission(perm);
            return (Boolean) false;
        } catch (AccessControlException ex) {
            return (Boolean) true;
        }
    });

    if (expectException ^ getException) {
        String message = "Check Permission :" + perm + "\n ExpectException = "
                + expectException + "\n getException = " + getException;
        throw new RuntimeException(message);
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:SignedJarTest.java

示例10: runTest

import java.security.AccessControlException; //导入依赖的package包/类
public void runTest(AccessControlContext acc, Permission perm,
        boolean expectACE, int id) {

    AccessController.doPrivileged(
            (PrivilegedAction) () -> {
                try {
                    AccessController.getContext().checkPermission(P1);
                } catch (AccessControlException ace) {
                    catchACE = true;
                }
                if (catchACE ^ expectACE) {
                    throw new RuntimeException("test" + id + " failed");
                }
                return null;
            }, acc, perm);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:LimitedDoPrivilegedWithThread.java

示例11: run

import java.security.AccessControlException; //导入依赖的package包/类
@Override
public java.lang.Object run() {
    System.out.println("Try to read 'java.class.path' property");

    AccessControlContext acc = AccessController.getContext();
    Subject s = Subject.getSubject(acc);
    System.out.println("principals = " + s.getPrincipals());

    try {
        System.out.println("java.class.path = "
                + System.getProperty("java.class.path"));
        throw new RuntimeException(
                "Test failed: no AccessControlException thrown");
    } catch (AccessControlException ace) {
        System.out.println(
                "AccessControlException thrown as expected: "
                + ace.getMessage());
    }

    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:NestedActions.java

示例12: newProxyInstance

import java.security.AccessControlException; //导入依赖的package包/类
private void newProxyInstance() {
    // expect newProxyInstance to succeed if it's in the same runtime package
    int i = proxyClass.getName().lastIndexOf('.');
    String pkg = (i != -1) ? proxyClass.getName().substring(0, i) : "";
    boolean hasAccess = pkg.isEmpty() || hasAccess();
    try {
        Proxy.newProxyInstance(loader, interfaces, handler);
        if (!hasAccess) {
            throw new RuntimeException("ERROR: Proxy.newProxyInstance should fail " + proxyClass);
        }
    } catch (AccessControlException e) {
        if (hasAccess) {
            throw e;
        }
        if (e.getPermission().getClass() != ReflectPermission.class ||
                !e.getPermission().getName().equals(NEW_PROXY_IN_PKG + pkg)) {
            throw e;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:NonPublicProxyClass.java

示例13: testGlobalFilter

import java.security.AccessControlException; //导入依赖的package包/类
/**
 * Test that setting process-wide filter is checked by security manager.
 */
@Test
public void testGlobalFilter() throws Exception {
    if (ObjectInputFilter.Config.getSerialFilter() == null) {
        return;
    }
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais)) {
        ObjectInputFilter.Config.setSerialFilter(filter);
        assertFalse(setSecurityManager,
                "When SecurityManager exists, without "
                + "java.security.SerializablePermission(serialFilter) Exception should be thrown");
        Object o = ois.readObject();
    } catch (AccessControlException ex) {
        assertTrue(setSecurityManager);
        assertTrue(ex.getMessage().contains("java.io.SerializablePermission"));
        assertTrue(ex.getMessage().contains("serialFilter"));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:FilterWithSecurityManagerTest.java

示例14: testGlobalFilter

import java.security.AccessControlException; //导入依赖的package包/类
/**
 * Test that setting process-wide filter is checked by security manager.
 */
@Test
public void testGlobalFilter() throws Exception {
    ObjectInputFilter global = ObjectInputFilter.Config.getSerialFilter();

    try  {
        ObjectInputFilter.Config.setSerialFilter(filter);
        assertFalse(setSecurityManager,
                "When SecurityManager exists, without "
                + "java.io.SerializablePermission(serialFilter) "
                + "IllegalStateException should be thrown");
    } catch (AccessControlException ex) {
        assertTrue(setSecurityManager);
        assertTrue(ex.getMessage().contains("java.io.SerializablePermission"));
        assertTrue(ex.getMessage().contains("serialFilter"));
    } catch (IllegalStateException ise) {
        // ISE should occur only if global filter already set
        Assert.assertNotNull(global, "Global filter should be non-null");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:FilterWithSecurityManagerTest.java

示例15: logged

import java.security.AccessControlException; //导入依赖的package包/类
@Override
public void logged(LogEntry entry) {
    if (entry.getException() != null &&
            entry.getException() instanceof AccessControlException) {
        String location = entry.getBundle().getLocation();
        Permission javaPerm =
                ((AccessControlException) entry.getException()).getPermission();
        org.onosproject.security.Permission permission = DefaultPolicyBuilder.getOnosPermission(javaPerm);
        if (permission == null) {
            log.warn("Unsupported permission requested.");
            return;
        }
        store.getApplicationIds(location).stream().filter(
                appId -> store.isSecured(appId) &&
                        appAdminService.getState(appId) == ApplicationState.ACTIVE).forEach(appId -> {
            store.requestPermission(appId, permission);
            print("[POLICY VIOLATION] APP: %s / Bundle: %s / Permission: %s ",
                    appId.name(), location, permission.toString());
        });
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:SecurityModeManager.java


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