- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试从这里实现 Facebook OAuth:
http://alvarosanchez.github.io/grails-spring-security-rest/latest/docs/index.html#_delegating_authentication_to_oauth_providers
我能够集成 OAuth 并从 Facebook 获取访问 token ,但我在实现自定义 OAuthUserDetailsService 时遇到了问题。我创建了
定制服务:
FacebookOauthUserDetails.groovy
class FacebookOauthUserDetailsService implements OauthUserDetailsService{
@Delegate
UserDetailsService userDetailsService
UserDetailsChecker preAuthenticationChecks
@Override
OauthUser loadUserByUserProfile(CommonProfile userProfile, Collection<GrantedAuthority> defaultRoles) throws UsernameNotFoundException {
UserDetails userDetails
OauthUser oauthUser
println("adss")
try {
println("Trying to fetch user details for user profile: ${userProfile}")
userDetails = userDetailsService.loadUserByUsername(userProfile.id)
log.debug("Checking user details with ${preAuthenticationChecks.class.name}")
preAuthenticationChecks?.check(userDetails)
Collection<GrantedAuthority> allRoles = userDetails.authorities + defaultRoles
oauthUser = new OauthUser(userDetails.username, userDetails.password, allRoles, userProfile)
} catch (UsernameNotFoundException unfe) {
println("User not found. Creating a new one with default roles: ${defaultRoles}")
oauthUser = new OauthUser(userProfile.id, 'N/A', defaultRoles, userProfile)
}
return oauthUser
}
}
import hungr.FacebookOauthUserDetailsService
import hungr.UserPasswordEncoderListener
beans =
{
userPasswordEncoderListener(UserPasswordEncoderListener)
oauthUserDetailsService(FacebookOauthUserDetailsService)
}
最佳答案
GrailsUserDetailsService
是接口(interface)基本驻留在org.springframework.security.core.userdetails
包裹。您可以实现 loadUserByUsername
在您的服务(类)中使用上述服务(接口(interface))的方法并编写代码(实现)以获取所需的数据/用户详细信息,您可以将用户详细信息作为对象/列表/映射获取任何您想要的格式,您可以在那里找到数据通过给定用户名的 GORM finder 方法并返回该数据。
下面是示例,
服务代码:
class Your_service_name implements GrailsUserDetailsService {
Map loadUserByUsername(String username) throws UsernameNotFoundException {
Map userDetails = [:]
User.withTransaction { status ->
User user = User.findByUsername(username, ["readOnly": true])
if (!user) throw new UsernameNotFoundException('User not found', username)
// you can also return the whole user object here instead of map keep method return type as UserDetails and return user object, you also return the user roles along with other details in Map.
userDetails["username"] = user.username
userDetails["emailAddress"] = user.emailAddress
userDetails["userFullName"] = user.userFullName
return userDetails
}
}
class YourController{
Your_service_name myService // injected above created service which contains the loadUserByUsername method implementation
def getUserDetails(){
Map userdetails = myService.loadUserByUsername("username_to_find")
println userdetails
}
}
beans = {
userDetailsService(Your_service_name)
}
Note : Clean and restart your application after this change.
关于grails - 在 grails spring security rest 中获取 'Cannot invoke method loadUserByUsername() on null object',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47969903/
我有以下代码: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub SetStat
在调用 Invoke-RestMethod 时使用 Powershell,例如: Invoke-RestMethod -Method Get -Uri "https://google.com/api/
我正在尝试将 Winform 应用程序转换为控制台应用程序。 Winform 应用程序有一个委托(delegate)处理程序。如何在 console 应用程序中编写相同的功能? this.Invoke
在 WPF 中,Dispatcher.Invoke 和直接在控件实例上调用的 Invoke 有什么区别。据我了解,调度程序负责处理线程的消息,Control.Invoke 是否会继续调用 Dispat
我正在研究性能监控系统,它可以将其例程注入(inject)现有程序集。为此,我试图了解 dalvik 代码的工作原理。 下面是我要完成的工作的示例。输入类可能如下所示: class MyClass{
我正在使用 powershell 命令来执行脚本和 cmdlet。因此,在执行 cmdlet 时,我使用了 powershell.invoke,而在执行脚本时,我使用了 pipeline.invoke
有人能解释一下 Invoke-Expression $test 之间的区别吗?和 Invoke-Expression -Command $test ? 变量测试是: $test = "notepad
我有四个类,即 MapperOne、ReducerOne、MapperTwo、ReducerTwo。我想要其中的一个链。 MapperOne-->ReducerOne-->输出文件生成,输入到Mapp
我正在阅读 Java ForkJoin 框架。不直接在 ForkJoinTask 的实现上调用 invoke()(例如 RecursiveTask),而是实例化 ForkJoinPool 有什么额外的
我在调用 Invoke-SqlCmd 时遇到问题,因为它包含第二个 Invoke-SqlCmd 调用: function Get-Foo { $query=` @" WITH data AS (
有人知道如何解决这个问题吗?我创建了一个客户端来使用网络服务。客户端代码为: package cliente; import java.util.List; import handler.Header
我希望使用 P/Invoke 来允许我的 C# 程序集与 native C 库互操作;这需要是跨平台的(即 Mono),因此不能使用混合模式程序集。我想知道使用不安全的 P/invoke 调用并在不安
一般来说,我对使用 Invoke-RestMethod/Invoke-WebRequest 比较陌生 - 我认为这是以下问题的重要背景。 我正在调用如下电话: $Headers = @{ "A
在 Jenkins 的一个自由风格项目(不是说 Maven2/3 项目)中,我有两个可能的构建步骤: 调用 Maven 3 调用顶级 Maven 目标 在不同的安装中,我有不同的组合(有些两者都有,有
这是完整的错误: e: C:\Users\HP\AndroidStudioProjects\MoneyManager\app\src\main\java\com\cruxrepublic\moneym
我正在编写 jQuery 插件并将它们与 AJAX 集成。我正在减少脂肪并专注于基础知识: (function($) { function MyPlugin(el, options) {
有人可以建议我如何处理这条消息吗? CA1060 Move P/Invokes to NativeMethods class Because it is a P/Invoke method, 'UCo
在java中我们可以“用类名调用一个静态方法”也可以“用一个对象调用一个静态方法”java中“用类名调用静态方法”和“用对象调用静态方法”有什么区别? 最佳答案 没有区别,但建议以静态方式调用 sta
尝试从对话框中的 EditText 获取 Edit Text 的值,但一次又一次地出现此错误 Attempt to invoke virtual method 'android.text.Editab
我正在开发一款扑翼应用程序。在出现此错误之前,读取和写入FireStore数据库没有任何问题,但随后突然出现错误(如下所示),并阻止我读取或写入数据库。我一直在寻找答案,但不幸的是,我找不到任何可以解
我是一名优秀的程序员,十分优秀!