Example usage for java.security PrivilegedActionException getException

List of usage examples for java.security PrivilegedActionException getException

Introduction

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

Prototype

public Exception getException() 

Source Link

Document

Returns the exception thrown by the privileged computation that resulted in this PrivilegedActionException .

Usage

From source file:org.apache.axis2.jaxws.util.WSDL4JWrapper.java

private URLConnection openConnection(final URL url) throws IOException {
    try {//  w w  w .java2  s. c  o  m
        return (URLConnection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                return url.openConnection();
            }
        });
    } catch (PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
}

From source file:org.apache.axis2.jaxws.util.WSDL4JWrapper.java

private URLConnection getPrivilegedURLConnection(final URL url) throws IOException {
    try {/*from w w w .  j  a v  a  2s  .  c o  m*/

        return (URLConnection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                return (getURLConnection(url));
            }
        });

    } catch (PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
}

From source file:org.apache.zeppelin.realm.kerberos.KerberosRealm.java

/**
 * Initializes the KerberosRealm by 'kinit'ing using principal and keytab.
 * <p>/*w  ww . j av  a  2  s  . co  m*/
 * It creates a Kerberos context using the principal and keytab specified in
 * the Shiro configuration.
 * <p>
 * This method should be called only once.
 *
 * @throws RuntimeException thrown if the handler could not be initialized.
 */
