Java Code Examples for org.wildfly.security.manager.WildFlySecurityManager#setPropertyPrivileged()
The following examples show how to use
org.wildfly.security.manager.WildFlySecurityManager#setPropertyPrivileged() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongOutputTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@After public void tearDown() throws Exception { afterTest(); readThreadActive.set(false); if (ctx != null) { ctx.terminateSession(); } for (Thread thread : threads) { thread.join(5000); if (thread.isAlive()) { thread.interrupt(); } waitFor(() -> !thread.isAlive(), 10000); } threads.removeAll(threads); IOUtil.close(consoleInput); IOUtil.close(consoleWriter); IOUtil.close(consoleOutput); IOUtil.close(consoleReader); // return back original value for jboss.cli.config property WildFlySecurityManager.setPropertyPrivileged("jboss.cli.config", originalCliConfig); }
Example 2
Source File: ServerEnvironment.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void setProcessName(String processName) { if (processName != null) { if (primordialProperties.contains(SERVER_NAME)) { // User specified both -Djboss.server.name and a standalone.xml <server name="xxx"/> value. // Log a WARN String rawServerProp = WildFlySecurityManager.getPropertyPrivileged(SERVER_NAME, serverName); ServerLogger.AS_ROOT_LOGGER.duplicateServerNameConfiguration(SERVER_NAME, rawServerProp, processName); } serverName = processName; WildFlySecurityManager.setPropertyPrivileged(SERVER_NAME, serverName); processNameSet = true; if (!primordialProperties.contains(NODE_NAME)) { nodeName = serverName; WildFlySecurityManager.setPropertyPrivileged(NODE_NAME, nodeName); } } }
Example 3
Source File: CliBootOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
void build() throws Exception { Files.createDirectories(markerDirectory.toPath()); sb.append(" -D" + AdditionalBootCliScriptInvoker.MARKER_DIRECTORY_PROPERTY + "=" + markerDirectory.getAbsolutePath()); File cliFile = new File(markerDirectory, "commands.cli"); Files.createFile(cliFile.toPath()); try (BufferedWriter writer = new BufferedWriter(new FileWriter(cliFile))) { writer.write(commands == null ? "" : commands); writer.write("\n\n"); } sb.append(" -D" + AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY + "=" + cliFile.getAbsolutePath()); if (skipReload) { sb.append(" -D" + AdditionalBootCliScriptInvoker.SKIP_RELOAD_PROPERTY + "=true"); } // Propagate this property since it has the maven repository information which is needed on CI if (WildFlySecurityManager.getPropertyPrivileged("cli.jvm.args", null) != null) { sb.append(" " + WildFlySecurityManager.getPropertyPrivileged("cli.jvm.args", null)); } WildFlySecurityManager.setPropertyPrivileged("jvm.args", sb.toString()); }
Example 4
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testKeepAliveScenario() throws Exception { WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.SKIP_RELOAD_PROPERTY, "true"); createCliScript("One\nTwo\n"); startController(); Assert.assertEquals("One\nTwo\n", TestAdditionalBootCliScriptInvoker.commands); // All our system properties should be unset checkNullProperty(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY); checkNullProperty(AdditionalBootCliScriptInvoker.MARKER_DIRECTORY_PROPERTY); checkNullProperty(AdditionalBootCliScriptInvoker.SKIP_RELOAD_PROPERTY); String marker = readFile(doneMarkerFile); Assert.assertEquals("success\n", marker); // :shutdown and :restart should not have been called and there should be no marker files // indicating that restart is happening Assert.assertNull(BootCliReloadHandler.INSTANCE.parameters); Assert.assertNull(BootCliShutdownHandler.INSTANCE.parameters); Assert.assertFalse(Files.exists(this.embeddedServerNeedsRestart.toPath())); Assert.assertFalse(Files.exists(this.restartInitiated.toPath())); }
Example 5
Source File: EnvironmentRestorer.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
void restoreEnvironment() { final Iterator<Map.Entry<String, String>> iter = propertiesToReset.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<String, String> entry = iter.next(); final String value = entry.getValue(); if (value == null) { WildFlySecurityManager.clearPropertyPrivileged(entry.getKey()); } else { WildFlySecurityManager.setPropertyPrivileged(entry.getKey(), value); } iter.remove(); } StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(defaultContexts.getStdioContext())); restoreLogContextSelector(); }
Example 6
Source File: SystemPropertyValueWriteAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, SysPropValue handback) throws OperationFailedException { if (handback != null) { if (handback.value != null) { WildFlySecurityManager.setPropertyPrivileged(handback.name, handback.value); } else { WildFlySecurityManager.clearPropertyPrivileged(handback.name); } systemPropertyUpdater.systemPropertyUpdated(handback.name, handback.value); } }
Example 7
Source File: BootScriptInvoker.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void handleProperties(File propertiesFile) { try ( InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(propertiesFile), StandardCharsets.UTF_8)) { props.load(inputStreamReader); for (String key : props.stringPropertyNames()) { String original = WildFlySecurityManager.getPropertyPrivileged(key, null); if (original != null) { existingProps.put(key, original); } WildFlySecurityManager.setPropertyPrivileged(key, props.getProperty(key)); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 8
Source File: SystemPropertyAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void setProperty(String name, String value) { if (value != null) { WildFlySecurityManager.setPropertyPrivileged(name, value); } else { WildFlySecurityManager.clearPropertyPrivileged(name); } if (systemPropertyUpdater != null) { systemPropertyUpdater.systemPropertyUpdated(name, value); } }
Example 9
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = IllegalStateException.class) public void testNotStandaloneOrEmbedded() throws Exception { super.processType = ProcessType.DOMAIN_SERVER; createCliScript("One\nTwo"); WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, cliFile.getAbsolutePath()); startController(); }
Example 10
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = IllegalStateException.class) public void testNoMarkerDirWhenSkippingReload() throws Exception { WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.SKIP_RELOAD_PROPERTY, "true"); WildFlySecurityManager.clearPropertyPrivileged(AdditionalBootCliScriptInvoker.MARKER_DIRECTORY_PROPERTY); createCliScript("One\nTwo"); WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, cliFile.getAbsolutePath()); startController(); }
Example 11
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test(expected = IllegalStateException.class) public void testNotAdminOnlyFails() throws Exception { runningModeControl = new RunningModeControl(RunningMode.NORMAL); createCliScript("One\nTwo"); WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, cliFile.getAbsolutePath()); startController(); }
Example 12
Source File: CliBootOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@After public void tearDown() { if (container.isStarted()) { container.stop(true); } if (originalJvmArgs != null) { WildFlySecurityManager.setPropertyPrivileged("jvm.args", originalJvmArgs); } else { WildFlySecurityManager.clearPropertyPrivileged("jvm.args"); } }
Example 13
Source File: CLIEmbedHostControllerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void setProperties(final String newBaseDir) { if (newBaseDir == null) { for (String prop : DOMAIN_PROPS) { WildFlySecurityManager.clearPropertyPrivileged(prop); } return; } WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_BASE_DIR, newBaseDir); WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_CONFIG_DIR, newBaseDir + File.separator + "configuration"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_DATA_DIR, newBaseDir + File.separator + "data"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_LOG_DIR, newBaseDir + File.separator + "log"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_TEMP_DIR, newBaseDir + File.separator + "tmp"); }
Example 14
Source File: CLIEmbedServerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void setProperties(final String newBaseDir) { if (newBaseDir == null) { for (String prop : SERVER_PROPS) { WildFlySecurityManager.clearPropertyPrivileged(prop); } return; } WildFlySecurityManager.setPropertyPrivileged(JBOSS_SERVER_BASE_DIR, newBaseDir); WildFlySecurityManager.setPropertyPrivileged(JBOSS_SERVER_CONFIG_DIR, newBaseDir + File.separator + "configuration"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_SERVER_DATA_DIR, newBaseDir + File.separator + "data"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_SERVER_LOG_DIR, newBaseDir + File.separator + "log"); WildFlySecurityManager.setPropertyPrivileged(JBOSS_SERVER_TEMP_DIR, newBaseDir + File.separator + "tmp"); }
Example 15
Source File: CLIEmbedServerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void testPathDir(final String propName, final String value) throws IOException, InterruptedException { String currBaseDir = null; final String newStandalone = "CLIEmbedServerTestCaseStandaloneTmp"; assertFalse(cli.isConnected()); try { // save the current value currBaseDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_SERVER_BASE_DIR, null); // The current directory isn't set until the embedded server is started, just use the root directory if the // property was not previously set. if (currBaseDir == null) { currBaseDir = ROOT + File.separator + "standalone"; } CLIEmbedUtil.copyServerBaseDir(ROOT, "standalone", newStandalone, true); String newBaseDir = ROOT + File.separator + newStandalone; WildFlySecurityManager.setPropertyPrivileged(propName, newBaseDir + File.separator + value); String line = "embed-server --std-out=echo " + JBOSS_HOME; cli.sendLine(line); assertTrue(cli.isConnected()); for(String prop : SERVER_PROPS) { if (prop.equals(propName)) { assertPath(propName, ROOT + File.separator + newStandalone + File.separator + value); } else { // just make sure the unchanged property has the default basedir assertTrue(WildFlySecurityManager.getPropertyPrivileged(prop, "").contains(currBaseDir)); } } } finally { // stop the server cli.sendLine("stop-embedded-server"); // restore the original setProperties(currBaseDir); FileUtils.deleteDirectory(new File(ROOT + File.separator + newStandalone)); } }
Example 16
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test(expected = IllegalStateException.class) public void testNonExistentMarkerDirectory() throws Exception { File file = new File(directory, "non-existent"); WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, file.getAbsolutePath()); startController(); }
Example 17
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test(expected = IllegalStateException.class) public void testNonExistentOperationFileFails() throws Exception { WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, new File(directory, "non-existent").getAbsolutePath()); startController(); }
Example 18
Source File: BootCliHookTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void createCliScript(String content) throws IOException { writeToFile(cliFile, content); WildFlySecurityManager.setPropertyPrivileged(AdditionalBootCliScriptInvoker.CLI_SCRIPT_PROPERTY, cliFile.getAbsolutePath()); }
Example 19
Source File: ServerEnvironment.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void setPathProperty(String propertyName, File path) { if (this.launchType == LaunchType.SELF_CONTAINED && path == null) { return; } WildFlySecurityManager.setPropertyPrivileged(propertyName, path.getAbsolutePath()); }
Example 20
Source File: LongOutputTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void setupConsole(OutputPaging outputPaging) throws Exception { CommandContextConfiguration.Builder builder = CLITestUtil.getCommandContextBuilder(TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort(), consoleInput, consoleOutput); File configFile; switch (outputPaging) { case ENABLE_PAGING_OUTPUT_VIA_XML: // create jboss-cli.xml and set to and set path to jboss.cli.config property configFile = CliConfigUtils.createConfigFile(false, 0, true, false, false, true); WildFlySecurityManager.setPropertyPrivileged("jboss.cli.config", configFile.getAbsolutePath()); break; case DISABLE_PAGING_OUTPUT_VIA_XML: // create jboss-cli.xml and set to and set path to jboss.cli.config property configFile = CliConfigUtils.createConfigFile(false, 0, true, false, false, false); WildFlySecurityManager.setPropertyPrivileged("jboss.cli.config", configFile.getAbsolutePath()); break ; case DISABLE_PAGING_OUTPUT_VIA_ARGUMENT: builder.setOutputPaging(false); break; case ENABLE_PAGING_OUTPUT_VIA_ARGUMENT: builder.setOutputPaging(true); break; case DEFAULT: // do nothing - just keep default (which is paging output enabled) break; default: // throw exception here throw new IllegalArgumentException("Invalid paging output enum passed: " + outputPaging + " - see LongOutputTestCase.OutputPaging enum for valid values."); } ctx = CommandContextFactory.getInstance().newCommandContext(builder.build()); Class<?> ctxClass = Class.forName("org.jboss.as.cli.impl.CommandContextImpl"); Method getConsoleMethod = ctxClass.getDeclaredMethod("getConsole"); getConsoleMethod.setAccessible(true); readlineConsole = (ReadlineConsole) getConsoleMethod.invoke(ctx); readlineConsole.forcePagingOutput(true); ctx.connectController(); final CommandContext c = ctx; Thread interactThread = new Thread(() -> c.interact()); threads.add(interactThread); interactThread.start(); final InputStream readThreadIs = consoleInputStream; final Reader readThreadReader = new BufferedReader(consoleReader); /** * The thread reads output from the CLI. There is implemented logic, which * captures an output into the StringBuilder. If no output is available * for 3 seconds, it suspects it is everything what should be read in this * round and it puts the captured output into the blocking queue. */ Thread readThread = new Thread(() -> { char[] buffer = new char[bufferSize]; int noAvailable = 0; while (readThreadActive.get()) { try { if (readThreadIs.available() > 0) { noAvailable = 0; int read = readThreadReader.read(buffer); sb.append(buffer, 0, read); } else { if (noAvailable < 300) { noAvailable++; Thread.sleep(5); } else { queue.put(sb.toString()); sb = new StringBuilder(); noAvailable = 0; } } } catch (Exception e) { log.error(e.getMessage(), e); } } }); threads.add(readThread); readThread.start(); // this just reads the lines which are printed when CLI is started String window = queue.poll(10, TimeUnit.SECONDS); Assert.assertNotNull(window); Assert.assertTrue(readlineConsole.getTerminalHeight() > 0); }