[
https://issues.apache.org/jira/browse/SHIRO-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13239413#comment-13239413
]
Matt Friedman commented on SHIRO-352:
-------------------------------------
Hi Bryan, Thanks for being so helpful. I've provided some more information
below. I can see that the result when the annotation is present is Proxy22
which wraps InfoProcessor. However, I'm not fluent enough with Spring to know
how I would get Spring to recognize the proxy as the object that I want
injected.
Processor is an interface, and InfoProcessor is an implementation.
Here is the application context:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
">
<!-- Apache Shiro security -->
<bean id="eppAuthenticationRealm"
class="info.afilias.epp.security.EppAuthenticatingRealmImpl"/>
<bean id="securityManager"
class="org.apache.shiro.mgt.DefaultSecurityManager">
<property name="realm" ref="eppAuthenticationRealm"/>
</bean>
<bean id="lifecycleBeanPostProcessor"
class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod"
value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
<property name="arguments" ref="securityManager"/>
</bean>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after
-->
<!-- the lifecycleBeanProcessor has run: -->
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor"/>
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<!-- Register Annotation-based Post Processing Beans-->
<context:annotation-config/>
<!-- Scan context package for any eligible annotation configured
beans.-->
<context:component-scan base-package="info.afilias"/>
<bean id="dataSource"
destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:epp-server"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>info.afilias.epp.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop
key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="info.afilias.epp.jaxb"/>
</bean>
<!--
The input stream contains a leading header which indicates the length of
the request, the header is 4 bytes long
-->
<bean id="EPP_LENGTH_HEADER_SIZE" class="java.lang.Integer">
<constructor-arg value="4"/>
</bean>
<!-- When receiving an input stream the max allowed length of the request
-->
<bean id="MAX_FRAME_SIZE_BYTES" class="java.lang.Integer">
<constructor-arg value="1024"/>
</bean>
<!--
The first 4 bytes of an epp request represent an integer value. This
value is equal to the total length
of the epp request (including the leading 4 byte header)
This is a ChannelUpstreamHandler
@see LengthFieldBasedFrameDecoder
-->
<bean id="lengthFieldBasedFrameDecoder"
class="org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder">
<constructor-arg ref="MAX_FRAME_SIZE_BYTES"/>
<!-- lengthFieldOffset -->
<constructor-arg value="0"/>
<!-- lengthFieldLength -->
<constructor-arg value="4"/>
<!-- lengthAdjustment -->
<constructor-arg value="-4"/>
<!-- initialBytesToStrip -->
<constructor-arg value="4"/>
<!-- frameDecoderFailFast - fails if the frame is too long -->
<constructor-arg value="true"/>
</bean>
<!--
When sending an epp xml string this encoder prepends the length of the
entire request to the
beginning of the byte array. The length of the length field is 4 bytes. If
the byte array length
being sent is 300, then the first four bytes would represent the integer
304.
@see LengthFieldPrepender
-->
<bean id="lengthFieldPrepender"
class="org.jboss.netty.handler.codec.frame.LengthFieldPrepender">
<!-- lengthOfLengthField -->
<constructor-arg value="4"/>
<!-- lengthIncludesFieldLength -->
<constructor-arg value="true"/>
</bean>
<bean id="eppHandler" class="info.afilias.epp.server.ControllerHandler"/>
</beans>
{code}
Test with No annotation present on InfoProcessor
Result:
processor = info.afilias.epp.processor.InfoProcessor@ecfeb11
{code:title=Test.java}
public void testGetInfoProcessor() throws Exception {
Command command = (Command) epp.getCommandType();
Class<? extends Processor> clazz = command.getProcessorType(); // clazz
= InfoProcessor.class
Processor processor = (Processor) applicationContext.getBean(clazz);
assertThat(processor, instanceOf(Processor.class));
}
{code}
Annotation present:
Result:
processor = {$Proxy22@4599}info.afilias.epp.processor.InfoProcessor@3415ddf5
{code:title=Test.java}
@Test
public void testGetInfoProcessor() throws Exception {
Command command = (Command) epp.getCommandType();
Processor processor = (Processor)
applicationContext.getBean("infoProcessor");
assertThat(processor, instanceOf(Processor.class));
}
{code}
> Shiro annotations with @Component and getBean(Type)
> ---------------------------------------------------
>
> Key: SHIRO-352
> URL: https://issues.apache.org/jira/browse/SHIRO-352
> Project: Shiro
> Issue Type: Bug
> Components: Integration: Spring
> Affects Versions: 1.2.0
> Environment: Linux, Spring, Java
> Reporter: Matt Friedman
>
> I have a bean where I'd like to annotate one of the methods with the
> @RequiresAuthentication annotation.
> When using the @RequiresAuthentication annotation and calling
> applicationContext.getBean(Class<?>) spring does not find my bean. Commenting
> out @RequiresAuthentication allows spring to find the bean.
> Using the string name of the bean instead of the type (i.e.
> applicationContext.getBean(String)) does work.
> // this causes spring to be unable to find the bean when using
> @RequiresAuthentication
> Class<? extends Processor> processorType = command.getProcessorType();
> Processor processor = applicationContext.getBean(processorType);
> // However this works:
> Processor processor = applicationContext.getBean(processorStringName);
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira