开发者

Grails security plugin: Redirecting post and passing its data

开发者 https://www.devze.com 2023-02-04 19:52 出处:网络
On a gsp, I have a submit that goes to a controller action.In that action, I want to do some processing, then pass the post parameters from the gsp to another POST method.How can I do this?

On a gsp, I have a submit that goes to a controller action. In that action, I want to do some processing, then pass the post parameters from the gsp to another POST method. How can I do this?

Basically, are 开发者_开发百科POST parameters treated specially in the call to redirect? Because I'm trying to do the following. I have some custom gsp that I want to use to create a user account.

<form action='save' method='POST' id='createForm' class='cssform' autocomplete='off'>
<input type='text' class='text' name='j_username'/>
<input type='password' class='text' name='j_password'/>
<input type='submit' value='Create' />
</form>

I have a save action in my controller that I want to create the user on the db, then login.

def save = {
// creating user on DB
def config = SpringSecurityUtils.securityConfig
String postUrl = "${request.contextPath}${config.apf.filterProcesse sUrl}"
redirect(uri: postUrl, params: params)
}

The redirect to j_security_check causes a login failure. I'm suspecting that's due to the redirect.


You can use redirect:

redirect(action:'xyz', controller:'Abc', params:params)

or you can chain actions:

chain(action:'abc', controller:'Xyz',model:["myObject":new MyDomain(params)])

Grails - Controllers - Redirects


In class RequestHolderAuthenticationFilter add this "super.setPostOnly(false);"

public class RequestHolderAuthenticationFilter extends UsernamePasswordAuthenticationFilter {

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    SecurityRequestHolder.set((HttpServletRequest)request, (HttpServletResponse)response);
    try {
        super.setPostOnly(false);
        super.doFilter(request, response, chain);
0

精彩评论

暂无评论...
验证码 换一张
取 消