I am using grails 2.5.5 version, Suppose I am entering url as www.localhost:8080/app-name then it should open the MyHome.gsp, suppose if I give other url ex: demo1.localhost.com:8080/app-name then it should redirect to some login page like login.jsp. How can I do that?
- 3,520
- 9
- 39
- 66
-
1I would highly recommend you create a basic grails application set up spring security and follow basic instructions in how to get it up and running - spring security does this by default - if you hit a page not authorised it redirects to login page – V H Feb 14 '17 at 11:32
-
actually I have an app, both `www.localhost:8080/app-name` and `demo1.localhost.com:8080/app-name` are showing same `MyHome.gsp` but now whenever clicks om `demo1.localhost.com:8080/app-name` it should redirect to `login.gsp` after login it shows same `MyHome.gsp`.. I found spring-security for something like `localhost:8080/app-name/example` but my url contailns different, its not after `app-name/` – Sat Feb 14 '17 at 14:50
-
So your question is worded entirely incorrectly then what you mean is : `spring security preserve url after login` try googling that http://stackoverflow.com/questions/6968210/grails-spring-security-redirect-after-login-success-failure – V H Feb 14 '17 at 15:17
-
actually your not getting my question clearly, its not about login & authentications and its not about after `login`. Its based on the url, I should get different view pages, but my url is not like `app-name/exp1` or `app-name/exp2`. Its like `localhost:8080/app-name` or `demo1.localhost.com:8080/app-name` or `demo2.localhost.com:8080/app-name`. The url have changes before localhost not after app-name. – Sat Feb 14 '17 at 15:40
1 Answers
Let me break it up for you :
Suppose I have www.localhost:8080/app-name
suppose if I give other url ex: demo1.localhost.com:8080/app-name
Your app starts here:
Case 1 :/app-name
case 2 :/app-name
The rest of that url is actually DNS and configurating binding tomcat specific or wild card urls to a given application.
So in short you need to filter entire url in the application parse url and redirect in your app accordingly.
You need to then intercept every url with grails 2 there is SecurityFilters which so far as i know works with apache-shiro may also work with spring security.
and within it you need to overall check for something like
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.
But as I said you are talking about superficial stuff here as I expressed what the address is or how somone gets to the app has nothing to do with the actual application. This is why IT is big business. Big business not because everyone tries to narrow everything down into one box doing all of this but because when situations likes this happen bigger thinking is needed i.e. do i need a load balancer something like F5 that will split traffic according to a given url and send to another app container that asks for authorisation.
subdomain= subdomain.split('.')[1] in that case then but this leaves room for errors since user could put in demo1.somedomain.com and if that resolves well it is either split by subdomain= subdomain.split('.')[0]
I would do this then
String subdomain=url.host
if (subdomain.contains('.')) {
def splitter= subdomain.split('.')
subdomain= splitter[0]
if (subdomain=='www' && splitter.size()>1) {
subdomain= splitter[1]
}
}
- 8,382
- 2
- 28
- 48
-
thanks, Its working fine in local, but when in comes to production side, actual url is something like `www.somedomain.com` and my client url is like `www.demo1.somedomain.com` in this case the output of `url.host` is `www.demo1.somedomain.com`, Here if client hits `www.somedomain.com` I would redirect to `MyHome.gsp`, otherwise `Login.gsp`. There is no guarantee that it should be `.com` at last, it may be `.org` or `.co.in` etc – Sat Feb 15 '17 at 11:52