2016-07-07 2 views
0

春と春のセキュリティを最新のバージョンにアップグレードして、基本機能をテストします。セキュリティー4.(私はjmd8に移行しています。これは、asmの競合により古いバージョンはもう使用できません)。どのような設定の変更私は春の新しいバージョンをサポートするために作成する必要があります:ここ春/春のセキュリティバージョンのアップグレード後に認証されていないオーセンティケータ

は私のweb.xmlです:ここ

<!--?xml version="1.0" encoding="UTF-8"?--> 
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" 
    version="3.0"> 

    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     <init-param> 
      <param-name>excludePatterns</param-name> 
      <param-value>/resources/*</param-value> 
     </init-param> 
    </filter> 

    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

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

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/springapp-servlet.xml 
      /WEB-INF/springapp-security.xml 
     </param-value> 
    </context-param> 

    <display-name>template</display-name> 

    <servlet> 
     <servlet-name>springapp</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>springapp</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>login.jsp</welcome-file> 
    </welcome-file-list> 

    <session-config> 
      <session-timeout>90000</session-timeout> 
    </session-config> 

    <error-page> 
      <error-code>404</error-code> 
      <location>/login.jsp</location> 
    </error-page>   

</web-app> 

は春のxmlです:ここ

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

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:security="http//www.springframework.org/schema/security" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.3.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.1.xsd"> 
    <context:component-scan base-package="com.spring" /> 
    <mvc:resources mapping="/resources/**" location="/resources/"/> 
    <mvc:annotation-driven/> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> 
     <property name="prefix" value="/WEB-INF/jsp/"></property> 
     <property name="suffix" value=".jsp"></property> 
    </bean> 
    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages"></property> 
     <property name="defaultEncoding" value="UTF-8"></property> 
    </bean> 
</beans> 

は春のセキュリティですXML:

<?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-4.3.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.1.xsd"> 
    <beans:bean id="SpringAuthenticationProvider" class="com.spring.SpringAuthenticationProvider"></beans:bean> 
    <authentication-manager alias="authenticationManager"> 
     <authentication-provider ref="SpringAuthenticationProvider"></authentication-provider> 
    </authentication-manager> 
    <!-- ############################################# --> 
    <http auto-config="true" use-expressions="true"> 
     <form-login login-page="/login" 
         default-target-url="/main" 
         username-parameter="j_username" 
         password-parameter="j_password" 
         authentication-failure-url="/login?auth=fail"/>  
     <intercept-url pattern="/admin/**" access="hasAnyRole('admin')"></intercept-url>                         
     <!-- <intercept-url pattern="/resources/**" access="permitAll"></intercept-url> --> 
     <intercept-url pattern="/login" access="permitAll"></intercept-url> 
     <intercept-url pattern="/logout" access="permitAll"></intercept-url> 
     <intercept-url pattern="/**" access="permitAll"/> 
     <intercept-url pattern="/main" access="permitAll"></intercept-url> 
     <intercept-url pattern="/" access="permitAll"></intercept-url> 
     <logout logout-url="/logout" logout-success-url="/login"></logout> 
     <access-denied-handler error-page="/403"/> 
    </http> 
</beans:beans> 

ここでは私のオーセンティケータである:

package com.spring; 

import java.util.ArrayList; 
import java.util.LinkedList; 
import java.util.List; 
import java.util.Locale; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.security.authentication.AuthenticationProvider; 
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 
import org.springframework.security.core.Authentication; 
import org.springframework.security.core.AuthenticationException; 
import org.springframework.security.core.GrantedAuthority; 
import org.springframework.security.core.authority.SimpleGrantedAuthority; 

public class SpringAuthenticationProvider implements AuthenticationProvider 
{ 
    private static final Logger LOG = LoggerFactory.getLogger(SpringAuthenticationProvider.class); 

    @Override 
    public boolean supports(Class<? extends Object> authentication) 
    { 
     return true; 
    } 

    /* 
    @Override 
    public boolean supports(Class<? extends Object> authentication) { 
     return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); 
    } 
    */ 

    @Override 
    public Authentication authenticate(Authentication authentication) throws AuthenticationException 
    { 
     String username = authentication.getName(); 
     String password = authentication.getCredentials().toString(); 
     List<GrantedAuthority> grants = new ArrayList<GrantedAuthority>(); 
     grants.add(new SimpleGrantedAuthority("admin")); 
     return new UsernamePasswordAuthenticationToken(username , "" , grants); 
    } 
} 

答えて

0

解決方法は、ログインページを/ loginに、以前のj_username/j_passwordをユーザー名/パスワードに変更することでした。

関連する問題