List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:es.mityc.javasign.pkstore.mscapi.mityc.SunMSCAPI_MITyC.java
public SunMSCAPI_MITyC() { super("SunMSCAPI_MITyC", 1.71d, INFO); // if there is no security manager installed, put directly into // the provider. Otherwise, create a temporary map and use a // doPrivileged() call at the end to transfer the contents final Map<Object, Object> map = (System.getSecurityManager() == null) ? (Map<Object, Object>) this : new HashMap<Object, Object>(); /*/*w ww.j av a 2s.c om*/ * Secure random */ map.put("SecureRandom.Windows-PRNG", "es.mityc.javasign.pkstore.mscapi.mityc.PRNG"); /* * Key store */ map.put("KeyStore.Windows-MY", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$MY"); map.put("KeyStore.Windows-ROOT", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$ROOT"); map.put("KeyStore.Windows-CA", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$CA"); map.put("KeyStore.Windows-LocalMachine-MY", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineMY"); map.put("KeyStore.Windows-LocalMachine-ROOT", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineROOT"); map.put("KeyStore.Windows-LocalMachine-CA", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineCA"); /* * Signature engines */ map.put("Signature.SHA1withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA1"); map.put("Signature.SHA256withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA256"); map.put("Signature.SHA384withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA384"); map.put("Signature.SHA512withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA512"); map.put("Signature.MD5withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$MD5"); map.put("Signature.MD2withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$MD2"); /* * Algorithms aliases */ map.put("Alg.Alias.Signature.RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA-1/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHAwithRSA", "SHA1witRSA"); map.put("Alg.Alias.Signature.RSAWithSHA1", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1withRSA"); map.put("Alg.Alias.Signature.OID.1.3.14.3.2.29", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1withRSAEncryption", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1WithRSAEncryption", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1WITHRSAENCRYPTION", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.1", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256withRSAEncryption", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256WithRSAEncryption", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256/RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA-256/RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256WITHRSAENCRYPTION", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA384withRSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.12", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384withRSAEncryption", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384WithRSAEncryption", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384/RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA-384/RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384WITHRSAENCRYPTION", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA512withRSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.13", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512withRSAEncryption", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512WithRSAEncryption", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512/RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA-512/RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512WITHRSAENCRYPTION", "SHA512withRSA"); // supported key classes map.put("Signature.SHA1withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA256withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA384withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA512withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.MD5withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.MD2withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.NONEwithRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); /* * Key Pair Generator engines */ map.put("KeyPairGenerator.RSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSAKeyPairGenerator"); map.put("KeyPairGenerator.RSA KeySize", "1024"); /* * Cipher engines */ map.put("Cipher.RSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSACipher"); map.put("Cipher.RSA/ECB/PKCS1Padding", "es.mityc.javasign.pkstore.mscapi.mityc.RSACipher"); map.put("Cipher.RSA SupportedModes", "ECB"); map.put("Cipher.RSA SupportedPaddings", "PKCS1PADDING"); map.put("Cipher.RSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); if (map != this) { AccessController.doPrivileged(new PutAllAction(this, map)); } }
From source file:org.beangle.model.persist.hibernate.internal.ChainedClassLoader.java
/** * Adds a class loader defining the given class, to the chained class loader * space./*w w w .j a va 2s. co m*/ * * @param clazz */ public void addClassLoader(final Class<?> clazz) { Validate.notNull(clazz, "a non-null class required"); if (System.getSecurityManager() != null) { addClassLoader(AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return ClassUtils.getClassLoader(clazz); } })); } else { addClassLoader(ClassUtils.getClassLoader(clazz)); } }
From source file:org.pepstock.jem.springbatch.tasks.DataSource.java
/** * Implements the connection to database, using the JNDI reference * @return a SQL connection//from w w w.j a v a2s .co m * @throws SQLException if any error occurs */ private Connection getConnectionImpl() throws SQLException { try { SpringBatchSecurityManager batchSM = (SpringBatchSecurityManager) System.getSecurityManager(); // checks if datasource is well defined if (getResource() == null) { throw new SQLException(SpringBatchMessage.JEMS016E.toMessage().getFormattedMessage()); } else if (getName() == null) { // if name is missing, it uses the same string // used to define the resource setName(getResource()); } // gets the RMi object to get resources CommonResourcer resourcer = InitiatorManager.getCommonResourcer(); // lookups by RMI for the database Resource res = resourcer.lookup(JobId.VALUE, getResource()); if (!batchSM.checkResource(res)) { throw new SQLException(SpringBatchMessage.JEMS017E.toMessage().getFormattedMessage(res.toString())); } // all properties create all StringRefAddrs necessary Map<String, ResourceProperty> props = res.getProperties(); // scans all properteis set by JCL for (Property property : getProperties()) { if (property.isCustom()) { if (res.getCustomProperties() == null) { res.setCustomProperties(new HashMap<String, String>()); } if (!res.getCustomProperties().containsKey(property.getName())) { res.getCustomProperties().put(property.getName(), property.getValue()); } else { throw new SQLException(SpringBatchMessage.JEMS018E.toMessage() .getFormattedMessage(property.getName(), res)); } } else { // if a key is defined FINAL, throw an exception for (ResourceProperty resProperty : props.values()) { if (resProperty.getName().equalsIgnoreCase(property.getName()) && !resProperty.isOverride()) { throw new SQLException(SpringBatchMessage.JEMS018E.toMessage() .getFormattedMessage(property.getName(), res)); } } ResourcePropertiesUtil.addProperty(res, property.getName(), property.getValue()); } } // creates a JNDI reference Reference ref = getReference(resourcer, res); // loads all properties into RefAddr for (ResourceProperty property : props.values()) { ref.add(new StringRefAddr(property.getName(), replaceProperties(property.getValue()))); } // loads custom properties in a string format if (res.getCustomProperties() != null && !res.getCustomProperties().isEmpty()) { // loads all entries and substitute variables for (Entry<String, String> entry : res.getCustomProperties().entrySet()) { String value = replaceProperties(entry.getValue()); entry.setValue(value); } // adds to reference ref.add(new StringRefAddr(CommonKeys.RESOURCE_CUSTOM_PROPERTIES, res.getCustomPropertiesString())); } // binds the object with format {type]/[name] LogAppl.getInstance().emit(SpringBatchMessage.JEMS024I, res); JdbcFactory factory = new JdbcFactory(); javax.sql.DataSource ds = (javax.sql.DataSource) factory.getObjectInstance(ref, null, null, null); return ds.getConnection(); } catch (RemoteException e) { throw new SQLException(e.getMessage(), e); } catch (UnknownHostException e) { throw new SQLException(e.getMessage(), e); } catch (Exception e) { throw new SQLException(e.getMessage(), e); } }
From source file:sernet.gs.ui.rcp.main.logging.LoggerInitializer.java
private SecurityManager getSecurityManager() { SecurityManager security = System.getSecurityManager(); new SecurityManager(); if (security == null) { security = new SecurityManager(); }//from w w w . j a v a2 s.com return security; }
From source file:org.apache.hadoop.hbase.mapreduce.TestCellCounter.java
/** * Test main method of CellCounter/*from ww w . j av a 2s . com*/ */ @Test(timeout = 300000) public void testCellCounterMain() throws Exception { PrintStream oldPrintStream = System.err; SecurityManager SECURITY_MANAGER = System.getSecurityManager(); LauncherSecurityManager newSecurityManager = new LauncherSecurityManager(); System.setSecurityManager(newSecurityManager); ByteArrayOutputStream data = new ByteArrayOutputStream(); String[] args = {}; System.setErr(new PrintStream(data)); try { System.setErr(new PrintStream(data)); try { CellCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains("ERROR: Wrong number of parameters:")); // should be information about usage assertTrue(data.toString().contains("Usage:")); } } finally { System.setErr(oldPrintStream); System.setSecurityManager(SECURITY_MANAGER); } }
From source file:org.apache.catalina.security.SecurityConfig.java
/** * Set the proper security property//from ww w .j a v a 2s. c om * @param properties the package.* property. */ private final void setSecurityProperty(String properties, String packageList) { if (System.getSecurityManager() != null) { String definition = Security.getProperty(properties); if (definition != null && definition.length() > 0) { definition += ","; } Security.setProperty(properties, // FIX ME package "javax." was removed to prevent HotSpot // fatal internal errors definition + packageList); } }
From source file:net.datenwerke.sandbox.SandboxLoader.java
/** * Instantiates a new SandboxLoader with the given ClassLoader as parent. * @param parent//from www . j a va 2 s .c o m */ public SandboxLoader(ClassLoader parent) { this(parent, System.getSecurityManager()); }
From source file:org.wso2.carbon.repository.core.internal.RepositoryServiceComponent.java
/** * Activates the Repository Kernel bundle. * * @param context the OSGi component context. *///from w w w. j a v a 2s. co m protected void activate(ComponentContext context) { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonContext.setTenantDomain(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); carbonContext.setTenantId(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID); // Need permissions in order to activate Registry SecurityManager securityManager = System.getSecurityManager(); if (securityManager != null) { securityManager.checkPermission(new ManagementPermission("control")); } try { bundleContext = context.getBundleContext(); repositoryService = buildRepositoryService(); log.debug("Completed initializing the Registry Kernel"); registrations.push(bundleContext.registerService(new String[] { RepositoryService.class.getName() }, repositoryService, null)); registrations.push(bundleContext.registerService(SimulationService.class.getName(), new DefaultSimulationService(), null)); log.debug("Registry Core bundle is activated "); } catch (Throwable e) { log.error("Failed to activate Registry Core bundle ", e); } }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void refreshFailure(final BlueprintEvent event) { if (dispatcher != null) { try {/*from ww w. j a va 2s .co m*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.refreshFailure(event); return null; } }); } else { dispatcher.refreshFailure(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:org.pepstock.jem.jbpm.tasks.JemWorkItemHandler.java
@Override public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { // gets the java class for workitem String className = (String) workItem.getParameter(CLASS_NAME_KEY); // must be defined if (className == null) { throw new JemRuntimeException(JBpmMessage.JEMM001E.toMessage().getFormattedMessage(CLASS_NAME_KEY)); }//from w ww. j a v a2 s . co m // removes all blank className = className.trim(); // if it still has got blanks, exception if (className.contains(" ")) { throw new JemRuntimeException(JBpmMessage.JEMM056E.toMessage().getFormattedMessage(className)); } // loads parameters as list of properties for substitutions JobsProperties.getInstance().loadParameters(workItem.getParameters()); // checks if there a method to call String methodName = null; if (className.contains(METHOD_DELIMITER)) { methodName = StringUtils.substringAfter(className, METHOD_DELIMITER); className = StringUtils.substringBefore(className, METHOD_DELIMITER); } // sets security manager internal action JBpmBatchSecurityManager batchSM = (JBpmBatchSecurityManager) System.getSecurityManager(); batchSM.setInternalAction(true); // defines the wrapper JemWorkItem wrapper = null; // load class Class<?> clazz; try { clazz = Class.forName(className); // if not method has been set (and ONLY if there isn't) // scans method to see if there the annotation // on the method to call if (methodName == null) { for (Method m : clazz.getDeclaredMethods()) { // checks if there is the annotation // and not already set if (m.isAnnotationPresent(ToBeExecuted.class) && methodName == null) { //set method name methodName = m.getName(); } } } } catch (ClassNotFoundException e) { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM006E, e, className); throw new JemRuntimeException(JBpmMessage.JEMM006E.toMessage().getFormattedMessage(className), e); } // if it has got the method instantiated if (methodName != null) { try { wrapper = new CustomMethodWorkItem(clazz, methodName); } catch (InstantiationException e) { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM006E, e, className); throw new JemRuntimeException(JBpmMessage.JEMM006E.toMessage().getFormattedMessage(className), e); } catch (IllegalAccessException e) { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM006E, e, className); throw new JemRuntimeException(JBpmMessage.JEMM006E.toMessage().getFormattedMessage(className), e); } } else if (MainClassWorkItem.hasMainMethod(clazz)) { wrapper = new MainClassWorkItem(clazz); } else { try { // load by Class.forName of workItem Object instance = clazz.newInstance(); // check if it's a JemWorkItem. if not, // exception occurs. if (instance instanceof JemWorkItem) { wrapper = new DelegatedWorkItem(instance); } else { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM004E, className); throw new JemRuntimeException(JBpmMessage.JEMM004E.toMessage().getFormattedMessage(className)); } } catch (InstantiationException e) { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM006E, e, className); throw new JemRuntimeException(JBpmMessage.JEMM006E.toMessage().getFormattedMessage(className), e); } catch (IllegalAccessException e) { batchSM.setInternalAction(false); LogAppl.getInstance().emit(JBpmMessage.JEMM006E, e, className); throw new JemRuntimeException(JBpmMessage.JEMM006E.toMessage().getFormattedMessage(className), e); } } // gets the current task Task currentTask = CompleteTasksList.getInstance().getTaskByWorkItemID(workItem.getId()); if (currentTask == null) { batchSM.setInternalAction(false); throw new JemRuntimeException(JBpmMessage.JEMM002E.toMessage().getFormattedMessage(workItem.getId())); } // initialize the listener passing parameters // properties try { int returnCode = execute(currentTask, wrapper, workItem.getParameters()); LogAppl.getInstance().emit(JBpmMessage.JEMM057I, currentTask.getId(), returnCode); currentTask.setReturnCode(returnCode); Map<String, Object> output = new HashMap<String, Object>(); output.put(RESULT_KEY, returnCode); manager.completeWorkItem(workItem.getId(), output); } catch (Exception e) { currentTask.setReturnCode(Result.ERROR); throw new JemRuntimeException(e); } }