Hallo Community,
ich habe eine Testapplikation mit Spring 3 / JSF2 erstellt (funktioniert alles) und wollte diese mit Spring Security absichern. Ich habe mir das Tut von Spring Source angesehen und meinen Bedürfnissen angepasst. Allerdings ist da in dem Beispiel kein Zugriff auf Managed Beans gezeigt, was ich allerdings in meiner Testapp habe.
Sobald ich Spring Security aktiviere (web.xml) ist kein Zugriff auf die Managed Beans mehr möglich:
Muss ich die Beans irgendwie noch angeben, oder habe ich hier einen Denkfehler?
web.xml (Auszug)
[XML]
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[/XML]
applicationContext-security.xml:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Sample namespace-based configuration
-
-->
<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
Index of /schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<debug />
<!--<global-method-security pre-post-annotations="enabled" />-->
<http pattern="/static/**" security="none"/>
<http pattern="/loggedout.jsp" security="none"/>
<http use-expressions="true">
<intercept-url pattern="/kunden/**" access="hasRole('supervisor')"/>
<!--
Allow all other requests. In a real application you should
adopt a whitelisting approach where access is not allowed by default
-->
<intercept-url pattern="/**" access="permitAll" />
<form-login />
<logout logout-success-url="/loggedout.jsp" delete-cookies="JSESSIONID"/>
<remember-me />
<!--
Uncomment to enable X509 client authentication support
<x509 />
-->
<!-- Uncomment to limit the number of sessions a user can have
<session-management invalid-session-url="/test.html">
<concurrency-control max-sessions="2" error-if-maximum-exceeded="true" />
</session-management>
-->
</http>
<!--
Usernames/Passwords are
rod/koala
dianne/emu
scott/wombat
peter/opal
-->
<beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/>
<authentication-manager>
<authentication-provider>
<password-encoder ref="encoder"/>
<user-service>
<user name="rod" password="4efe081594ce25ee4efd9f7067f7f678a347bccf2de201f3adf2a3eb544850b465b4e51cdc3fcdde" authorities="supervisor, user, teller" />
<user name="dianne" password="957ea522524a41cbfb649a3e293d56268f840fd5b661b499b07858bc020d6d223f912e3ab303b00f" authorities="user,teller" />
<user name="scott" password="fb1f9e48058d30dc21c35ab4cf895e2a80f2f03fac549b51be637196dfb6b2b7276a89c65e38b7a1" authorities="user" />
<user name="peter" password="e175750688deee19d7179d444bfaf92129f4eea8b4503d83eb8f92a7dd9cda5fbae73638c913e420" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
[/XML]
root-context.xml:
[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
="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
Index of /schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<context:annotation-config />
<context:component-scan base-package="org.test"/>
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="10"/>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
</beans>
[/XML]
ich habe eine Testapplikation mit Spring 3 / JSF2 erstellt (funktioniert alles) und wollte diese mit Spring Security absichern. Ich habe mir das Tut von Spring Source angesehen und meinen Bedürfnissen angepasst. Allerdings ist da in dem Beispiel kein Zugriff auf Managed Beans gezeigt, was ich allerdings in meiner Testapp habe.
Sobald ich Spring Security aktiviere (web.xml) ist kein Zugriff auf die Managed Beans mehr möglich:
Code:
05.09.2012 21:12:19 com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SCHWERWIEGEND: Error Rendering View[/kunden/auftrag.xhtml]
javax.el.PropertyNotFoundException: /kunden/auftrag.xhtml @126,99 value="#{auftragBean.auftrag.nr}": Target Unreachable, identifier 'auftragBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:100)
at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:67)
...
Muss ich die Beans irgendwie noch angeben, oder habe ich hier einen Denkfehler?
web.xml (Auszug)
[XML]
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[/XML]
applicationContext-security.xml:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Sample namespace-based configuration
-
-->
<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
Index of /schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<debug />
<!--<global-method-security pre-post-annotations="enabled" />-->
<http pattern="/static/**" security="none"/>
<http pattern="/loggedout.jsp" security="none"/>
<http use-expressions="true">
<intercept-url pattern="/kunden/**" access="hasRole('supervisor')"/>
<!--
Allow all other requests. In a real application you should
adopt a whitelisting approach where access is not allowed by default
-->
<intercept-url pattern="/**" access="permitAll" />
<form-login />
<logout logout-success-url="/loggedout.jsp" delete-cookies="JSESSIONID"/>
<remember-me />
<!--
Uncomment to enable X509 client authentication support
<x509 />
-->
<!-- Uncomment to limit the number of sessions a user can have
<session-management invalid-session-url="/test.html">
<concurrency-control max-sessions="2" error-if-maximum-exceeded="true" />
</session-management>
-->
</http>
<!--
Usernames/Passwords are
rod/koala
dianne/emu
scott/wombat
peter/opal
-->
<beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/>
<authentication-manager>
<authentication-provider>
<password-encoder ref="encoder"/>
<user-service>
<user name="rod" password="4efe081594ce25ee4efd9f7067f7f678a347bccf2de201f3adf2a3eb544850b465b4e51cdc3fcdde" authorities="supervisor, user, teller" />
<user name="dianne" password="957ea522524a41cbfb649a3e293d56268f840fd5b661b499b07858bc020d6d223f912e3ab303b00f" authorities="user,teller" />
<user name="scott" password="fb1f9e48058d30dc21c35ab4cf895e2a80f2f03fac549b51be637196dfb6b2b7276a89c65e38b7a1" authorities="user" />
<user name="peter" password="e175750688deee19d7179d444bfaf92129f4eea8b4503d83eb8f92a7dd9cda5fbae73638c913e420" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
[/XML]
root-context.xml:
[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
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
Index of /schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<context:annotation-config />
<context:component-scan base-package="org.test"/>
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="10"/>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
</beans>
[/XML]
Java:
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
@Named("auftragBean")
@Scope("session")
public class AuftragBean implements Serializable {
private static final long serialVersionUID = 5451044444775095552L;
private static Logger log = Logger.getLogger(AuftragBean.class);
Auftrag auftrag;
@PostConstruct
public void init(){
log.info("INIT");
createEmptyAuftrag();
}
private void createEmptyAuftrag(){
auftrag = new Auftrag();
auftrag.setNr("A66488");
}
public Auftrag getAuftrag() {
return auftrag;
}
public void setAuftrag(Auftrag auftrag) {
this.auftrag = auftrag;
}
}