2016-12-19 16 views
-1

私のカスタムUsernamePasswordAuthenticationFilterを登録したいのですが、それを行うと、属性 'id'が表示されないというエラーが表示されます私はタグのどこかで間違いを犯したと知っていますが、このタグがどのように機能しているか分かりません。ここでは、バネのsecurity.xmlです:lineNumber:12; columnNumber:139; cvc-complex-type.2.4.a:要素 'beans:bean'で始まる無効なコンテンツが見つかりました

<beans:bean 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 
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-4.2.xsd"> 
<bean id="loginUrlAuthenticationEntryPoint" 
     class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 
    <property name="loginFormUrl" value="/login" /> 
</bean> 
<bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
    <property name="defaultTargetUrl" value="/login" /> 
</bean> 
<bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/login?error=true" /> 
</bean> 
<bean id="myAuthFilter" 
class="com.webproject.MyAuthFilter"> 
    <property name="authenticationManager" ref="authenticationManager" /> 
    <property name="authenticationFailureHandler" ref="failureHandler" /> 
    <property name="authenticationSuccessHandler" ref="successHandler" /> 
</bean> 

<http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint"> 
    <intercept-url pattern="/courses**" access="hasRole('ROLE_USER')" /> 
    <intercept-url pattern="/mycourses**" access="hasRole('ROLE_USER')" /> 
    <intercept-url pattern="/courses/**" access="hasRole('ROLE_USER')" /> 
    <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" /> 
    <csrf disabled="true" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource" 
             users-by-username-query= 
       "select username,passwort, enabled from users where username=?" 
             authorities-by-username-query= 
       "select username, user_role from user_roles where username =? " /> 
    </authentication-provider> 
</authentication-manager> 

+3

に変更してください。エラーメッセージがはっきりしているようです。無効な構成では、 '要素があります。多分あなたは ''を意味していたでしょうか?そうでない場合、なぜその要素にIDが必要であると思いますか? – Seelenvirtuose

答えて

1

EDIT:

あなたのデフォルトnamespaceは、セキュリティからそれほど離れてhttp://www.springframework.org/schema/securityですあなたが参照する必要がある他のすべての名前空間<beans:bean>

したがって、次の宣言は有効で正しいものです。

<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: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 
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-4.2.xsd"> 
<beans:bean id="loginUrlAuthenticationEntryPoint" 
     class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 
    <property name="loginFormUrl" value="/login" /> 
</beans:bean> 
<beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
    <property name="defaultTargetUrl" value="/login" /> 
</beans:bean> 
<beans:bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/login?error=true" /> 
</bean> 
<beans:bean id="myAuthFilter" 
class="com.webproject.MyAuthFilter"> 
    <property name="authenticationManager" ref="authenticationManager" /> 
    <property name="authenticationFailureHandler" ref="failureHandler" /> 
    <property name="authenticationSuccessHandler" ref="successHandler" /> 
</beans:bean> 

<http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint"> 
    <intercept-url pattern="/courses**" access="hasRole('ROLE_USER')" /> 
    <intercept-url pattern="/mycourses**" access="hasRole('ROLE_USER')" /> 
    <intercept-url pattern="/courses/**" access="hasRole('ROLE_USER')" /> 
    <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" /> 
    <csrf disabled="true" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource" 
             users-by-username-query= 
       "select username,passwort, enabled from users where username=?" 
             authorities-by-username-query= 
       "select username, user_role from user_roles where username =? " /> 
    </authentication-provider> 
</authentication-manager> 
+0

私はあなたが言ったようにしていますが、今では、要素 'beans:bean'の宣言を見つけることができないというエラーを示しています。また、私は問題のコードを更新しました。 – Papich

+0

@Papich私は自分の質問を更新しました。 config xmlを投稿して使用してください。グローバル定義は必須ですが、デフォルトの名前空間は常に最初の名前空間のみです。あなたの場合は春のセキュリティなので、春のセキュリティタグは ScanQR

0
<beans:beans id="loginUrlAuthenticationEntryPoint" ... 

- この1つはあったはず

<beans:bean id="loginUrlAuthenticationEntryPoint" ... 
0

ちょうど名前空間xmlns:beans="http://www.springframework.org/schema/beans"を見て、あなたは豆を指定するためのbeans名前空間を使用している、だからあなたの豆は

<beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> <property name="defaultTargetUrl" value="/login" /> </beans:bean>

ようにする必要があり、のようになります。

または

豆のネームスペースを からxmlns:beans="http://www.springframework.org/schema/beans"に変更してxmlns="http://www.springframework.org/schema/beans"

関連する問題