2016-04-13 40 views
0

Merhaba Spring Security için yeni Ben basit bir Sppring Güvenlik Programı yapıyorum ama bahar güvenliği otomatik oluşturulan giriş sayfası almıyorum.
Bu Bu Bu benim memuru servlet.xmlYay güvenliği alınamadı otomatik oluşturulan giriş sayfası

olan Bu benim Bahar Güvenlik XML sınıfı

<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.0.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 
    <http auto-config="true"> 
     <intercept-url pattern="/admin" access="ROLE_ADMIN" /> 
    </http> 
    <authentication-manager> 

     <authentication-provider> 
     <user-service> 
     <user name="Hello" password="Pass" authorities="ROLE_USER" /> 
     </user-service> 
     </authentication-provider> 
    </authentication-manager> 
</beans:beans> 

benim 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" 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"> 


    <display-name>Archetype Created Web Application</display-name> 

    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 

    </welcome-file-list> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

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

    <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> 

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

</web-app> 

benim Kontrolör

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class HelloWorldController { 

    String message = "Welcome to Spring MVC!"; 

    @RequestMapping("/hello") 
    public ModelAndView showMessage(
      @RequestParam(value = "name", required = false, defaultValue = "World") String name) { 
     System.out.println("in controller"); 

     ModelAndView mv = new ModelAndView("helloworld"); 
     mv.addObject("message", message); 
     mv.addObject("name", name); 
     return mv; 
    } 

    @RequestMapping("/") 
    public ModelAndView showIndex() { 
     System.out.println("in index controller"); 

     ModelAndView mv = new ModelAndView("index"); 
     return mv; 
    } 

    @RequestMapping("/admin") 
    public ModelAndView showMessageAdmin() { 
     System.out.println("in controller"); 

     ModelAndView mv = new ModelAndView("helloworld"); 
     return mv; 
    } 
} 

olduğunu

<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" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-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.ge.web.Controller" /> 

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/WEB-INF/views/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 
</beans> 

for/admin Kimlik doğrulama için varsayılan olarak Spring Security'i almak istiyorum. Ama bunu anlamıyorum, doğrudan yanlış nerede bulabileceğimi görecek mi? peşin Teşekkür ....

cevap

0

İlk düzeltme size web.xml: Dosya memuru servlet için varsayılan konumu olan src/main/webapp/WEB-INF altında olduğundan bağlam param içindeki /WEB-INF/dispatcher-servlet.xml belirtmek gerekmez. senin pring Güvenlik XML Sonra

<?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" 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"> 

    <display-name>Archetype Created Web Application</display-name> 

    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
     <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

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

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

    <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> 

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

</web-app> 

: Burada varsayılan Girişi formunu elde etmek için gerekli olan <form-login /><logout /> kayıptı.

<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.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 

    <http> 
     <intercept-url pattern="/admin" access="ROLE_ADMIN" /> 
     <form-login /> 
     <logout /> 
    </http> 

    <authentication-manager> 
     <authentication-provider> 
     <user-service> 
     <user name="Admin" password="AdminPassword" authorities="ROLE_USER, ROLE_ADMIN" /> 
     </user-service> 
     </authentication-provider> 
    </authentication-manager> 

</beans:beans> 
+0

Doğrudan – priyanka

+0

ayarlarda yukarıda denediniz .... gelmiyor sayfası varsayılan giriş sayfası admin.jsp adına yönlendirme? Dosyaların üstüne kopyalayıp yapıştırın, çalışması gerekir. Eğer hala giriş sayfası alamıyorsanız, bu ... 'yi deneyin. –