List of usage examples for java.security PrivilegedActionException getException
public Exception getException()
From source file:org.tinygroup.jspengine.runtime.PageContextImpl.java
/** * Evaluates an EL expression//from w w w .j av a 2 s. c om * * @param expression The expression to be evaluated * @param expectedType The expected resulting type * @param pageContext The page context * @param functionMap Maps prefix and name to Method * @return The result of the evaluation */ public static Object evaluateExpression(final String expression, final Class expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap) throws ELException { Object retValue; if (SecurityUtil.isPackageProtectionEnabled()) { try { retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { ELContextImpl elContext = (ELContextImpl) pageContext.getELContext(); elContext.setFunctionMapper(functionMap); ExpressionFactory expFactory = getExpressionFactory(pageContext); ValueExpression expr = expFactory.createValueExpression(elContext, expression, expectedType); return expr.getValue(elContext); } }); } catch (PrivilegedActionException ex) { Exception realEx = ex.getException(); if (realEx instanceof ELException) { throw (ELException) realEx; } else { throw new ELException(realEx); } } } else { ELContextImpl elContext = (ELContextImpl) pageContext.getELContext(); elContext.setFunctionMapper(functionMap); ExpressionFactory expFactory = getExpressionFactory(pageContext); ValueExpression expr = expFactory.createValueExpression(elContext, expression, expectedType); retValue = expr.getValue(elContext); } return retValue; }
From source file:org.apache.axis2.jaxws.util.WSDL4JWrapper.java
private static WSDLReader getWSDLReader() throws WSDLException { // Keep this method private WSDLReader reader;/*from w ww . j ava 2s.c o m*/ try { reader = (WSDLReader) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws WSDLException { WSDLFactory factory = WSDLFactory.newInstance(); return factory.newWSDLReader(); } }); } catch (PrivilegedActionException e) { throw (WSDLException) e.getException(); } WSDLReaderConfigurator configurator = (WSDLReaderConfigurator) MetadataFactoryRegistry .getFactory(WSDLReaderConfigurator.class); if (configurator != null) { if (log.isDebugEnabled()) { log.debug("Calling configureReaderInstance with: " + configurator.getClass().getName()); } configurator.configureReaderInstance(reader); } return reader; }
From source file:org.wso2.carbon.client.configcontext.provider.Axis2ClientConfigContextProviderImpl.java
/** * Returns the Configuration Context for the specified tenant ID, * Create a Configuration Context if not already created, and return it. * If the client Configuration Context for that tenant is available, it will return it. * /*from w w w . j a v a 2 s.co m*/ * @param tenantID * @return * @throws RemoteException */ public ConfigurationContext getConfigurationContext() throws RemoteException { ConfigurationContext configurationContext = null; int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (Axis2ClientConfigurationContextStore.getInstance().getTenantConfigurationContextMap() .containsKey(tenantID)) { configurationContext = Axis2ClientConfigurationContextStore.getInstance() .getTenantConfigurationContextMap().get(tenantID); log.debug("Configuration context for the Tenant: " + tenantID + " already exists."); } else { try { configurationContext = (ConfigurationContext) AccessController .doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws RemoteException { return ConfigurationContextFactory .createConfigurationContextFromFileSystem(CONFIG_LOCATION, null); } }); log.info("Created new configuration context for the Tenant: " + tenantID); } catch (PrivilegedActionException e) { throw (RemoteException) e.getException(); } Axis2ClientConfigurationContextStore.getInstance().getTenantConfigurationContextMap().put(tenantID, configurationContext); } return configurationContext; }
From source file:org.apache.axis2.jaxws.spi.ServiceDelegate.java
/** * Return the class for this name//w ww . ja va2 s . c om * * @return Class */ private static Class forName(final String className, final boolean initialize, final ClassLoader classLoader) throws ClassNotFoundException { // NOTE: This method must remain protected because it uses AccessController Class cl = null; try { cl = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { return Class.forName(className, initialize, classLoader); } }); } catch (PrivilegedActionException e) { if (log.isDebugEnabled()) { log.debug("Exception thrown from AccessController: " + e); } throw (ClassNotFoundException) e.getException(); } return cl; }
From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java
private static Definition getWSDLDefinition(String wsdlLoc) { Definition wsdlDefinition = null;//w w w . j av a 2 s . c om final String wsdlLocation = wsdlLoc; if (wsdlLocation != null && wsdlLocation.trim().length() > 0) { try { wsdlDefinition = (Definition) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws MalformedURLException, IOException, WSDLException { String baseDir = new File(System.getProperty("basedir", ".")).getCanonicalPath(); String wsdlLocationPath = new File(baseDir + File.separator + wsdlLocation) .getAbsolutePath(); File file = new File(wsdlLocationPath); URL url = file.toURL(); if (log.isDebugEnabled()) { log.debug("Reading WSDL from URL:" + url.toString()); } // This is a temporary wsdl and we use it to dig into the schemas, // Thus the memory limit is set to false. It will be discarded after it is used // by the PackageSetBuilder implementation. WSDLWrapper wsdlWrapper = new WSDL4JWrapper(url, false, 0); return wsdlWrapper.getDefinition(); } }); } catch (PrivilegedActionException e) { // Swallow and continue if (log.isDebugEnabled()) { log.debug("Exception getting wsdlLocation: " + e.getException()); } } } return wsdlDefinition; }
From source file:com.scoredev.scores.HighScore.java
/** * get the high score. return -1 if it hasn't been set. * *///from ww w . j a v a 2s . co m public int getHighScore() throws IOException, ClassNotFoundException { //check permission first SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new HighScorePermission(gameName)); } Integer score = null; // need a doPrivileged block to manipulate the file try { score = (Integer) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException, ClassNotFoundException { Hashtable scores = null; // try to open the existing file. Should have a locking // protocol (could use File.createNewFile). FileInputStream fis = new FileInputStream(highScoreFile); ObjectInputStream ois = new ObjectInputStream(fis); scores = (Hashtable) ois.readObject(); // get the high score out return scores.get(gameName); } }); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); if (e instanceof IOException) throw (IOException) e; else throw (ClassNotFoundException) e; } if (score == null) return -1; else return score.intValue(); }
From source file:com.scoredev.scores.HighScore.java
public void setHighScore(final int score) throws IOException { //check permission first SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new HighScorePermission(gameName)); }/*from www .jav a2s .co m*/ // need a doPrivileged block to manipulate the file try { AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { Hashtable scores = null; // try to open the existing file. Should have a locking // protocol (could use File.createNewFile). try { FileInputStream fis = new FileInputStream(highScoreFile); ObjectInputStream ois = new ObjectInputStream(fis); scores = (Hashtable) ois.readObject(); } catch (Exception e) { // ignore, try and create new file } // if scores is null, create a new hashtable if (scores == null) scores = new Hashtable(13); // update the score and save out the new high score scores.put(gameName, new Integer(score)); FileOutputStream fos = new FileOutputStream(highScoreFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(scores); oos.close(); return null; } }); } catch (PrivilegedActionException pae) { throw (IOException) pae.getException(); } }
From source file:org.apache.axis2.jaxws.spi.ServiceDelegate.java
/** @return ClassLoader */ private static ClassLoader getClassLoader(final Class cls) { // NOTE: This method must remain private because it uses AccessController ClassLoader cl = null;// w ww . ja v a 2 s. c om try { cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { return cls.getClassLoader(); } }); } catch (PrivilegedActionException e) { if (log.isDebugEnabled()) { log.debug("Exception thrown from AccessController: " + e); } throw ExceptionFactory.makeWebServiceException(e.getException()); } return cl; }
From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java
/** * Return the class for this name/* ww w. ja va 2s.c om*/ * * @return Class */ static Class forName(final String className, final boolean initialize, final ClassLoader classloader) throws ClassNotFoundException { // NOTE: This method must remain protected because it uses AccessController Class cl = null; try { cl = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { // Class.forName does not support primitives Class cls = ClassUtils.getPrimitiveClass(className); if (cls == null) { cls = Class.forName(className, initialize, classloader); } return cls; } }); } catch (PrivilegedActionException e) { if (log.isDebugEnabled()) { log.debug("Exception thrown from AccessController: " + e); } throw (ClassNotFoundException) e.getException(); } return cl; }
From source file:com.netspective.commons.io.UriAddressableUniqueFileLocator.java
/** * Creates a new file resource locator that will use the specified directory * as the base directory for loading templates. * * @param baseDir the base directory for loading templates *///from ww w . ja v a 2 s .c o m public UriAddressableUniqueFileLocator(final String rootUrl, final File baseDir, final boolean cacheLocations) throws IOException { this.rootUrl = rootUrl; this.cacheLocations = cacheLocations; try { Object[] retval = (Object[]) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { if (!baseDir.exists()) { throw new FileNotFoundException(baseDir + " does not exist."); } if (!baseDir.isDirectory()) { throw new IOException(baseDir + " is not a directory."); } Object[] retval = new Object[2]; retval[0] = baseDir.getCanonicalFile(); retval[1] = ((File) retval[0]).getPath() + File.separatorChar; return retval; } }); this.baseDir = (File) retval[0]; this.canonicalPath = (String) retval[1]; } catch (PrivilegedActionException e) { throw (IOException) e.getException(); } }