2016-07-10 1 views
0

스프링 및 스프링 보안을 사용하여 웹 애플리케이션 ("원더"라고 함)을 개발했습니다. 내 개발 PC에서 웹 응용 프로그램을 실행하거나 웹 사이트를 호스팅하는 Tomcat 서버에 webapp를 배포하면 webapp이 제대로 작동하고 URL이 http : // localhost : 8080/http : // localhost : 8080/원터치/로그인 할 때 로그인하지 않았습니다. 예상대로 프로젝트 루트로 로그인하면 루트 http://localhost:8080/wander으로 리디렉션됩니다.사용자 정의 도메인이있는 Tomcat 서버에서 Spring Security를 ​​사용하여 webapp를 전개 할 때 리디렉션

그러나 내 vhosts 파일을 조정하여 사용자 정의 도메인을 사용하는 경우 www.customdomain.com/wander를 프로젝트 루트로 사용하거나 로그인하지 않은 경우 여기에 www가있는 URL에 "login"이 추가됩니다. .customdomain.com/wanderlogin이 URL로 나타나면 404 오류 누락이 발생합니다. www.customdomain.com/wander로 갈 때 왜이 오류가 발생합니까? 또는 로그인하지 않았을 때 www.customdomain.com/wander/login으로 이동하는 대신 "login"이 추가되는 이유는 무엇입니까? 이 오류가 내 웹 응용 프로그램 자체 또는 배포 서버에 있는지, 구성 방법은 확실하지 않습니다. 어떤 제안이라도 webapp 개발에 익숙하기 때문에 매우 도움이 될 것입니다. 내 Tomcat 및 Apache 로그를 확인했는데 아무런 관련이없는 것 같습니다.

디스패처 서블릿 :

<context:component-scan base-package="com.togetherwander.web.controllers"> 
</context:component-scan> 

<mvc:annotation-driven /> 
<bean class="org.springframework.context.support.ResourceBundleMessageSource" 
    id="messageSource"> 

    <property value="com.togetherwander.web.messages.messages" 
     name="basename" /> 
</bean> 

<bean id="tilesViewResolver" 
    class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"> 
</bean> 


<bean id="tilesConfigurer" 
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
    <property name="definitions"> 
     <list> 
      <value>/WEB-INF/layouts/default.xml</value> 
     </list> 
    </property> 
</bean> 

보안-conext.xml :

<security:authentication-manager> 
    <security:authentication-provider> 
     <security:jdbc-user-service 
      data-source-ref="dataSource" 
      authorities-by-username-query='select username, authority from users where binary username = ?' 
      users-by-username-query='select username, password, enabled from users where binary username = ?' 
      id="jdbcUserService" /> 
    </security:authentication-provider> 
</security:authentication-manager> 

<security:http use-expressions="true"> 
    <security:intercept-url pattern="/admin" 
     access="hasRole('ROLE_ADMIN')" /> 
    <security:intercept-url pattern="/" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/createevent" 
     access="permitAll" /> 
    <security:intercept-url pattern="/docreateevent" 
     access="permitAll" /> 
    <security:intercept-url pattern="/createwander" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/editevent" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/doeditevent" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/removetraveler" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/docreate" 
     access="isAuthenticated()" /> 
    <security:intercept-url pattern="/showwander" 
     access="permitAll" /> 
    <security:intercept-url pattern="/home" 
     access="permitAll" /> 
    <security:intercept-url pattern="/removewander" 
     access="permitAll" /> 
    <security:intercept-url pattern="/removeevent" 
     access="permitAll" /> 
    <security:intercept-url pattern="/loggedout" 
     access="permitAll" /> 
    <security:intercept-url pattern="/newaccount" 
     access="permitAll" /> 
    <security:intercept-url pattern="/createaccount" 
     access="permitAll" /> 
    <security:intercept-url pattern="/accountcreated" 
     access="permitAll" /> 
    <security:intercept-url pattern="/static/**" 
     access="permitAll" /> 
    <security:intercept-url pattern="/login" 
     access="permitAll" /> 
    <security:intercept-url pattern="/**" access="denyAll" /> 
    <security:form-login login-page="/login" 
     authentication-failure-url="/login?error=true" /> 
    <security:logout logout-success-url="/loggedout" /> 
    <security:access-denied-handler 
     error-page="/denied" /> 
    <security:remember-me key="offersAppKey" 
     user-service-ref="jdbcUserService" /> 
</security:http> 

<security:global-method-security 
    secured-annotations="enabled"></security:global-method-security> 

<bean id="passwordEncoder" 
    class="org.springframework.security.crypto.password.StandardPasswordEncoder"> 
</bean> 

인 LoginController :

package com.togetherwander.web.controllers; 

import javax.validation.Valid; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.dao.DuplicateKeyException; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.validation.BindingResult; 
import org.springframework.validation.annotation.Validated; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

import com.togetherwander.web.dao.FormValidationGroup; 
import com.togetherwander.web.dao.User; 
import com.togetherwander.web.service.UsersService; 

@Controller 
public class LoginController { 

    private UsersService usersService; 

    @RequestMapping("/loggedout") 
    public String showLoggedOut() { 
     return "login"; 
    } 

@Autowired 
public void setUsersService(UsersService usersService) { 
    this.usersService = usersService; 
} 

@RequestMapping("/login") 
public String showLogin() { 
    return "login"; 
} 

@RequestMapping("/newaccount") 
public String showNewAccount(Model model) { 

    model.addAttribute("user", new User()); 
    return "newaccount"; 
} 


@RequestMapping(value="/createaccount", method=RequestMethod.POST) 
public String createAccount(@Validated(FormValidationGroup.class) User user, BindingResult result) { 

    if(result.hasErrors()) { 
     return "newaccount"; 
    } 

    user.setAuthority("user"); 
    user.setEnabled(true); 



    if(usersService.exists(user.getUsername())){ 
     result.rejectValue("username", "DuplicateKey.user.username", "This username already exists!"); 
     return "newaccount"; 
    } 


    try { 
     usersService.create(user); 
    } catch (DuplicateKeyException e) { 
     result.rejectValue("username", "DuplicateKey.user.username"); 
     return "newaccount"; 
    } 

    return "home"; 
} 
} 

답변

0

좋습니다. 그렇기 때문에 항상 간단한 대답입니다. 내 로그인 컨트롤러가 다른 webapps와는 달리 login jsp로 리다이렉트되었을 때 루트 이후에 프록시 패스에 슬래시가 필요했다. "/ wander /"여전히 스프링 프로젝트가 왜 필요한지 모르겠습니다. 내 표준 JSP 및 서블릿 프로젝트는 아닙니다.

<VirtualHost *:80> 
ServerName example.com 
ProxyRequests On 
ProxyPass /wander/ http://localhost:8080/wander/ 
ProxyPassReverse /wander/ http://localhost:8080/wander/ 
<Location "/sample"> 
    Order allow,deny 
    Allow from all 
</Location> 

관련 문제