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.axiom.om.util.StAXUtils.java

/**
 * @return Trhead Context ClassLoader/*  ww w .  ja  v a  2s.  co  m*/
 */
private static ClassLoader getContextClassLoader() {
    ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });

    return cl;
}

From source file:org.apache.axis2.datasource.jaxb.JAXBDSContext.java

/**
 * convert the String into a list or array
 * @param <T>/*from ww  w. jav a 2s  . co  m*/
 * @param jaxb
 * @param type
 * @return
 * @throws IllegalAccessException
 * @throws ParseException
 * @throws NoSuchMethodException
 * @throws InstantiationException
 * @throws DatatypeConfigurationException
 * @throws InvocationTargetException
 */
public static Object unmarshalAsListOrArray(final XMLStreamReader reader, final Unmarshaller u, Class type)
        throws IllegalAccessException, ParseException, NoSuchMethodException, InstantiationException,
        DatatypeConfigurationException, InvocationTargetException, JAXBException {

    if (DEBUG_ENABLED) {
        log.debug("Invoking unmarshalAsListOrArray");
    }

    // If this is an xsd:list, we need to return the appropriate
    // list or array (see NOTE above)
    // First unmarshal as a String
    Object jaxb = null;
    try {
        jaxb = AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                try {
                    return u.unmarshal(reader, String.class);
                } catch (OMException e) {
                    throw e;
                } catch (Throwable t) {
                    throw new OMException(t);
                }
            }
        });
    } catch (OMException e) {
        throw e;
    } catch (Throwable t) {
        throw new OMException(t);
    }
    //Second convert the String into a list or array
    if (getTypeEnabledObject(jaxb) instanceof String) {
        QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
        Object obj = XSDListUtils.fromXSDListString((String) getTypeEnabledObject(jaxb), type);
        return new JAXBElement(qName, type, obj);
    } else {
        return jaxb;
    }

}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductBundlesController.java

/**
 * This method returns the Collection of Resource Component
 * /*  w  w w .  j a  v  a2 s.c o m*/
 * @param serviceInstanceUUID
 * @param resourceTypeId
 * @param component
 * @return
 * @throws ConnectorManagementServiceException
 */
@RequestMapping(value = ("/getComponentValue"), method = RequestMethod.GET)
@ResponseBody
public Collection<ResourceComponent> getServiceResourceComponentValues(
        @RequestParam(value = "serviceInstance", required = true) final String serviceInstanceUUID,
        @RequestParam(value = "resourceType", required = true) long resourceTypeId,
        @RequestParam(value = "component", required = true) final String component)
        throws ConnectorManagementServiceException {
    logger.debug("### getServiceResourceComponentValues method starting...");

    final ServiceResourceType resourceTypeObj = connectorConfigurationManager
            .getServiceResourceTypeById(resourceTypeId);

    return privilegeService.runAsPortal(new PrivilegedAction<Collection<ResourceComponent>>() {

        @Override
        public Collection<ResourceComponent> run() {
            return ((CloudConnector) connectorManagementService.getServiceInstance(serviceInstanceUUID))
                    .getMetadataRegistry()
                    .getResourceComponentValues(resourceTypeObj.getResourceTypeName(), component);
        }
    });
}

From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java

