Search in sources :

Example 31 with PrivilegedActionException

use of java.security.PrivilegedActionException in project wildfly by wildfly.

the class RoleAddingInterceptor method processInvocation.

public Object processInvocation(final InterceptorContext context) throws Exception {
    final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
    Assert.checkNotNullParam("securityDomain", securityDomain);
    final SecurityIdentity currentIdentity = securityDomain.getCurrentSecurityIdentity();
    final RoleMapper mergeMapper = roleMapper.or((roles) -> currentIdentity.getRoles(category));
    final SecurityIdentity newIdentity = currentIdentity.withRoleMapper(category, mergeMapper);
    try {
        return newIdentity.runAs(context);
    } catch (PrivilegedActionException e) {
        Throwable cause = e.getCause();
        if (cause != null) {
            if (cause instanceof Exception) {
                throw (Exception) cause;
            } else {
                throw new RuntimeException(e);
            }
        } else {
            throw e;
        }
    }
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) RoleMapper(org.wildfly.security.authz.RoleMapper) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedActionException(java.security.PrivilegedActionException) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 32 with PrivilegedActionException

use of java.security.PrivilegedActionException in project wildfly by wildfly.

the class ExternalizableExternalizer method readObject.

@Override
public T readObject(ObjectInput input) throws IOException, ClassNotFoundException {
    PrivilegedExceptionAction<T> action = new PrivilegedExceptionAction<T>() {

        @Override
        public T run() throws InstantiationException, IllegalAccessException {
            return ExternalizableExternalizer.this.getTargetClass().newInstance();
        }
    };
    try {
        T object = WildFlySecurityManager.doChecked(action);
        object.readExternal(input);
        return object;
    } catch (PrivilegedActionException e) {
        throw new IOException(e.getCause());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException)

Example 33 with PrivilegedActionException

use of java.security.PrivilegedActionException in project gerrit by GerritCodeReview.

the class Helper method kerberosOpen.

private DirContext kerberosOpen(final Properties env) throws LoginException, NamingException {
    LoginContext ctx = new LoginContext("KerberosLogin");
    ctx.login();
    Subject subject = ctx.getSubject();
    try {
        return Subject.doAs(subject, new PrivilegedExceptionAction<DirContext>() {

            @Override
            public DirContext run() throws NamingException {
                return new InitialDirContext(env);
            }
        });
    } catch (PrivilegedActionException e) {
        Throwables.throwIfInstanceOf(e.getException(), NamingException.class);
        Throwables.throwIfInstanceOf(e.getException(), RuntimeException.class);
        LdapRealm.log.warn("Internal error", e.getException());
        return null;
    } finally {
        ctx.logout();
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) PrivilegedActionException(java.security.PrivilegedActionException) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext) Subject(javax.security.auth.Subject)

Example 34 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class RMIConnectionImpl method addNotificationListener.

// MarshalledObject
@SuppressWarnings("rawtypes")
public void addNotificationListener(ObjectName name, ObjectName listener, MarshalledObject filter, MarshalledObject handback, Subject delegationSubject) throws InstanceNotFoundException, IOException {
    checkNonNull("Target MBean name", name);
    checkNonNull("Listener MBean name", listener);
    final NotificationFilter filterValue;
    final Object handbackValue;
    final boolean debug = logger.debugOn();
    final ClassLoader targetCl = getClassLoaderFor(name);
    if (debug)
        logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + " unwrapping filter with target extended ClassLoader.");
    filterValue = unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class, delegationSubject);
    if (debug)
        logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + " unwrapping handback with target extended ClassLoader.");
    handbackValue = unwrap(handback, targetCl, defaultClassLoader, Object.class, delegationSubject);
    try {
        final Object[] params = new Object[] { name, listener, filterValue, handbackValue };
        if (debug)
            logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + ", name=" + name + ", listenerName=" + listener + ", filter=" + filterValue + ", handback=" + handbackValue);
        doPrivilegedOperation(ADD_NOTIFICATION_LISTENER_OBJECTNAME, params, delegationSubject);
    } catch (PrivilegedActionException pe) {
        Exception e = extractException(pe);
        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException) e;
        if (e instanceof IOException)
            throw (IOException) e;
        throw newIOException("Got unexpected server exception: " + e, e);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) MarshalledObject(java.rmi.MarshalledObject) IOException(java.io.IOException) UnmarshalException(java.rmi.UnmarshalException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Example 35 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class RMIConnectionImpl method doPrivilegedOperation.

private Object doPrivilegedOperation(final int operation, final Object[] params, final Subject delegationSubject) throws PrivilegedActionException, IOException {
    serverCommunicatorAdmin.reqIncoming();
    try {
        final AccessControlContext reqACC;
        if (delegationSubject == null)
            reqACC = acc;
        else {
            if (subject == null) {
                final String msg = "Subject delegation cannot be enabled unless " + "an authenticated subject is put in place";
                throw new SecurityException(msg);
            }
            reqACC = subjectDelegator.delegatedContext(acc, delegationSubject, removeCallerContext);
        }
        PrivilegedOperation op = new PrivilegedOperation(operation, params);
        if (reqACC == null) {
            try {
                return op.run();
            } catch (Exception e) {
                if (e instanceof RuntimeException)
                    throw (RuntimeException) e;
                throw new PrivilegedActionException(e);
            }
        } else {
            return AccessController.doPrivileged(op, reqACC);
        }
    } catch (Error e) {
        throw new JMXServerErrorException(e.toString(), e);
    } finally {
        serverCommunicatorAdmin.rspOutgoing();
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) UnmarshalException(java.rmi.UnmarshalException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)135 IOException (java.io.IOException)58 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)56 Subject (javax.security.auth.Subject)23 LoginContext (javax.security.auth.login.LoginContext)14 LoginException (javax.security.auth.login.LoginException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 Method (java.lang.reflect.Method)11 URISyntaxException (java.net.URISyntaxException)11 HashSet (java.util.HashSet)11 ServletException (javax.servlet.ServletException)11 AccessControlContext (java.security.AccessControlContext)10 Principal (java.security.Principal)9 GSSException (org.ietf.jgss.GSSException)9 Field (java.lang.reflect.Field)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 GSSManager (org.ietf.jgss.GSSManager)7 MalformedURLException (java.net.MalformedURLException)6 ArrayList (java.util.ArrayList)6 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)6