my successHandler deafultTargetUrl is this
grails.plugin.springsecurity.successHandler.deafultTargetUrl = '/home'
home set with permitAll
'/home': ['permitAll']
but when i submit form then home page does not open.
i am try also this
grails.plugin.springsecurity.successHandler.alwaysUseDefault = true
grails.plugin.springsecurity.successHandler.deafultTargetUrl = '/home'
home controller code is
class HomeController {
def index() {
render(view:'welcome')
}
}
deafultTargetUrl should be defaultTargetUrl.
Related
I have a grails app where the content of urlMappings.groovy file is:
"/" {
controller="home"
view="home"
}
My home controller looks like
class HomeController {
List products = [
['price': 100, 'desc':'a'],
['price': 200, 'desc':'b']
]
def home() {
[products: products]
}
When I navigate to localhost:8080/myProject/home/home, I have access to "${products}", but when I navigate to localhost:8080/myProject, "${products}" statement is null.
Why is this and how can I make the localhost:8080/myProject act the same way as localhost:8080/myProject/home/home?
You should do
"/"(controller: 'home', action: 'home')
i am trying to Different home page for user depending upon its Role
grails.plugins.springsecurity.successHandler.defaultTargetUrl = "/home"
grails.plugins.springsecurity.securityConfigType="InterceptUrlMap"
grails.plugins.springsecurity.interceptUrlMap=[
....
....
'/User/**':['ROLE_USER'],
'/home/**':['ROLE_ADMIN','ROLE_USER'],
....
....
]
i set success handler controller "HomeController"
in that i redirect role wise home page
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
class HomeController {
def index() {
if (SpringSecurityUtils.ifAllGranted('ROLE_ADMIN')) {
redirect controller: '...', action: '...'
return
}
if (SpringSecurityUtils.ifAllGranted('ROLE_USER')) {
redirect controller: 'user', action: 'show'
return
}
}
}
In this When i logged in through ADMIN Profile it hits "HomeController" and redirect as well
But When I trying to Log In from User Profile it gives me an error springSecurity.denied.message...
The problem seems to be with your redirect call:
redirect controller: 'UserController'
it should be
redirect controller: 'user'
Because in this cases you follow the url convension: :8080/your-app/user/show
'/user/**':['ROLE_USER'],
instead
'/User/**':['ROLE_USER'],
I have a Grails application with Spring Security implemented (CAS). However, after I hit the logout button, I am not logged out. I have the LogoutController, with following code:
class LogoutController {
def index = {
println "IN LOGOUT CONTROLLER TRYING TO LOGOUT"
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout'
}
def accessDenied = {
}
}
And in my Config.groovy file, I have:
grails.plugins.springsecurity.logout.afterLogoutUrl = 'https://login.test.com/cas/logout'
The code for my GSP page is
<g:link controller='Logout'>Logout</g:link>
However, when I click the logout button I get redirected, but not fully logged out. Any ideas on what I am doing wrong?
Have you tried call session.invalidate() direct in the controller index method?
class LogoutController {
def index = {
println "IN LOGOUT CONTROLLER TRYING TO LOGOUT"
session.invalidate()
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl
}
}
Cheers
<g:link controller='Logout'>Logout</g:link>
def index = {
logoutProcessService.process(params)
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUr
}
I'm running Grails 1.3.6. I have this in my URLMappings.groovy file ...
static mappings = {
"/$folder?/$page?"{
controller = "Home"
action = "index"
}
"/"(view:"/index")
"500"(view:'/error')
}
and this is my HomeController ...
class HomeController {
def IOService
def index = {
def folder = params.folder;
def page = params.page;
def contents = IOService.getFileContents(folder, page)
response.setContentType("application/json")
response.text = contents
}
}
however, when I visit my URL "/context-path/folder1/page1", I'm getting an Apache Tomcat 404 error (complaining about "/context-path/folder1"). I'm new to Grails but can't figure this out. How can I adjust my mappings to make this work?
Thanks, - Dave
I'm not sure if controller/action definitions are case-insensitive. I've always used lowercase names. Try changing
controller = "Home"
to
controller = 'home'
I use Acegi with grails but I have a problem with a redirection.
I define in UrlMapping this :
"/" {
controller = "mycontroller"
action = "myaction"
}
In mycontroller :
myaction = {
if (authenticateService.isLoggedIn(){ "/mycontext/public" }
else {
// pseudo code
if (role = ROLE_1) {
redirect "/mycontext/myactionforNormalUser"
}
else if (role = ROLE_ADMIN) {
redirect "/mycontext/myactionforROLEADMIN"
}
}
}
IfI go to my app without login, I'm redirected to the public page, so it's right.
But on login on admin, I'm redirected to the auth/deniedAjax (of acegi) and not on my page.
And if I login as a normal user, I'm redirect on a ajax method define in my gsp.
Do you have an idea ?
Thanks a lot.
Upgraded and working fine now with spring security