2017-02-14 79 views
0

我使用grails 2.5.5版本的特定視圖,假設我進入網址爲www.localhost:8080/app-name那麼就應該打開MyHome.gsp,想,如果我給其他網址前:demo1.localhost.com:8080/app-name那麼它應該重定向到一些登錄頁面,如login.jsp。我怎樣才能做到這一點?我怎樣才能重定向到基於URL中的Grails

+1

我會強烈建議您創建一個基本的Grails應用程序,設置彈簧安全性並遵循如何啓動和運行的基本說明 - 彈簧安全默認爲這樣 - 如果您打開一個未授權的頁面,它會重定向到登錄頁面 – Vahid

+0

實際上我有一個應用程序, 'www.localhost:8080/app- name'和'demo1.localhost.com:8080/app-name'顯示的是相同的'MyHome.gsp',但現在無論何時點擊'demo1.localhost.com:8080/app-name',它都應該重定向到'login.gsp '登錄後它顯示相同的'MyHome.gsp' ..我發現像'localhost:8080/app-name/example'這樣的spring-security,但是我的url不同,它不在'app-name /'後面 – Sat

+0

因此你的問題的措辭完全不正確,那麼你的意思是:'春季安全保留URL登錄後'嘗試谷歌搜索http://stackoverflow.com/questions/6968210/grails-spring-security-redirect-after-login-success-failure – Vahid

回答

1

讓我打破它給你:

假設我有www.localhost:8080/app-name

想,如果我給其他網址前:demo1.localhost.com:8080/app-name

您的應用程序從這裏開始:

案例1:/app-name 案例2:/app-name

該網址的其餘部分實際上是DNS,並將綁定的tomcat特定或通配符網址配置爲給定的應用程序。

因此,總之,您需要篩選應用程序parse url中的整個網址並相應地重定向到您的應用程序。

然後你需要用grails截取每個url 2有SecurityFilters這就是我所知道的與apache-shiro一起工作的可能也適用於spring安全。

,並在其中你需要全面檢查這樣的事情

URL url = new URL(request.getRequestURL().toString()) 
       String subdomain=url.host 
       if (subdomain.contains('.')) { 
        subdomain= subdomain.split('.')[0] 
       } 
that then returns your `demo1` you then redirect it another url if it matches your specific rule. 

但正如我說,你是爲我所表達的地址是什麼,或者有人爲如何獲取到的應用程序有沒有在這裏談論膚淺的東西與實際的應用程序做。這就是爲什麼IT是大生意。大企業並不是因爲每個人都試圖將所有事情都縮小到一個盒子裏,而是因爲當情況喜歡這種情況時,需要做出更大的想法,也就是說我需要一個像F5這樣的負載均衡器,它將根據給定的URL分割流量併發送給要求授權的另一個應用程序容器。

在這種情況下,則subdomain= subdomain.split('.')[1]但這餘地錯誤,因爲用戶可以把在demo1.somedomain.com,如果能夠解決好它要麼通過subdomain= subdomain.split('.')[0]

拆我就這樣做,那麼

String subdomain=url.host 

        if (subdomain.contains('.')) { 
         def splitter= subdomain.split('.') 
         subdomain= splitter[0] 
         if (subdomain=='www' && splitter.size()>1) { 
           subdomain= splitter[1] 
         } 
        } 
+0

謝謝,它在本地工作很好,但是當涉及到生產方面時,實際的url就像'www.somedomain.com',我的客戶端url就像'www.demo1.somedomain.com'在這種情況下輸出'url.host'是'www.demo1.somedomain.com',這裏如果客戶端點擊'www.somedomain.com',我會重定向到'MyHome.gsp',否則'Login.gsp'。不能保證它最後應該是'.com',它可能是'.org'或'.co.in'等 – Sat

+0

檢查我的更新 – Vahid