@SuppressWarnings("unchecked")
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
    String propertyName = tokens.canonicalName;
    String actualName = tokens.actualName;
    PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
    if (pd == null || pd.getReadMethod() == null) {
        throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
    }// www . j  a v  a  2s. c om
    final Method readMethod = pd.getReadMethod();
    try {
        if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) {
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    @Override
                    public Object run() {
                        readMethod.setAccessible(true);
                        return null;
                    }
                });
            } else {
                readMethod.setAccessible(true);
            }
        }

        Object value;
        if (System.getSecurityManager() != null) {
            try {
                value = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    @Override
                    public Object run() throws Exception {
                        return readMethod.invoke(object, (Object[]) null);
                    }
                }, acc);
            } catch (PrivilegedActionException pae) {
                throw pae.getException();
            }
        } else {
            value = readMethod.invoke(object, (Object[]) null);
        }

        if (tokens.keys != null) {
            if (value == null) {
                if (isAutoGrowNestedPaths()) {
                    value = setDefaultValue(tokens.actualName);
                } else {
                    throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
                            "Cannot access indexed value of property referenced in indexed " + "property path '"
                                    + propertyName + "': returned null");
                }
            }
            String indexedPropertyName = tokens.actualName;
            // apply indexes and map keys
            for (int i = 0; i < tokens.keys.length; i++) {
                String key = tokens.keys[i];
                if (value == null) {
                    throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
                            "Cannot access indexed value of property referenced in indexed " + "property path '"
                                    + propertyName + "': returned null");
                } else if (value.getClass().isArray()) {
                    int index = Integer.parseInt(key);
                    value = growArrayIfNecessary(value, index, indexedPropertyName);
                    value = Array.get(value, index);
                } else if (value instanceof List) {
                    int index = Integer.parseInt(key);
                    List<Object> list = (List<Object>) value;
                    growCollectionIfNecessary(list, index, indexedPropertyName, pd, i + 1);
                    value = list.get(index);
                } else if (value instanceof Set) {
                    // Apply index to Iterator in case of a Set.
                    Set<Object> set = (Set<Object>) value;
                    int index = Integer.parseInt(key);
                    if (index < 0 || index >= set.size()) {
                        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                                "Cannot get element with index " + index + " from Set of size " + set.size()
                                        + ", accessed using property path '" + propertyName + "'");
                    }
                    Iterator<Object> it = set.iterator();
                    for (int j = 0; it.hasNext(); j++) {
                        Object elem = it.next();
                        if (j == index) {
                            value = elem;
                            break;
                        }
                    }
                } else if (value instanceof Map) {
                    Map<Object, Object> map = (Map<Object, Object>) value;
                    Class<?> mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(pd.getReadMethod(),
                            i + 1);
                    // IMPORTANT: Do not pass full property name in here - property editors
                    // must not kick in for map keys but rather only for map values.
                    TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(mapKeyType);
                    Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType, typeDescriptor);
                    value = map.get(convertedMapKey);
                } else {
                    throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                            "Property referenced in indexed property path '" + propertyName
                                    + "' is neither an array nor a List nor a Set nor a Map; returned value was ["
                                    + value + "]");
                }
                indexedPropertyName += PROPERTY_KEY_PREFIX + key + PROPERTY_KEY_SUFFIX;
            }
        }
        return value;
    } catch (IndexOutOfBoundsException ex) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "Index of out of bounds in property path '" + propertyName + "'", ex);
    } catch (NumberFormatException ex) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "Invalid index in property path '" + propertyName + "'", ex);
    } catch (TypeMismatchException ex) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "Invalid index in property path '" + propertyName + "'", ex);
    } catch (InvocationTargetException ex) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "Getter for property '" + actualName + "' threw exception", ex);
    } catch (Exception ex) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "Illegal attempt to get property '" + actualName + "' threw exception", ex);
    }
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractSubscriptionController.java

