0

我有一个不寻常的问题——我需要让移动设备登录到 Grails 上的数据库系统。移动设备正在发送 XML 文件,它们用作设备和数据库应用程序之间的数据传输。我必须做的第一件事是根据发送的 XML 文件对数据库进行身份验证。当我将 Shiro 用作安全框架时,现在我必须从 XML 读取服务进行登录。有人可以帮我吗?

这是我尝试使其工作的方法。导入 shiro.ShiroRole 导入 shiro.ShiroUser

class LoginService {

 def shiroSecurityService

 def AuthController

 def params

 def confirmation() {

    def path = System.properties['base.dir']    

 def file = new File (path+"/web-app/xml/ConfirmationRequest.xml") 

 def records = new XmlSlurper().parse(file)

   if(records.user.username=='klemens'&&records.user.password=='kot12345')
    {
        params.username='klemens'
        params.password='kot12345'
        AuthController.signIn(params)
    }

  }
}

当然,它没有,它挂在这个错误上:

ERROR context.GrailsContextLoader  - Error executing bootstraps: Cannot get property 'params' on null object
Message: Cannot get property 'params' on null object
4

1 回答 1

0

好的,我认为您应该依赖 Shiro SecurityUtils 类并拒绝在您的服务上使用 AuthController,如下所示:

 def confirmation() {


    def path = System.properties['base.dir']    

    def file = new File (path+"/web-app/xml/ConfirmationRequest.xml") 

    def records = new XmlSlurper().parse(file)
    Subject currentUser = SecurityUtils.getSubject()
    UsernamePasswordToken token = new UsernamePasswordToken(records.user.username, records.user.password);
    currentUser.login(token);
    currentUser.isAuthenticated()
  }

  }

不要忘记阅读手册

于 2012-10-02T12:07:36.697 回答