Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何在SpringMVC中重定向到子域_Spring Mvc - Fatal编程技术网

Spring mvc 如何在SpringMVC中重定向到子域

Spring mvc 如何在SpringMVC中重定向到子域,spring-mvc,Spring Mvc,默认情况下,所有已登录的用户都将被定向到 http://example.com/landing 如何将用户重定向到基于其公司名称的URL,例如 http://mcd.example.com/landing 或 http://kfc.example.com/landing 这些子域仍然指向与example.com指向的IP相同的IP 身份验证后如何将用户重定向到其子域 我启用了log4j,并注意到我的身份验证令牌在重定向后不会保留 更新日志 DEBUG: org.springframewo

默认情况下,所有已登录的用户都将被定向到

http://example.com/landing
如何将用户重定向到基于其公司名称的URL,例如

http://mcd.example.com/landing 

http://kfc.example.com/landing
这些
子域
仍然指向与
example.com
指向的IP相同的IP

身份验证后如何将用户重定向到其子域

我启用了
log4j
,并注意到我的身份验证令牌在重定向后不会保留

更新日志

DEBUG: org.springframework.security.web.DefaultRedirectStrategy - Redirecting to '/chaffic/redirectPage'
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - SecurityContext stored to HttpSession: 'org.springframework.security.core.context.SecurityContextImpl@629fb6b: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@629fb6b: Principal: com.myapp.auth.AuthenticationUserDetails@817f0539; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 127.0.0.1; SessionId: 42A6C4938AC026C3ACB8F9DB1148A19A; Granted Authorities: MEMBER'
DEBUG: org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/rest/game/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/rest/app/**'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 1 of 13 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/login'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/authentication'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/forgot'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/resources/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/site_**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/apk/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/admin/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Request '/redirectpage' matched by universal pattern '/**'
DEBUG: org.springframework.security.web.access.channel.ChannelProcessingFilter - Request: FilterInvocation: URL: /redirectPage; ConfigAttributes: [REQUIRES_SECURE_CHANNEL]
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 2 of 13 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@629fb6b: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@629fb6b: Principal: com.myapp.auth.AuthenticationUserDetails@817f0539; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 127.0.0.1; SessionId: 42A6C4938AC026C3ACB8F9DB1148A19A; Granted Authorities: MEMBER'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 3 of 13 in additional filter chain; firing Filter: 'ConcurrentSessionFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 4 of 13 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 5 of 13 in additional filter chain; firing Filter: 'LogoutFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 6 of 13 in additional filter chain; firing Filter: 'BrowserAuthenticationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 7 of 13 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 8 of 13 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 9 of 13 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
DEBUG: org.springframework.security.web.authentication.AnonymousAuthenticationFilter - SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@629fb6b: Principal: com.myapp.auth.AuthenticationUserDetails@817f0539; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 127.0.0.1; SessionId: 42A6C4938AC026C3ACB8F9DB1148A19A; Granted Authorities: MEMBER'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 10 of 13 in additional filter chain; firing Filter: 'SessionManagementFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 11 of 13 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 12 of 13 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/login'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/authentication'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/forgot'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/resources/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/site_**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/apk/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/redirectpage'; against '/admin/**'
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /redirectPage; Attributes: [hasAnyRole('MEMBER','ADMIN')]
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@629fb6b: Principal: com.myapp.auth.AuthenticationUserDetails@817f0539; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 127.0.0.1; SessionId: 42A6C4938AC026C3ACB8F9DB1148A19A; Granted Authorities: MEMBER
DEBUG: org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@6ec797e, returned: 1
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Authorization successful
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - RunAsManager did not change Authentication object
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage at position 13 of 13 in additional filter chain; firing Filter: 'SwitchUserFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /redirectPage reached end of additional filter chain; proceeding with original chain
DEBUG: org.springframework.web.servlet.i18n.CookieLocaleResolver - Parsed cookie value [en_US] into locale 'en_US'
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'mvc-dispatcher' processing GET request for [/chaffic/redirectPage]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /redirectPage
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public org.springframework.web.servlet.ModelAndView com.myapp.controller.LandingPageController.redirectPage(org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)]
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'landingPageController'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/chaffic/redirectPage] is: -1
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.RedirectView: name 'redirect:https://company.chaffic.com:8443/chaffic/landing'; URL [https://company.chaffic.com:8443/chaffic/landing]] in DispatcherServlet with name 'mvc-dispatcher'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.security.web.access.ExceptionTranslationFilter - Chain processed normally
DEBUG: org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/rest/game/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/rest/app/**'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 1 of 13 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/login'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/authentication'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/forgot'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/resources/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/site_**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/apk/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/admin/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Request '/landing' matched by universal pattern '/**'
DEBUG: org.springframework.security.web.access.channel.ChannelProcessingFilter - Request: FilterInvocation: URL: /landing; ConfigAttributes: [REQUIRES_SECURE_CHANNEL]
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 2 of 13 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - HttpSession returned null object for SPRING_SECURITY_CONTEXT
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@267a6199. A new one will be created.
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 3 of 13 in additional filter chain; firing Filter: 'ConcurrentSessionFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 4 of 13 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 5 of 13 in additional filter chain; firing Filter: 'LogoutFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 6 of 13 in additional filter chain; firing Filter: 'BrowserAuthenticationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 7 of 13 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - pathInfo: both null (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - queryString: both null (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - requestURI: arg1=/chaffic/landing; arg2=/chaffic/landing (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - serverPort: arg1=8443; arg2=8443 (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - requestURL: arg1=https://company.chaffic.com:8443/chaffic/landing; arg2=https://company.chaffic.com:8443/chaffic/landing (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - scheme: arg1=https; arg2=https (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - serverName: arg1=company.chaffic.com; arg2=company.chaffic.com (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - contextPath: arg1=/chaffic; arg2=/chaffic (property equals)
DEBUG: org.springframework.security.web.savedrequest.DefaultSavedRequest - servletPath: arg1=/landing; arg2=/landing (property equals)
DEBUG: org.springframework.security.web.savedrequest.HttpSessionRequestCache - Removing DefaultSavedRequest from session if present
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 8 of 13 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 9 of 13 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
DEBUG: org.springframework.security.web.authentication.AnonymousAuthenticationFilter - Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@6fa8dbd0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08: RemoteIpAddress: 127.0.0.1; SessionId: 9F9470A7CBD2D51E8F7DFB9EFB34F5A2; Granted Authorities: ROLE_ANONYMOUS'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 10 of 13 in additional filter chain; firing Filter: 'SessionManagementFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 11 of 13 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
DEBUG: org.springframework.security.web.FilterChainProxy - /landing at position 12 of 13 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/login'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/authentication'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/forgot'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/resources/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/site_**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/apk/**'
DEBUG: org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/landing'; against '/admin/**'
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /landing; Attributes: [hasAnyRole('MEMBER','ADMIN')]
DEBUG: org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@6fa8dbd0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08: RemoteIpAddress: 127.0.0.1; SessionId: 9F9470A7CBD2D51E8F7DFB9EFB34F5A2; Granted Authorities: ROLE_ANONYMOUS
DEBUG: org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@6ec797e, returned: -1
DEBUG: org.springframework.security.web.access.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
    at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83)

你可以用两种方法来做到这一点

请更改
RequestMethod。按您的意愿获取

@RequestMapping(value = "/comeHereToRedirec", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Location", "http://mcd.example.com/landing ");
}


@RequestMapping(value = "/comeHereToRedirec", method = RequestMethod.GET)
public ModelAndView method() {
        return new ModelAndView("redirect:" + "http://mcd.example.com/landing");

}

希望这有帮助。

我将被重定向到登录页面。知道为什么吗?@Abieez:你确定身份验证正确吗?如果身份验证失败,会发生什么情况?是的,如果键入错误的凭据,我将收到正确的无效凭据消息。现在,我键入了正确的凭据,但是,当我重定向到子域时,我的身份验证令牌似乎丢失了。@Abieez:是的,当会话id在cookie中时,确实会发生这种情况。以下是如何克服这一问题: