Spring+Spring Security 3.1.3 jak zacząć.

0

Witam

Próbuję w zasadzie zaimplementować Security Spring do szkieletu aplikacji wygenerowanego przez Netbeans 7.2.
Niestety nie chce to działać.

Pliki:

  • applicationContext.xml - wygenerowany przez Netbeans,

  • applicationContext-security.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<debug />
<http auto-config="true">
    <intercept-url pattern="/*" access="ROLE_USER" />
</http>
<authentication-manager alias="authenticationManager">
    <authentication-provider>
        <user-service>
            <user authorities="ROLE-USER" name="guest" password="guest"/>
        </user-service>
    </authentication-provider>
</authentication-manager>
</beans>
  • web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext-security.xml <!--Po usunięciu aplikacja uruchamia się, ale bez Spring Sec-->
            /WEB-INF/applicationContext.xml
</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    
    <!---->
    <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>
    <!---->
    
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
    </welcome-file-list>
</web-app>

błąd:

Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/applicationContext-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.. Please see server.log for more details.
C:\Documents and Settings\user\Moje dokumenty\NetBeansProjects\SpringSec4\nbproject\build-impl.xml:1027: The module has not been deployed.

Pozdrawiam

0

uzywasz elementu beans tak jakbys schema beans zdefiniowal jako domyslna, ale domyslna jest u ciebie security. zamiast beans dajesz beans:beans.

0

Witam

Dzięki za odpowiedź.

Po zmianie beans na beans:beans w pliku applicationContext-security.xml

SEVERE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.parsing.

BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

Offending resource: ServletContext resource [/WEB-INF/applicationContext-security.xml]

Czyli prawdopodobnie coś z : Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

Nagłówek przekleiłem z tutoriala z biblioteki Spring Sec. 3.1.3.

<?xml version="1.0" encoding="UTF-8"?>
<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">

Zmodyfikowałem nagłówek applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:security="http://www.springframework.org/schema/security" <!-- dodane -->
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"><!-- dodane -->

Pozdrawiam

0

Prawdopodobnie nie ma spring-security-3.1.3.jar w classpath, np. w WEB-INF/lib. Jestes pewien ze dobrze wszystko wyeksportowales? Jesli uzywasz mavena, to wszystkie zaleznosci zdefiniowane?

0

Witam

Działa ;-) Dziękuję za pomoc.

Błąd znajdował się w pliku applicationContext-security.xml.

<http auto-config="true">
    <intercept-url pattern="/*" access="ROLE_USER" />
</http>
<authentication-manager alias="authenticationManager">
    <authentication-provider>
        <user-service>
            <user authorities="ROLE_USER" name="a" password="a"/> <!--ROLE-USER-->
        </user-service>
    </authentication-provider>
</authentication-manager>

Obecnie aplikacja się uruchamia ;-) niestety nie uwierzytelnia.

Dodałem ponownie bibliotekę Spring Sec tyle, że rozpakowaną.


Dzięki za szybką odpowiedź.

Właśnie wyrzuciłem bibliotekę Spring Sec. 3.1.1 z Libraries i komunikat jest ten sam.

In-place deployment at C:\Documents and Settings\user\Moje dokumenty\NetBeansProjects\SpringSec4\build\web
deploy?DEFAULT=C:\Documents and Settings\user\Moje dokumenty\NetBeansProjects\SpringSec4\build\web&name=SpringSec4&contextroot=/SpringSec4&force=true failed on GlassFish Server 3.1.2 

 Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.

LifecycleException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

Offending resource: ServletContext resource [/WEB-INF/applicationContext-security.xml]

Jak dodałem bibliotekę?

Dodałem po prostu do projektu w formacie .zip ściągniętą z www tak jak np. hibernate, rozumiem, że nie jest to właściwy sposób?

Pozdrawiam

0

Witam

Działa ;-) Dziękuję za pomoc.

Pozdrawiam

1 użytkowników online, w tym zalogowanych: 0, gości: 1