能够从本地tomcat实例访问URL,但不能从生产服务器访问 - Spring Security

时间:2015-10-01 14:51:30

标签: java spring spring-mvc tomcat spring-security

当我尝试从生产服务器点击以下URL时,我在firefox控制台中获得404,当我从本地tomcat实例点击相同时它工作正常。

网址 - http://www.nattukottainagarathar.com/profile/pirivu/1 404未找到 - 无效

localhost:8080 / NattukottaiNagarathar / profile / pirivu / 1 - 工作

http://www.nattukottainagarathar.com/user/profile/pirivu/1 - 工作

我使用过弹簧安全装置。我已经配置了弹簧安全性,以便在访问带有/ user的URL时将用户引导到登录屏幕但在我的情况下'/ profile / pirivu / 1'不起作用但它正在使用/ user / profile / pirivu / 1。为什么它在本地tomcat实例中工作而不在prod实例中工作。它应该在没有/ user的情况下工作。

在我的.js文件中,控件直到

$.getJSON("profile/pirivu/"+selectedKovilValue,function(data)

之后我得到404 Not found exception

春季安全

<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.2.xsd">

<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/user/**" access="hasRole('ROLE_USER')" />

    <!-- access denied page -->
    <access-denied-handler error-page="/403" />
    <form-login 
        login-page="/login" 
        default-target-url="/welcome"
        authentication-failure-url="/login?error" 
        username-parameter="username"
        password-parameter="password" />
    <logout logout-success-url="/login?logout" />
    <!-- enable csrf protection -->
    <csrf />
</http>

<authentication-manager>
    <authentication-provider user-service-ref="userManager" >
        <password-encoder hash="bcrypt" />    
    </authentication-provider>
</authentication-manager>
</beans:beans>

register.js

$(document).ready(function() {
$("#kovil").change(function() {
    $('#pirivu').prop('disabled', false);

    var selectedKovilValue = $("#kovil").val();
    var pirivuType = $("#pirivu");
    if (selectedKovilValue == 0) {
        pirivuType.empty();
        pirivuType.append("<option value='0'>-- Please choose kovil from above -- </option>");
        pirivuType.val(0);
        pirivuType.prop('disabled', true);
    } else {
        $.getJSON("profile/pirivu/"+selectedKovilValue,function(data) {
            if(selectedKovilValue!=0)
            {
                pirivuType.empty();
                pirivuType.append("<option value='0'>-- Select --</option>");
                $.each(data,function(index,value) {
                    if(selectedKovilValue==value.kovilId){
                    pirivuType.append("<option value='" + value.pirivuId + "'>"+ value.pirivu+ "</option>");
                    }
                });
            }
        });
    }
});
});

控制器

@RequestMapping(value = "/profile/pirivu/{kovil}", method = RequestMethod.GET)
public @ResponseBody List<Pirivu> gePirivu(@PathVariable("kovil") String kovil) {
    List<Pirivu> pirivuObjs = serviceManager.getPirivu(kovil);
    return pirivuObjs;
}

的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">
<display-name>www.nattukottainagarathar.com</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-database.xml,
        /WEB-INF/spring-security.xml,
        /WEB-INF/applicationContext.xml
    </param-value>
</context-param>
<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>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/user/*</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>30</session-timeout>
</session-config>

<!-- 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>
</web-app>

0 个答案:

没有答案