2011-09-20 2 views
2

Hy. 내가하려고하는 것은 Spring 보안을 Jsf + Spring IOC + Hibernate 응용 프로그램과 통합하는 것이다. 로그인 페이지를 설정하고 다른 페이지를 필터링 할 수 있었다. 그렇게까지 좋았지 만, @Secured 또는 @PreAuthorize 주석을 managedBeans 내부의 메소드에 사용합니다 (Dao의 주석이 작동 함). 나는 아무 것도하지 않는다는 것을 깨달았습니다. 나는 포스 클래스 프록시가 필요하다는 것을 읽었다. Spring은 프록시 기반의 aop을 사용하고 관리되는 bean은 인터페이스를 구현하므로 클래스 프록시 대신 동적 프록시가 사용됩니다. 그래서 난 내 설정 파일에 이런 짓을 :스프링 보안 3.1 + JSF 2.0. ManagedBeans에서 주석을 달기에 문제가 있습니까?

<?xml version="1.0" encoding="UTF-8"?> 

<!-- - Sample namespace-based configuration - - $Id: applicationContext-security.xml 
3019 2008-05-01 17:51:48Z luke_t $ --> 

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

<global-method-security secured-annotations="enabled" jsr250-annotations="enabled"/> 

<http pattern="/css/**" security="none" /> 
<http pattern="/pages/login.xhtml" security="none" /> 

<http auto-config='false'> 
    <intercept-url pattern="/pages/customer/**" access='ROLE_SITE_ADMIN' /> 
    <intercept-url pattern="/pages/department/overhead*" access='ROLE_SITE_ADMIN' /> 
    <intercept-url pattern="/**" 
     access='ROLE_SITE_ADMIN,ROLE_PROJECT_MANAGER,ROLE_DEPARTMENT_MANAGER,ROLE_ACCOUNTING' /> 
    <form-login login-page="/pages/login.xhtml" 
     default-target-url='/pages/reports.xhtml' always-use-default-target='true' 
     authentication-failure-handler-ref="userLoginService" /> 
    <logout invalidate-session="true" logout-success-url="/pages/login.xhtml"/> 
</http> 

<authentication-manager> 
    <authentication-provider user-service-ref='userLoginService'> 
     <password-encoder hash="md5" /> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="userLoginService" class="com.evozon.demo.bean.SecureLoginService"> 
    <beans:property name="defaultFailureUrl" value="/pages/login.xhtml" /> 
    <beans:property name="userDao" ref="userDao" /> 
    <beans:property name="loginReportDao" ref="loginReportDao" /> 
</beans:bean> 
</beans:beans> 

누군가가 주석이 관리 빈 내에서 작동하지 않는 이유는 내 말, 방법에 대한 수 :

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"**  
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 

<aop:aspectj-autoproxy proxy-target-class="true"/> 
//the rest of the beans 
</beans> 

ApplicationContext에 보안 XML은 다음과 같습니다 문제를 해결 하시겠습니까? 예 :

@PreAuthorize("ROLE_PROJECT_MANAGER") 
public void aproveVacation(Vacation vacation) {...} 

들으 문제는 solved.The 해결되었습니다

답변

0

콩을 봄 할 수있는 관리 빈을 변환하는 것입니다.

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
</listener> 

응용 프로그램 컨텍스트 처음에 작동이 설정이 필요합니다 :
의 web.xml은 JSF 리스너에만 sprin 사람이 필요하지 않는 방법은 다음과 같습니다이다

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 


<context:component-scan base-package="com.company.demo.bean" /> 
<context:annotation-config /> 
<aop:config proxy-target-class="true" /> 
//other configs 
</beans>  

참고가 처음 두 Spring Bean (Components의 경우)에 대한 기본 패키지를 정의하고 Bean에 주석을 달아야합니다. 세 번째 구성은 클래스 프록시를 강제하는 데 필요합니다 (here is why you need that).

@ManagedBean 
@SessionScoped 
public class UserLoginBean { 

@ManagedProperty(name = "userDao", value = "#{userDao}") 
private UserDao userDao; 
} 

에 : 당신은 이미이 설정을 가지고 있고 작동하지 않습니다 all.If있어

@Component 
@Scope("session") 
@Qualifier("userLoginBean") 
public class UserLoginBean { 

@Autowired 
private UserDao userDao; 
}  


하나씩 하나씩 우리는 우리가 구성 요소를 봄에 JSF managedBeans에서 주석을 변경하는 것이 알고 applicationContext.xml에 <aop:config proxy-target-class="true" />을 설정해야합니다.