@Override
protected void onInit() {
    super.onInit();
    config = getConfiguration();
    try {
        if (principal == null || principal.trim().length() == 0) {
            throw new RuntimeException("Principal not defined in configuration");
        }

        if (keytab == null || keytab.trim().length() == 0) {
            throw new RuntimeException("Keytab not defined in configuration");
        }

        File keytabFile = new File(keytab);
        if (!keytabFile.exists()) {
            throw new RuntimeException("Keytab file does not exist: " + keytab);
        }

        // use all SPNEGO principals in the keytab if a principal isn't
        // specifically configured
        final String[] spnegoPrincipals;
        if (principal.equals("*")) {
            spnegoPrincipals = KerberosUtil.getPrincipalNames(keytab, Pattern.compile("HTTP/.*"));
            if (spnegoPrincipals.length == 0) {
                throw new RuntimeException("Principals do not exist in the keytab");
            }
        } else {
            spnegoPrincipals = new String[] { principal };
        }
        KeyTab keytabInstance = KeyTab.getInstance(keytabFile);

        serverSubject = new Subject();
        serverSubject.getPrivateCredentials().add(keytabInstance);
        for (String spnegoPrincipal : spnegoPrincipals) {
            Principal krbPrincipal = new KerberosPrincipal(spnegoPrincipal);
            LOG.info("Using keytab {}, for principal {}", keytab, krbPrincipal);
            serverSubject.getPrincipals().add(krbPrincipal);
        }

        if (nameRules == null || nameRules.trim().length() == 0) {
            LOG.warn("No auth_to_local rules defined, DEFAULT will be used.");
            nameRules = "DEFAULT";
        }

        KerberosName.setRules(nameRules);

        if (null == gssManager) {
            try {
                gssManager = Subject.doAs(serverSubject, new PrivilegedExceptionAction<GSSManager>() {
                    @Override
                    public GSSManager run() {
                        return GSSManager.getInstance();
                    }
                });
                LOG.trace("SPNEGO gssManager initialized.");
            } catch (PrivilegedActionException ex) {
                throw ex.getException();
            }
        }

        if (null == signer) {
            initializeSecretProvider();
        }

        Configuration hadoopConfig = new Configuration();
        hadoopGroups = new Groups(hadoopConfig);

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Remove this Session from the active Sessions for this Manager,
 * and from the Store.//from w  w  w. ja  va 2 s .c  o  m
 *
 * @param is Session's id to be removed
 */
protected void removeSession(String id) {
    try {
        if (System.getSecurityManager() != null) {
            try {
                AccessController.doPrivileged(new PrivilegedStoreRemove(id));
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                exception.printStackTrace();
            }
        } else {
            store.remove(id);
        }
    } catch (IOException e) {
        log.error("Exception removing session  " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Clear all sessions from the Store.// w  w  w.j a  v  a2 s . c  o m
 */
public void clearStore() {

    if (store == null)
        return;

    try {
        if (System.getSecurityManager() != null) {
            try {
                AccessController.doPrivileged(new PrivilegedStoreClear());
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                exception.printStackTrace();
            }
        } else {
            store.clear();
        }
    } catch (IOException e) {
        log.error("Exception clearing the Store: " + e);
        e.printStackTrace();
    }

}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Write the provided session to the Store without modifying
 * the copy in memory or triggering passivation events. Does
 * nothing if the session is invalid or past its expiration.
 *//*from   w w w. j a va 2s  . c  o  m*/
protected void writeSession(Session session) throws IOException {

    if (store == null || !session.isValid()) {
        return;
    }

    try {
        if (System.getSecurityManager() != null) {
            try {
                AccessController.doPrivileged(new PrivilegedStoreSave(session));
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                exception.printStackTrace();
            }
        } else {
            store.save(session);
        }
    } catch (IOException e) {
        log.error(sm.getString("persistentManager.serializeError", session.getId(), e));
        throw e;
    }

}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Load all sessions found in the persistence mechanism, assuming
 * they are marked as valid and have not passed their expiration
 * limit. If persistence is not supported, this method returns
 * without doing anything.//  www  .  j  av a 2 s.c  om
 * <p>
 * Note that by default, this method is not called by the MiddleManager
 * class. In order to use it, a subclass must specifically call it,
 * for example in the start() and/or processPersistenceChecks() methods.
 */
public void load() {

    // Initialize our internal data structures
    sessions.clear();

    if (store == null)
        return;

    String[] ids = null;
    try {
        if (System.getSecurityManager() != null) {
            try {
                ids = (String[]) AccessController.doPrivileged(new PrivilegedStoreKeys());
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                exception.printStackTrace();
            }
        } else {
            ids = store.keys();
        }
    } catch (IOException e) {
        log.error("Can't load sessions from store, " + e.getMessage(), e);
        return;
    }

    int n = ids.length;
    if (n == 0)
        return;

    if (log.isDebugEnabled())
        log.debug(sm.getString("persistentManager.loading", String.valueOf(n)));

    for (int i = 0; i < n; i++)
        try {
            swapIn(ids[i]);
        } catch (IOException e) {
            log.error("Failed load session from store, " + e.getMessage(), e);
        }

}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Look for a session in the Store and, if found, restore
 * it in the Manager's list of active sessions if appropriate.
 * The session will be removed from the Store after swapping
 * in, but will not be added to the active session list if it
 * is invalid or past its expiration./*from  w w  w  .  j  a va 2  s .  c  o m*/
 */
protected Session swapIn(String id) throws IOException {

    if (store == null)
        return null;

    Session session = null;
    try {
        if (System.getSecurityManager() != null) {
            try {
                session = (Session) AccessController.doPrivileged(new PrivilegedStoreLoad(id));
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                if (exception instanceof IOException) {
                    throw (IOException) exception;
                } else if (exception instanceof ClassNotFoundException) {
                    throw (ClassNotFoundException) exception;
                }
            }
        } else {
            session = store.load(id);
        }
    } catch (ClassNotFoundException e) {
        log.error(sm.getString("persistentManager.deserializeError", id, e));
        throw new IllegalStateException(sm.getString("persistentManager.deserializeError", id, e));
    }

    if (session == null)
        return (null);

    if (!session.isValid()) {
        log.error("session swapped in is invalid or expired");
        session.expire();
        removeSession(id);
        return (null);
    }

    if (log.isDebugEnabled())
        log.debug(sm.getString("persistentManager.swapIn", id));

    session.setManager(this);
    // make sure the listeners know about it.
    ((StandardSession) session).tellNew();
    add(session);
    ((StandardSession) session).activate();

    return (session);

}

From source file:org.apache.openjpa.jdbc.meta.ReverseMappingTool.java

/**
 * Run the tool. Returns false if invalid options were given.
 *
 * @see #main/*from   w w  w  .j a  v  a  2s  . c o  m*/
 */
public static boolean run(JDBCConfiguration conf, String[] args, Options opts)
        throws IOException, SQLException {
    // flags
    Flags flags = new Flags();
    flags.packageName = opts.removeProperty("package", "pkg", flags.packageName);
    flags.directory = Files.getFile(opts.removeProperty("directory", "d", null), null);
    flags.useSchemaName = opts.removeBooleanProperty("useSchemaName", "sn", flags.useSchemaName);
    flags.useForeignKeyName = opts.removeBooleanProperty("useForeignKeyName", "fkn", flags.useForeignKeyName);
    flags.nullableAsObject = opts.removeBooleanProperty("nullableAsObject", "no", flags.nullableAsObject);
    flags.blobAsObject = opts.removeBooleanProperty("blobAsObject", "bo", flags.blobAsObject);
    flags.useGenericCollections = opts.removeBooleanProperty("useGenericCollections", "gc",
            flags.useGenericCollections);
    flags.primaryKeyOnJoin = opts.removeBooleanProperty("primaryKeyOnJoin", "pkj", flags.primaryKeyOnJoin);
    flags.useDataStoreIdentity = opts.removeBooleanProperty("useDatastoreIdentity", "ds",
            flags.useDataStoreIdentity);
    flags.useBuiltinIdentityClass = opts.removeBooleanProperty("useBuiltinIdentityClass", "bic",
            flags.useBuiltinIdentityClass);
    flags.innerIdentityClasses = opts.removeBooleanProperty("innerIdentityClasses", "inn",
            flags.innerIdentityClasses);
    flags.identityClassSuffix = opts.removeProperty("identityClassSuffix", "is", flags.identityClassSuffix);
    flags.inverseRelations = opts.removeBooleanProperty("inverseRelations", "ir", flags.inverseRelations);
    flags.detachable = opts.removeBooleanProperty("detachable", "det", flags.detachable);
    flags.discriminatorStrategy = opts.removeProperty("discriminatorStrategy", "ds",
            flags.discriminatorStrategy);
    flags.versionStrategy = opts.removeProperty("versionStrategy", "vs", flags.versionStrategy);
    flags.metaDataLevel = opts.removeProperty("metadata", "md", flags.metaDataLevel);
    flags.generateAnnotations = opts.removeBooleanProperty("annotations", "ann", flags.generateAnnotations);
    flags.accessType = opts.removeProperty("accessType", "access", flags.accessType);

    String typeMap = opts.removeProperty("typeMap", "typ", null);
    if (typeMap != null)
        flags.typeMap = Configurations.parseProperties(typeMap);

    // remap the -s shortcut to the "schemas" property name so that it
    // gets set into the configuration
    if (opts.containsKey("s"))
        opts.put("schemas", opts.get("s"));

    // customizer
    String customCls = opts.removeProperty("customizerClass", "cc",
            PropertiesReverseCustomizer.class.getName());
    File customFile = Files.getFile(opts.removeProperty("customizerProperties", "cp", null), null);
    Properties customProps = new Properties();
    if (customFile != null
            && (AccessController.doPrivileged(J2DoPrivHelper.existsAction(customFile))).booleanValue()) {
        FileInputStream fis = null;
        try {
            fis = AccessController.doPrivileged(J2DoPrivHelper.newFileInputStreamAction(customFile));
        } catch (PrivilegedActionException pae) {
            throw (FileNotFoundException) pae.getException();
        }
        customProps.load(fis);
    }

    // separate the properties for the customizer and code format
    Options customOpts = new Options();
    Options formatOpts = new Options();
    Map.Entry entry;
    String key;
    for (Iterator itr = opts.entrySet().iterator(); itr.hasNext();) {
        entry = (Map.Entry) itr.next();
        key = (String) entry.getKey();
        if (key.startsWith("customizer.")) {
            customOpts.put(key.substring(11), entry.getValue());
            itr.remove();
        } else if (key.startsWith("c.")) {
            customOpts.put(key.substring(2), entry.getValue());
            itr.remove();
        } else if (key.startsWith("codeFormat.")) {
            formatOpts.put(key.substring(11), entry.getValue());
            itr.remove();
        } else if (key.startsWith("cf.")) {
            formatOpts.put(key.substring(3), entry.getValue());
            itr.remove();
        }
    }

    // code format
    if (!formatOpts.isEmpty()) {
        flags.format = new CodeFormat();
        formatOpts.setInto(flags.format);
    }

    // setup a configuration instance with cmd-line info
    Configurations.populateConfiguration(conf, opts);
    ClassLoader loader = conf.getClassResolverInstance().getClassLoader(ReverseMappingTool.class, null);

    // customizer
    flags.customizer = (ReverseCustomizer) Configurations.newInstance(customCls, loader);
    if (flags.customizer != null) {
        Configurations.configureInstance(flags.customizer, conf, customOpts);
        flags.customizer.setConfiguration(customProps);
    }

    run(conf, args, flags, loader);
    return true;
}

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

private String readLegacyWebMethodFlag() {

    String legacyWebmethod = null;

    try {/*from   w w w  .  ja  va  2s  .  c  om*/
        legacyWebmethod = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() {
                //System property takes precedence over manifest property.
                //So first lets check for system property.
                return (System.getProperty(MDQConstants.USE_LEGACY_WEB_METHOD_RULES));
            }
        });
    } catch (PrivilegedActionException e) {
        // Swallow and continue
        if (log.isWarnEnabled()) {
            log.debug("Exception getting USE_LEGACY_WEB_METHOD_RULES system property: " + e.getException());
        }
    }
    //System property not set, so let return the manifest property.
    if (!WSToolingUtils.hasValue(legacyWebmethod)) {
        if (log.isDebugEnabled()) {
            log.debug("EndpointInterfaceDescriptionImpl: system property '"
                    + MDQConstants.USE_LEGACY_WEB_METHOD_RULES + "' not set");
        }
        ConfigurationContext configContext = getEndpointDescription().getServiceDescription()
                .getAxisConfigContext();
        if (configContext != null) {
            if (log.isDebugEnabled()) {
                log.debug("EndpointInterfaceDescriptionImpl: Reading Manifest property '"
                        + MDQConstants.USE_MANIFEST_LEGACY_WEB_METHOD_RULES + "'");
            }
            String param = (String) configContext
                    .getProperty(MDQConstants.USE_MANIFEST_LEGACY_WEB_METHOD_RULES);
            if (param == null) {
                if (log.isDebugEnabled()) {
                    log.debug("EndpointInterfaceDescriptionImpl: Manifest property '"
                            + MDQConstants.USE_MANIFEST_LEGACY_WEB_METHOD_RULES + "' not set");
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("EndpointInterfaceDescriptionImpl: Manifest property '"
                            + MDQConstants.USE_MANIFEST_LEGACY_WEB_METHOD_RULES + "' is set to" + param);
                }
                legacyWebmethod = param;
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("EndpointInterfaceDescriptionImpl: Unable to Read Manifest property '"
                        + MDQConstants.USE_MANIFEST_LEGACY_WEB_METHOD_RULES + "'");
                log.debug("EndpointInterfaceDescriptionImpl: AxisConfigContext was null");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("EndpointInterfaceDescriptionImpl: system property '"
                    + MDQConstants.USE_LEGACY_WEB_METHOD_RULES + "' set");
        }
    }
    return legacyWebmethod;
}