Search in sources :

Example 21 with BeansException

use of org.springframework.beans.BeansException in project spring-security by spring-projects.

the class AuthenticationTag method doEndTag.

public int doEndTag() throws JspException {
    Object result = null;
    // determine the value by...
    if (property != null) {
        if ((SecurityContextHolder.getContext() == null) || !(SecurityContextHolder.getContext() instanceof SecurityContext) || (SecurityContextHolder.getContext().getAuthentication() == null)) {
            return Tag.EVAL_PAGE;
        }
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth.getPrincipal() == null) {
            return Tag.EVAL_PAGE;
        }
        try {
            BeanWrapperImpl wrapper = new BeanWrapperImpl(auth);
            result = wrapper.getPropertyValue(property);
        } catch (BeansException e) {
            throw new JspException(e);
        }
    }
    if (var != null) {
        /*
			 * Store the result, letting an IllegalArgumentException propagate back if the
			 * scope is invalid (e.g., if an attempt is made to store something in the
			 * session without any HttpSession existing).
			 */
        if (result != null) {
            pageContext.setAttribute(var, result, scope);
        } else {
            if (scopeSpecified) {
                pageContext.removeAttribute(var, scope);
            } else {
                pageContext.removeAttribute(var);
            }
        }
    } else {
        if (htmlEscape) {
            writeMessage(TextEscapeUtils.escapeEntities(String.valueOf(result)));
        } else {
            writeMessage(String.valueOf(result));
        }
    }
    return EVAL_PAGE;
}
Also used : JspException(javax.servlet.jsp.JspException) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) BeansException(org.springframework.beans.BeansException)

Example 22 with BeansException

use of org.springframework.beans.BeansException in project spring-security by spring-projects.

the class ProtectPointcutPostProcessor method postProcessBeforeInitialization.

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    if (processedBeans.contains(beanName)) {
        // We already have the metadata for this bean
        return bean;
    }
    synchronized (processedBeans) {
        // check again synchronized this time
        if (processedBeans.contains(beanName)) {
            return bean;
        }
        // Obtain methods for the present bean
        Method[] methods;
        try {
            methods = bean.getClass().getMethods();
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage());
        }
        // expressions
        for (Method method : methods) {
            for (PointcutExpression expression : pointCutExpressions) {
                // Try for the bean class directly
                if (attemptMatch(bean.getClass(), method, expression, beanName)) {
                    // the "while" loop, not the "for" loop
                    break;
                }
            }
        }
        processedBeans.add(beanName);
    }
    return bean;
}
Also used : PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Method(java.lang.reflect.Method) BeansException(org.springframework.beans.BeansException)

Example 23 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class EventBuilder method setField.

/**
     * <p>setField</p>
     *
     * @param name a {@link java.lang.String} object.
     * @param val a {@link java.lang.String} object.
     */
