私は最近、同様に類似何かに取り組んできました...再び
を、このいずれかを試してみてください。あなたと同じ "欲望"を持っていました。ここで私は結局何をしたのですか?
異なるログイン画面を指すように、私はセキュリティフィルタチェーンのAuthenticationEntryPointステップ(春のセキュリティ)を上書きしました。私はspring-mobileプラグインが使用するのと同じロジックを使用しました。 (実際には、これを動作させるためにspring-mobileプラグインがインストールされている必要があります)deviceResolverはそのプラグインによって配線されています。私はまた、モバイルランディングページにモバイルユーザーを強制的に私のAuthenticationSuccessHandlerステップを書かれているConfig.groovy
grails.plugins.springsecurity.auth.loginFormUrl = '/register'
grails.plugins.springsecurity.auth.mobileLoginFormUrl = '/mobile/login'
でとても
resources.groovy
authenticationEntryPoint(com.myapp.security.MyAppAuthenticationEntryPoint) {
loginFormUrl = conf.auth.loginFormUrl
forceHttps = conf.auth.forceHttps
ajaxLoginFormUrl = conf.auth.ajaxLoginFormUrl
useForward = conf.auth.useForward
portMapper = ref('portMapper')
portResolver = ref('portResolver')
deviceResolver = ref('deviceResolver')
mobileLoginFormUrl = conf.auth.mobileLoginFormUrl
}
のconfigラインのような
package com.myapp.security
import org.codehaus.groovy.grails.plugins.springsecurity.AjaxAwareAuthenticationEntryPoint
import javax.servlet.http.HttpServletRequestimport javax.servlet.http.HttpServletResponse
import org.springframework.security.core.AuthenticationException
class MyAppAuthenticationEntryPoint extends AjaxAwareAuthenticationEntryPoint {
def mobileLoginFormUrl
def deviceResolver
@Override
protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) {
if (deviceResolver.resolveDevice(request).isMobile())
{
return mobileLoginFormUrl
}
return super.determineUrlToUseForThisRequest(request, response, e)
}
}
有線ログイン後
package com.myapp.security
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.codehaus.groovy.grails.plugins.springsecurity.AjaxAwareAuthenticationSuccessHandler
import org.springframework.security.web.savedrequest.RequestCache
class MyAppAuthenticationSuccessHandler extends AjaxAwareAuthenticationSuccessHandler {
def mobileTargetUrl
def deviceResolver
RequestCache requestCache
@Override
protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) {
if (isMobile(request))
{
return mobileTargetUrl
}
return super.determineTargetUrl(request, response)
}
@Override
void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.Authentication authentication) {
if (isMobile(request))
{
// we always want to go to the mobile landing page here.
requestCache.removeRequest(request, response);
}
super.onAuthenticationSuccess(request, response, authentication)
}
private boolean isMobile(request) {
deviceResolver.resolveDevice(request).isMobile()
}
@Override
void setRequestCache(RequestCache requestCache) {
super.setRequestCache(requestCache)
this.requestCache = requestCache
}
}
これはユーザーがモバイル以外のページを閲覧するのを止めるわけではありませんが、ログイン後に強制的に/ mobile/indexに移動します。そこに私のモバイルページ上のすべてのリンクは、他のモバイルページを参照してください。
丁寧な例をありがとう。私は再び問題に遭遇するときにそれを試してみる。今回私は長い道のりをとり、プロジェクトを1つのプラグイン(主にドメインクラスを含む)と2つのgrailsプロジェクト(1つはモバイル用、もう1つは他のデバイス用)に分割しました。これは午後に行われましたが、現在は標準設定に移行することができます。 – johanneslink