List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:org.apache.hadoop.yarn.server.resourcemanager.TestAMAuthorization.java
@Test public void testAuthorizedAccess() throws Exception { MyContainerManager containerManager = new MyContainerManager(); rm = new MockRMWithAMS(conf, containerManager); rm.start();//w ww. ja v a2 s . c o m MockNM nm1 = rm.registerNode("localhost:1234", 5120); Map<ApplicationAccessType, String> acls = new HashMap<ApplicationAccessType, String>(2); acls.put(ApplicationAccessType.VIEW_APP, "*"); RMApp app = rm.submitApp(1024, "appname", "appuser", acls); nm1.nodeHeartbeat(true); int waitCount = 0; while (containerManager.containerTokens == null && waitCount++ < 20) { LOG.info("Waiting for AM Launch to happen.."); Thread.sleep(1000); } Assert.assertNotNull(containerManager.containerTokens); RMAppAttempt attempt = app.getCurrentAppAttempt(); ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId(); waitForLaunchedState(attempt); // Create a client to the RM. final Configuration conf = rm.getConfig(); final YarnRPC rpc = YarnRPC.create(conf); UserGroupInformation currentUser = UserGroupInformation.createRemoteUser(applicationAttemptId.toString()); Credentials credentials = containerManager.getContainerCredentials(); final InetSocketAddress rmBindAddress = rm.getApplicationMasterService().getBindAddress(); Token<? extends TokenIdentifier> amRMToken = MockRMWithAMS.setupAndReturnAMRMToken(rmBindAddress, credentials.getAllTokens()); currentUser.addToken(amRMToken); ApplicationMasterProtocol client = currentUser.doAs(new PrivilegedAction<ApplicationMasterProtocol>() { @Override public ApplicationMasterProtocol run() { return (ApplicationMasterProtocol) rpc.getProxy(ApplicationMasterProtocol.class, rm.getApplicationMasterService().getBindAddress(), conf); } }); RegisterApplicationMasterRequest request = Records.newRecord(RegisterApplicationMasterRequest.class); RegisterApplicationMasterResponse response = client.registerApplicationMaster(request); Assert.assertNotNull(response.getClientToAMTokenMasterKey()); if (UserGroupInformation.isSecurityEnabled()) { Assert.assertTrue(response.getClientToAMTokenMasterKey().array().length > 0); } Assert.assertEquals("Register response has bad ACLs", "*", response.getApplicationACLs().get(ApplicationAccessType.VIEW_APP)); }
From source file:org.echocat.nodoodle.classloading.FileClassLoader.java
@Override protected synchronized URL findResource(final String name) { ensureNotClosed();// w w w . j a v a2 s . c o m return doPrivileged(new PrivilegedAction<URL>() { @Override public URL run() { URL result = null; final Iterator<File> i = _directories.iterator(); while (result == null && i.hasNext()) { final File directory = i.next(); final File file = new File(directory, name); if (file.isFile()) { result = new DirectoryResource(directory, file).getResourceUrl(); } } if (result == null) { final Iterator<JarFile> j = _jarFiles.iterator(); while (result == null && j.hasNext()) { final JarFile jarFile = j.next(); final JarEntry jarEntry = jarFile.getJarEntry(name); if (jarEntry != null) { result = new JarResource(jarFile, jarEntry).getResourceUrl(); } } } return result; } }, _acc); }
From source file:org.rhq.enterprise.client.LocalClient.java
@Override public MeasurementBaselineManagerRemote getMeasurementBaselineManager() { return AccessController.doPrivileged(new PrivilegedAction<MeasurementBaselineManagerRemote>() { @Override/*from ww w.j a v a 2s . c o m*/ public MeasurementBaselineManagerRemote run() { return getProxy(LookupUtil.getMeasurementBaselineManager(), MeasurementBaselineManagerRemote.class); } }); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestApplicationTokens.java
private AMRMProtocol createRMClient(final MockRM rm, final Configuration conf, final YarnRPC rpc, UserGroupInformation currentUser) { return currentUser.doAs(new PrivilegedAction<AMRMProtocol>() { @Override/*from ww w .j a va 2 s. c o m*/ public AMRMProtocol run() { return (AMRMProtocol) rpc.getProxy(AMRMProtocol.class, rm.getApplicationMasterService().getBindAddress(), conf); } }); }
From source file:FileErrorManager.java
/** * Gets the location of the email store. * * @return the File location./*from w w w .ja v a 2 s.co m*/ */ private File getEmailStore() { String dir = manager.getProperty(getClass().getName().concat(".pattern")); if (dir == null) { dir = AccessController.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { return System.getProperty("java.io.tmpdir", "."); } }); } return new File(dir); }
From source file:org.apache.axis2.engine.DependencyManager.java
protected static void restoreThreadContext(final ThreadContextDescriptor tc) { org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Thread.currentThread().setContextClassLoader(tc.oldClassLoader); return null; }/*from w w w.ja va2s . c o m*/ }); MessageContext.currentMessageContext.set(tc.oldMessageContext); }
From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java
public void setAttribute(final String name, final Object o, final int scope) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*from w ww . j ava 2s . c o m*/ if (SecurityUtil.isPackageProtectionEnabled()) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { doSetAttribute(name, o, scope); return null; } }); } else { doSetAttribute(name, o, scope); } }
From source file:org.nebulaframework.grid.cluster.manager.services.jobs.ClusterJobServiceImpl.java
/** * Creates a {@link GridNodeClassLoader} to remotely load necessary class * definitions.// ww w .j a v a2 s . c om * * @param owner * Owner GridNode to load classes from * * @return ClassLoader instance */ protected ClassLoader createNodeClassLoader(final UUID owner) { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { ClassLoadingService service = ClusterManager.getInstance().getClassLoadingService(); return new GridNodeClassLoader(owner, service); } }); }
From source file:org.apache.jasper.runtime.PageContextImpl.java
public Object getAttribute(final String name) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*from w ww . j a va2s .com*/ if (System.getSecurityManager() != null) { return AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return doGetAttribute(name); } }); } else { return doGetAttribute(name); } }
From source file:org.eclipse.gemini.blueprint.test.AbstractDependencyManagerTests.java
/** * {@inheritDoc}/*from w ww . ja v a 2 s . c om*/ * * <p/>Sets specific log4j property to avoid class loading problems during * start up related to the thread context class loader. */ protected void preProcessBundleContext(BundleContext platformBundleContext) throws Exception { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { System.setProperty("log4j.ignoreTCL", "true"); return null; } }); super.preProcessBundleContext(platformBundleContext); }