简体   繁体   English

使用Acegi安全性以脚本级别登录Grails应用

[英]Script level login to Grails app using Acegi security

Scenario: I have a Grails app that uses Acegi security for authentication. 场景:我有一个Grails应用程序,该应用程序使用Acegi安全性进行身份验证。 I'm implementing a REST service endpoint in the app and want to be able to GET and POST to / from the service endpoint using a shell script. 我正在应用程序中实现REST服务端点,并希望能够使用Shell脚本从服务端点GET和POST到POST。

I've been trying to use curl to do this, but can't find the right combination of parameters to make the curl command log in to the Grails app; 我一直在尝试使用curl来执行此操作,但是找不到正确的参数组合以使curl命令登录到Grails应用程序; I keep getting the login page back whenever I try a GET or POST. 每当尝试GET或POST时,我都会不断返回登录页面。

I know I could change the Grails app security settings to open up the specific service endpoint URLs so that they don't require authentication, but I'd rather not do this; 我知道我可以更改Grails应用程序的安全性设置来打开特定的服务端点URL,以便它们不需要身份验证,但是我不希望这样做。 anyone know how to make the authentication work with curl, or an alternative approach ? 有谁知道如何使身份验证与curl或其他方法兼容?

Your login URL would be '/j_spring_security_check' with the username field 'j_username' and the password field 'j_password'. 您的登录URL为“ / j_spring_security_check”,其中用户名字段为“ j_username”,密码字段为“ j_password”。 You will want to modify the index method of the Login controller to allow you to redirect to your target URL. 您将需要修改Login控制器的index方法,以允许您重定向到目标URL。 Something like: 就像是:

def index = {
  if (isLoggedIn() && params.redirectUri)
      redirect(uri: redirectUri, params: params)        
  }
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM