我一直在爲需要AOP知識的配置而苦苦掙扎。Spring AOP和apache shiro的配置。註釋未被掃描
我必須承認,AOP是我試圖得到一段時間沒有成功的那部分。 似乎我的shiro註釋不被掃描,因此被忽略。
我試過使用shiro 1.1.0+ maven3 + spring 3.0.5.RELEASE,hibernate 3.6.1.Final與ZK 5.0.6。 我有我的hibernaterealm工作,與數據庫交談,我得到了認證工作,我成功(我相信)獲得角色和權限加載。
所以測試授權方我在我的代碼,這個地方:
Subject currentUser = SecurityUtils.getSubject();
if (!currentUser.isPermitted("businessaccount:list")) {
throw new AuthorizationException("User not authorized");
}
,它工作正常。
所以我知道我的權限被loaded.i'll方便我使用註釋我已經把它放在實現類,因爲我沒有計劃在第一個地方使用接口與我的控制器類擴展ZK GenericForwardController 。
我已經看到了這個bug,我決定嘗試一個接口與方法@RequiresPersmissions。
顯然它仍然沒有工作在它給訪問未經授權的subject.there是我log.Maybe沒有錯誤我做錯了這裏的代碼片段:
@Component("layouteventhandler")
public class LayoutEventHandlerImpl extends GenericForwardComposer implements LayoutEventHandler {
Logger logger = Logger.getLogger(LayoutEventHandlerImpl.class);
Menuitem logout;
//...
@Override
public void onClick$pAccounts() {
try {
execution.sendRedirect("/accounts/personal/list");
} catch (Exception ex) {
logger.info("Error redirecting to personal accounts", ex);
}
}
@Override
public void onClick$bAccounts() {
try {
execution.sendRedirect("/accounts/business/list");
} catch (Exception ex) {
logger.info("Error redirecting to business accounts", ex);
}
}
//.....
}
它的接口它:
public interface LayoutEventHandler {
@RequiresPermissions(value="personalaccount:list")
public void onClick$pAccounts();
@RequiresPermissions(value="businessaccount:list")
public void onClick$bAccounts();
//.....
}
這裏是我的四郎的ApplicationContext
<bean id="hibernateRealm" class="com.personal.project.admin.webapp.security.DatabaseRealm" />
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="hibernateRealm" />
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<!-- <property name="proxyTargetClass" value="true" />-->
</bean>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<!-- Secure Spring remoting: Ensure any Spring Remoting method invocations can be associated
with a Subject for security checks. -->
<bean id="secureRemoteInvocationExecutor" class="org.apache.shiro.spring.remoting.SecureRemoteInvocationExecutor">
<property name="securityManager" ref="securityManager"/>
</bean>
<!-- ... -->
是否有我應該做的事情?感謝您的閱讀和幫助
你能提供更多的信息嗎?你的Shiro註釋如何被忽略?他們在你的課程中是否爲空,你將它們連接到? – Caps
你好,我已經添加了更多的細節,如您requested.thanks –
這仍然感興趣?使用中是否還有其他AOP方面(例如交易處理)? – rudolfson