Example usage for java.security PrivilegedAction PrivilegedAction

List of usage examples for java.security PrivilegedAction PrivilegedAction

Introduction

In this page you can find the example usage for java.security PrivilegedAction PrivilegedAction.

Prototype

PrivilegedAction

Source Link

Usage

From source file:org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.java

private URL getResource(final String wsdlLocation, final ClassLoader loader) {
    return (URL) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return loader.getResource(wsdlLocation);
        }// w w w .ja v  a  2 s.c o  m
    });
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java

private static Annotation getAnnotation(final AnnotatedElement element, final Class annotation) {
    return (Annotation) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return element.getAnnotation(annotation);
        }//ww w  . ja v a2s.c  o  m
    });
}

From source file:org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex.java

/**
 * Returns the document element of the indexing configuration or
 * <code>null</code> if there is no indexing configuration.
 * //  w w  w . java2s  .  co m
 * @return the indexing configuration or <code>null</code> if there is none.
 */
protected Element getIndexingConfigurationDOM() {
    if (indexingConfiguration == null) {
        if (indexingConfigPath != null) {

            // File config = PrivilegedFileHelper.file(indexingConfigPath);
            SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>() {
                public Object run() {
                    InputStream is = SearchIndex.class.getResourceAsStream(indexingConfigPath);
                    if (is == null) {
                        try {
                            is = cfm.getInputStream(indexingConfigPath);
                        } catch (Exception e1) {
                            log.warn("Unable to load configuration " + indexingConfigPath);
                        }
                    }

                    try {
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder = factory.newDocumentBuilder();
                        builder.setEntityResolver(new IndexingConfigurationEntityResolver());
                        indexingConfiguration = builder.parse(is).getDocumentElement();
                    } catch (ParserConfigurationException e) {
                        log.warn("Unable to create XML parser", e);
                    } catch (IOException e) {
                        log.warn("Exception parsing " + indexingConfigPath, e);
                    } catch (SAXException e) {
                        log.warn("Exception parsing " + indexingConfigPath, e);
                    }
                    return null;
                }
            });
        }
    }
    return indexingConfiguration;
}

From source file:org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex.java

/**
 * Retrieves the root of the indexing aggregate for
 * <code>removedUUIDs</code> and puts it into <code>map</code>.
 * /*w  ww  . j a va  2  s  .  c  om*/
 * @param removedUUIDs
 *            the UUIDs of removed nodes.
 * @param map
 *            aggregate roots are collected in this map. Key=UUID,
 *            value=NodeState.
 */
protected void retrieveAggregateRoot(final Set<String> removedNodeIds, final Map<String, NodeData> map) {
    if (indexingConfig != null) {
        AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
        if (aggregateRules == null) {
            return;
        }
        long time = 0;
        if (log.isDebugEnabled()) {
            time = System.currentTimeMillis();
        }
        int found = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Integer>() {
            public Integer run() {
                int found = 0;
                try {
                    CachingMultiIndexReader reader = index.getIndexReader();
                    try {
                        Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
                        TermDocs tDocs = reader.termDocs();
                        try {
                            ItemDataConsumer ism = getContext().getItemStateManager();
                            for (Iterator<String> it = removedNodeIds.iterator(); it.hasNext();) {
                                String id = it.next();
                                aggregateUUIDs = aggregateUUIDs.createTerm(id);
                                tDocs.seek(aggregateUUIDs);
                                while (tDocs.next()) {
                                    Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
                                    String uuid = doc.get(FieldNames.UUID);
                                    ItemData itd = ism.getItemData(uuid);
                                    if (itd == null) {
                                        continue;
                                    }
                                    if (!itd.isNode()) {
                                        throw new RepositoryException(
                                                "Item with id:" + uuid + " is not a node");
                                    }
                                    map.put(uuid, (NodeData) itd);
                                    found++;
                                }
                            }
                        } finally {
                            tDocs.close();
                        }
                    } finally {
                        reader.release();
                    }
                } catch (Exception e) {
                    log.warn("Exception while retrieving aggregate roots", e);
                }
                return found;
            }
        });
        if (log.isDebugEnabled()) {
            time = System.currentTimeMillis() - time;
            log.debug("Retrieved {} aggregate roots in {} ms.", new Integer(found), new Long(time));
        }
    }
}