public void setField(final String name, final String val) {
    if (name.equals("eventparms")) {
        String[] parts = val.split(";");
        for (String part : parts) {
            String[] pair = part.split("=");
            addParam(pair[0], pair[1].replaceFirst("[(]\\w+,\\w+[)]", ""));
        }
    } else {
        final BeanWrapper w = PropertyAccessorFactory.forBeanPropertyAccess(m_event);
        try {
            w.setPropertyValue(name, val);
        } catch (final BeansException e) {
            LOG.warn("Could not set field on event: {}", name, e);
        }
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeansException(org.springframework.beans.BeansException)

Example 24 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class ReportDefinitionBuilder method buildReportDefinitions.

/**
     * Builds and schedules all reports enabled in the statsd-configuration.
     * This method has the capability to throw a ton of exceptions, just generically throwing <code>Exception</code>
     *
     * @return a <code>Collection</code> of enabled reports from the statsd-configuration.
     * @throws java.lang.Exception if any.
     */
public Collection<ReportDefinition> buildReportDefinitions() throws Exception {
    Set<ReportDefinition> reportDefinitions = new HashSet<ReportDefinition>();
    for (StatsdPackage pkg : m_statsdConfigDao.getPackages()) {
        for (PackageReport packageReport : pkg.getReports()) {
            Report report = packageReport.getReport();
            if (!packageReport.isEnabled()) {
                LOG.debug("skipping report '{}' in package '{}' because the report is not enabled", report.getName(), pkg.getName());
                continue;
            }
            Class<? extends AttributeStatisticVisitorWithResults> clazz;
            try {
                clazz = createClassForReport(report);
            } catch (ClassNotFoundException e) {
                throw new DataAccessResourceFailureException("Could not find class '" + report.getClassName() + "'; nested exception: " + e, e);
            }
            Assert.isAssignable(AttributeStatisticVisitorWithResults.class, clazz, "the class specified by class-name in the '" + report.getName() + "' report does not implement the interface " + AttributeStatisticVisitorWithResults.class.getName() + "; ");
            ReportDefinition reportDef = new ReportDefinition();
            reportDef.setReport(packageReport);
            reportDef.setReportClass(clazz);
            BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(reportDef);
            try {
                bw.setPropertyValues(packageReport.getAggregateParameters());
            } catch (BeansException e) {
                LOG.error("Could not set properties on report definition: {}", e.getMessage(), e);
            }
            reportDef.afterPropertiesSet();
            reportDefinitions.add(reportDef);
        }
    }
    return reportDefinitions;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PackageReport(org.opennms.netmgt.config.statsd.model.PackageReport) Report(org.opennms.netmgt.config.statsd.model.Report) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) AttributeStatisticVisitorWithResults(org.opennms.netmgt.model.AttributeStatisticVisitorWithResults) PackageReport(org.opennms.netmgt.config.statsd.model.PackageReport) StatsdPackage(org.opennms.netmgt.config.statsd.model.StatsdPackage) HashSet(java.util.HashSet) BeansException(org.springframework.beans.BeansException)

Example 25 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapter method doAddNode.

/**
	 * <p>doAdd</p>
	 *
	 * @param nodeId a int.
	 * @param retry a boolean.
	 * @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
	 */
@Override
public void doAddNode(final int nodeId) throws ProvisioningAdapterException {
    LOG.debug("doAdd: adding nodeid: {}", nodeId);
    final OnmsNode node = m_nodeDao.get(nodeId);
    Assert.notNull(node, "doAdd: failed to return node for given nodeId:" + nodeId);
    InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {

        @Override
        public InetAddress doInTransaction(TransactionStatus arg0) {
            return getIpForNode(node);
        }
    });
    SnmpAgentConfig agentConfig = null;
    String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
    agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
    final OnmsAssetRecord asset = node.getAssetRecord();
    m_config.getReadLock().lock();
    try {
        for (final AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
            try {
                final String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
                LOG.debug("doAdd: Setting asset field \" {} \" to value: {}", field.getName(), value);
                // Use Spring bean-accessor classes to set the field value
                final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
                try {
                    wrapper.setPropertyValue(field.getName(), value);
                } catch (final BeansException e) {
                    LOG.warn("doAdd: Could not set property \" {} \" on asset object {}", field.getName(), e.getMessage(), e);
                }
            } catch (final Throwable t) {
                // This exception is thrown if the SNMP operation fails or an incorrect number of
                // parameters is returned by the agent or because of a misconfiguration.
                LOG.warn("doAdd: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
            }
        }
    } finally {
        m_config.getReadLock().unlock();
    }
    node.setAssetRecord(asset);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) AssetField(org.opennms.netmgt.config.snmpAsset.adapter.AssetField) TransactionStatus(org.springframework.transaction.TransactionStatus) InetAddress(java.net.InetAddress) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)64 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 BeanWrapper (org.springframework.beans.BeanWrapper)11 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)9 BeanCreationException (org.springframework.beans.factory.BeanCreationException)8 MalformedURLException (java.net.MalformedURLException)7 ArrayList (java.util.ArrayList)7 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 ApplicationContext (org.springframework.context.ApplicationContext)7 Map (java.util.Map)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5 IOException (java.io.IOException)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)4 UrlResource (org.springframework.core.io.UrlResource)4 File (java.io.File)3 HashMap (java.util.HashMap)3