Search in sources :

Example 86 with PrivilegedActionException

use of java.security.PrivilegedActionException in project otter by alibaba.

the class Integers method getClassMetadata.

/*
     * A helper method for manipulating a class metadata cache.
     */
private static ClassMetadata getClassMetadata(final Class cls, final Map metadataMap, final ClassAccessPrivilegedAction caAction, final FieldAccessPrivilegedAction faAction) {
    if (null == cls) {
        return null;
    }
    ClassMetadata result;
    synchronized (metadataMap) {
        result = (ClassMetadata) metadataMap.get(cls);
    }
    if (result != null) {
        return result;
    }
    int primitiveFieldCount = 0;
    // java.lang.Object shell
    int shellSize = OBJECT_SHELL_SIZE;
    final List /* Field */
    refFields = new LinkedList();
    final Field[] declaredFields;
    try {
        caAction.setContext(cls);
        declaredFields = (Field[]) AccessController.doPrivileged(caAction);
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException("could not access declared fields of class " + cls.getName() + ": " + pae.getException());
    }
    for (int f = 0; f < declaredFields.length; ++f) {
        final Field field = declaredFields[f];
        if (Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        /*
             * Can't do that: HashMap data is transient, for example... if (Modifier.isTransient(field.getModifiers()))
             * { shellSize += OBJREF_SIZE; continue; }
             */
        final Class fieldType = field.getType();
        if (fieldType.isPrimitive()) {
            // memory alignment ignored:
            shellSize += sizeofPrimitiveType(fieldType);
            ++primitiveFieldCount;
        } else {
            // prepare for graph traversal later:
            if (!field.isAccessible()) {
                try {
                    faAction.setContext(field);
                    AccessController.doPrivileged(faAction);
                } catch (PrivilegedActionException pae) {
                    throw new RuntimeException("could not make field " + field + " accessible: " + pae.getException());
                }
            }
            // memory alignment ignored:
            shellSize += OBJREF_SIZE;
            refFields.add(field);
        }
    }
    // recurse into superclass:
    final ClassMetadata superMetadata = getClassMetadata(cls.getSuperclass(), metadataMap, caAction, faAction);
    if (superMetadata != null) {
        primitiveFieldCount += superMetadata.m_primitiveFieldCount;
        shellSize += superMetadata.m_shellSize - OBJECT_SHELL_SIZE;
        refFields.addAll(Arrays.asList(superMetadata.m_refFields));
    }
    final Field[] _refFields = new Field[refFields.size()];
    refFields.toArray(_refFields);
    result = new ClassMetadata(primitiveFieldCount, shellSize, _refFields);
    synchronized (metadataMap) {
        metadataMap.put(cls, result);
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 87 with PrivilegedActionException

use of java.security.PrivilegedActionException in project es6draft by anba.

the class UnsafeHolder method initializeUnsafe.

private static Unsafe initializeUnsafe() {
    try {
        return Unsafe.getUnsafe();
    } catch (SecurityException e) {
        try {
            return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
                Field f = Unsafe.class.getDeclaredField("theUnsafe");
                f.setAccessible(true);
                return (Unsafe) f.get(null);
            });
        } catch (PrivilegedActionException e2) {
            throw new ExceptionInInitializerError(e2.getException());
        }
    }
}
Also used : Field(java.lang.reflect.Field) PrivilegedActionException(java.security.PrivilegedActionException) Unsafe(sun.misc.Unsafe) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 88 with PrivilegedActionException

use of java.security.PrivilegedActionException in project es6draft by anba.

the class UnsafeHolder method initializeUnsafe.

private static Unsafe initializeUnsafe() {
    try {
        return Unsafe.getUnsafe();
    } catch (SecurityException e) {
        try {
            return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
                Field f = Unsafe.class.getDeclaredField("theUnsafe");
                f.setAccessible(true);
                return (Unsafe) f.get(null);
            });
        } catch (PrivilegedActionException e2) {
            throw new ExceptionInInitializerError(e2.getException());
        }
    }
}
Also used : Field(java.lang.reflect.Field) PrivilegedActionException(java.security.PrivilegedActionException) Unsafe(sun.misc.Unsafe) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 89 with PrivilegedActionException

use of java.security.PrivilegedActionException in project spring-framework by spring-projects.

the class AbstractNestablePropertyAccessor method processLocalProperty.

private void processLocalProperty(PropertyTokenHolder tokens, PropertyValue pv) {
    PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
    if (ph == null || !ph.isWritable()) {
        if (pv.isOptional()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignoring optional value for property '" + tokens.actualName + "' - property not found on bean class [" + getRootClass().getName() + "]");
            }
            return;
        } else {
            throw createNotWritablePropertyException(tokens.canonicalName);
        }
    }
    Object oldValue = null;
    try {
        Object originalValue = pv.getValue();
        Object valueToApply = originalValue;
        if (!Boolean.FALSE.equals(pv.conversionNecessary)) {
            if (pv.isConverted()) {
                valueToApply = pv.getConvertedValue();
            } else {
                if (isExtractOldValueForEditor() && ph.isReadable()) {
                    try {
                        oldValue = ph.getValue();
                    } catch (Exception ex) {
                        if (ex instanceof PrivilegedActionException) {
                            ex = ((PrivilegedActionException) ex).getException();
                        }
                        if (logger.isDebugEnabled()) {
                            logger.debug("Could not read previous value of property '" + this.nestedPath + tokens.canonicalName + "'", ex);
                        }
                    }
                }
                valueToApply = convertForProperty(tokens.canonicalName, oldValue, originalValue, ph.toTypeDescriptor());
            }
            pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
        }
        ph.setValue(this.wrappedObject, valueToApply);
    } catch (TypeMismatchException ex) {
        throw ex;
    } catch (InvocationTargetException ex) {
        PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this.rootObject, this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
        if (ex.getTargetException() instanceof ClassCastException) {
            throw new TypeMismatchException(propertyChangeEvent, ph.getPropertyType(), ex.getTargetException());
        } else {
            Throwable cause = ex.getTargetException();
            if (cause instanceof UndeclaredThrowableException) {
                // May happen e.g. with Groovy-generated methods
                cause = cause.getCause();
            }
            throw new MethodInvocationException(propertyChangeEvent, cause);
        }
    } catch (Exception ex) {
        PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
        throw new MethodInvocationException(pce, ex);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PrivilegedActionException(java.security.PrivilegedActionException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) PrivilegedActionException(java.security.PrivilegedActionException) ConversionException(org.springframework.core.convert.ConversionException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 90 with PrivilegedActionException

use of java.security.PrivilegedActionException in project spring-framework by spring-projects.

the class AbstractAutowireCapableBeanFactory method invokeCustomInitMethod.

/**
	 * Invoke the specified custom init method on the given bean.
	 * Called by invokeInitMethods.
	 * <p>Can be overridden in subclasses for custom resolution of init
	 * methods with arguments.
	 * @see #invokeInitMethods
	 */
protected void invokeCustomInitMethod(String beanName, final Object bean, RootBeanDefinition mbd) throws Throwable {
    String initMethodName = mbd.getInitMethodName();
    final Method initMethod = (mbd.isNonPublicAccessAllowed() ? BeanUtils.findMethod(bean.getClass(), initMethodName) : ClassUtils.getMethodIfAvailable(bean.getClass(), initMethodName));
    if (initMethod == null) {
        if (mbd.isEnforceInitMethod()) {
            throw new BeanDefinitionValidationException("Couldn't find an init method named '" + initMethodName + "' on bean with name '" + beanName + "'");
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("No default init method named '" + initMethodName + "' found on bean with name '" + beanName + "'");
            }
            // Ignore non-existent default lifecycle methods.
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Invoking init method  '" + initMethodName + "' on bean with name '" + beanName + "'");
    }
    if (System.getSecurityManager() != null) {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                ReflectionUtils.makeAccessible(initMethod);
                return null;
            }
        });
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                @Override
                public Object run() throws Exception {
                    initMethod.invoke(bean);
                    return null;
                }
            }, getAccessControlContext());
        } catch (PrivilegedActionException pae) {
            InvocationTargetException ex = (InvocationTargetException) pae.getException();
            throw ex.getTargetException();
        }
    } else {
        try {
            ReflectionUtils.makeAccessible(initMethod);
            initMethod.invoke(bean);
        } catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) Method(java.lang.reflect.Method) BeanCurrentlyInCreationException(org.springframework.beans.factory.BeanCurrentlyInCreationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsatisfiedDependencyException(org.springframework.beans.factory.UnsatisfiedDependencyException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) PrivilegedActionException(java.security.PrivilegedActionException) BeansException(org.springframework.beans.BeansException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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