From source file:org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl.java

/**
 * Returns a schema derived java class containing the the handler configuration information.  
 * That information, returned in the HandlerChainsType object, is looked for in the following 
 * places in this order:/*from   w  ww.  j a  v a  2s  .  com*/
 * - Set on the sparseComposite for the given key
 * - Set on the composite
 * - Read in from the file specified on HandlerChain annotation
 * 
 * @return HandlerChainsType This is the top-level element for the Handler configuration file
 * 
 */
public HandlerChainsType getHandlerChain(Object sparseCompositeKey) {

    DescriptionBuilderComposite sparseComposite = null;

    // If there is a HandlerChainsType in the sparse composite for this ServiceDelegate
    // (i.e. this sparseCompositeKey), then return that.
    if (sparseCompositeKey != null) {
        sparseComposite = composite.getSparseComposite(sparseCompositeKey);
        if (sparseComposite != null && sparseComposite.getHandlerChainsType() != null) {
            HandlerChainsType hct = sparseComposite.getHandlerChainsType();
            return hct;
        }
    }

    // If there is no HandlerChainsType in the composite, then read in the file specified
    // on the HandlerChain annotation if it is present.
    if (handlerChainsType == null) {
        getAnnoHandlerChainAnnotation(sparseCompositeKey);
        if (handlerChainAnnotation != null) {
            String handlerFileName = handlerChainAnnotation.file();

            if (log.isDebugEnabled()) {
                log.debug(
                        Messages.getMessage("handlerChainsTypeErr", handlerFileName, composite.getClassName()));
            }

            String className = composite.getClassName();

            // REVIEW: This is using the classloader for EndpointDescriptionImpl; is that OK?
            ClassLoader classLoader = (composite.isServiceProvider()) ? composite.getClassLoader()
                    : (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
                        public Object run() {
                            return this.getClass().getClassLoader();
                        }
                    });

            if (log.isDebugEnabled()) {
                log.debug("Trying to load file " + handlerFileName + " relative to " + className);
            }
            InputStream is = DescriptionUtils.openHandlerConfigStream(handlerFileName, className, classLoader);
            if (is == null) {
                // config stream is still null.  This may mean the @HandlerChain annotation is on a *driver* class
                // next to a @WebServiceRef annotation, so the path is relative to the class declaring @HandlerChain
                // and NOT relative to the Service or Endpoint class, which also means we should use the sparseComposite
                // since that is where the @HandlerChain annotation info would have been loaded.
                if (sparseComposite != null) {
                    String handlerChainDeclaringClass = (String) sparseComposite.getProperties()
                            .get(MDQConstants.HANDLER_CHAIN_DECLARING_CLASS);
                    if (handlerChainDeclaringClass != null) {
                        className = handlerChainDeclaringClass;
                        is = DescriptionUtils.openHandlerConfigStream(handlerFileName, className, classLoader);
                    }
                }
            }

            if (is == null) {
                throw ExceptionFactory.makeWebServiceException(
                        Messages.getMessage("handlerChainNS", handlerFileName, className));
            } else {
                ClassLoader classLoader1 = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        return this.getClass().getClassLoader();
                    }
                });
                handlerChainsType = DescriptionUtils.loadHandlerChains(is, classLoader1);
            }
        }
    }
    return handlerChainsType;
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Play" selection./*from w  w  w  .  java 2  s .c  o m*/
 */
public void pressStart() {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acPlay.fireEvent();
            return null;
        }
    });
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Pause" selection./*from  ww w .jav a  2s  .com*/
 */
public void pressPause() {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acPause.fireEvent();
            return null;
        }
    });
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Stop" selection.//www . j  a va  2s . co  m
 */
public void pressStop() {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acStop.fireEvent();
            return null;
        }
    });
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Next" selection./*from w ww  .  j  a va 2 s .  co  m*/
 */
public void pressNext() {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acNext.fireEvent();
            return null;
        }
    });
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Previous" selection./*from  www .ja  va 2 s. c  o  m*/
 */
public void pressPrevious() {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acPrevious.fireEvent();
            return null;
        }
    });
}