简体   繁体   English

使用Grails Spring Security插件登录的其他字段

[英]Additional field in login using Grails Spring Security plugin

My question is similar to this one 我的问题与此类似

How to pass an additional parameter with spring security login page 如何在Spring Security登录页面中传递附加参数

though it applies to Grails Spring Security plugin. 尽管适用于Grails Spring Security插件。 If I have to support an additional field in login (company name) , how do I do it in Grails? 如果我必须在登录名(公司名称)中支持其他字段,如何在Grails中做到这一点?

I will get the company name field from the URL. 我将从URL获得公司名称字段。

For example. 例如。 /login?companyname=c1 /login?companyname=c2 / login?companyname = c1 / login?companyname = c2

The same user name can be used by different users in different companies. 同一用户名可由不同公司的不同用户使用。 So user name is not unique but user name + company name is unique. 因此,用户名不是唯一的,但用户名+公司名称是唯一的。

Thanks in Advance. 提前致谢。

This is not nice solution but you can join username and company name into single username field. 这不是很好的解决方案,但是您可以将用户名和公司名称加入单个用户名字段。 For example oneUser_company1 , oneUser_company2 . 例如oneUser_company1oneUser_company2 In that case, you would have to create multiple accounts for single user. 在这种情况下,您将必须为单个用户创建多个帐户。

I think that this custom filter is a start point. 我认为此自定义过滤器是一个起点。

Probably you will need a custom AuthenticationToken to store your company name, instead of using UsernamePasswordAuthenticationToken . 您可能需要一个自定义AuthenticationToken来存储您的公司名称,而不是使用UsernamePasswordAuthenticationToken

You will need an AuthenticationProvider too, since you will need to get your user by username and company. 您还将需要AuthenticationProvider ,因为您将需要通过用户名和公司来获取用户。

The flow will be: 流程将是:

  • Filter will create your custom AuthenticationToken , storing the company field. Filter将创建您的自定义AuthenticationToken ,并存储公司字段。
  • Your custom AuthenticationProvider will get this token and try to load the user by username and company 您的自定义AuthenticationProvider将获得此令牌,并尝试按用户名和公司加载用户
  • Spring Security Core will check your password Spring Security Core将检查您的密码

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

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