@RequestMapping(value = { "/getResourceComponents" }, method = RequestMethod.GET)
@ResponseBody/*ww  w.j a  va 2s  .co  m*/
public List<ResourceComponent> getResourceComponents(@ModelAttribute("currentTenant") Tenant currentTenant,
        @RequestParam(value = "tenant", required = false) String tenantParam,
        @RequestParam(value = "serviceInstanceUuid", required = true) final String serviceInstanceUuid,
        @RequestParam(value = "resourceType", required = true) final String resourceType,
        @RequestParam(value = "componentType", required = true) final String componentType,
        @RequestParam(value = "contextString", required = true) final String contextString,
        @RequestParam(value = "viewCatalog", required = false, defaultValue = "false") Boolean viewCatalog,
        @RequestParam(value = "filters", required = false) final String filters, HttpServletRequest request)
        throws ConnectorManagementServiceException {
    List<ResourceComponent> resourceComponents = new ArrayList<ResourceComponent>();
    if (getCurrentUser() == null
            || (viewCatalog == true && getCurrentUser().getTenant().equals(tenantService.getSystemTenant()))) {
        resourceComponents = privilegeService.runAsPortal(new PrivilegedAction<List<ResourceComponent>>() {

            @Override
            public List<ResourceComponent> run() {
                return ((CloudConnector) connectorManagementService.getServiceInstance(serviceInstanceUuid))
                        .getMetadataRegistry().getResourceComponentValues(resourceType, componentType,
                                tenantService.getTenantHandle(tenantService.getSystemTenant().getUuid(),
                                        serviceInstanceUuid).getHandle(),
                                userService.getUserHandleByServiceInstanceUuid(
                                        tenantService.getSystemUser(Handle.PORTAL).getUuid(),
                                        serviceInstanceUuid).getHandle(),
                                createStringMap(contextString), createStringMap(filters));
            }
        });

    } else {

        User user = getCurrentUser();
        Tenant effectiveTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY);
        if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
            user = effectiveTenant.getOwner();
        }

        String userHandle = userService.getUserHandleByServiceInstanceUuid(user.getUuid(), serviceInstanceUuid)
                .getHandle();

        resourceComponents = ((CloudConnector) connectorManagementService
                .getServiceInstance(serviceInstanceUuid)).getMetadataRegistry().getResourceComponentValues(
                        resourceType, componentType,
                        tenantService.getTenantHandle(getTenant().getUuid(), serviceInstanceUuid).getHandle(),
                        userHandle, createStringMap(contextString), createStringMap(filters));
    }
    return resourceComponents;
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductBundlesController.java

/**
 * This method returns the Collection of Filter Component
 * //ww  w .  j  av a 2s.c  o m
 * @param serviceInstanceUUID
 * @param component
 * @return
 * @throws ConnectorManagementServiceException
 */
@RequestMapping(value = ("/get_filter_value"), method = RequestMethod.GET)
@ResponseBody
public Collection<FilterComponent> getServiceFilterValues(
        @RequestParam(value = "serviceInstance", required = true) final String serviceInstanceUUID,
        @RequestParam(value = "component", required = true) final String component)
        throws ConnectorManagementServiceException {
    logger.debug("### getServiceResourceComponentValues method starting...");

    return privilegeService.runAsPortal(new PrivilegedAction<Collection<FilterComponent>>() {

        @Override
        public Collection<FilterComponent> run() {
            return ((CloudConnector) connectorManagementService.getServiceInstance(serviceInstanceUUID))
                    .getMetadataRegistry().getFilterValues(
                            tenantService.getTenantHandle(tenantService.getSystemTenant().getUuid(),
                                    serviceInstanceUUID).getHandle(),
                            userService.getUserHandleByServiceInstanceUuid(
                                    tenantService.getSystemUser(Handle.PORTAL).getUuid(), serviceInstanceUUID)
                                    .getHandle(),
                            component);
        }
    });
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.ArtifactProcessor.java

/**
 * Get an annotation.  This is wrappered to avoid a Java2Security violation.
 * @param cls Class that contains annotation 
 * @param annotation Class of requested Annotation
 * @return annotation or null/*  www  . ja va  2s. c om*/
 */
private static Annotation getAnnotation(final AnnotatedElement element, final Class annotation) {
    Annotation anno = null;
    try {
        anno = (Annotation) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                return element.getAnnotation(annotation);
            }
        });
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Problem occurred.  Continuing.  The problem is " + t);
        }
    }
    return anno;
}

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

private static JAXBIntrospector internalCreateIntrospector(final JAXBContext context) {
    JAXBIntrospector i;//from ww w.  java2s  .  co m
    i = (JAXBIntrospector) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return context.createJAXBIntrospector();
        }
    });
    return i;
}

From source file:org.apache.axis2.deployment.util.Utils.java

public static DeploymentClassLoader createClassLoader(File serviceFile, boolean isChildFirstClassLoading)
        throws MalformedURLException {
    ClassLoader contextClassLoader = (ClassLoader) org.apache.axis2.java.security.AccessController
            .doPrivileged(new PrivilegedAction() {
                public Object run() {
                    return Thread.currentThread().getContextClassLoader();
                }/* w w  w. ja  v  a 2  s. c om*/
            });
    return createDeploymentClassLoader(new URL[] { serviceFile.toURL() }, contextClassLoader, new ArrayList(),
            isChildFirstClassLoading);
}