首页 \ 问答 \ 如何注册Keycloak密码哈希服务提供商SPI(How to Register Keycloak Password Hash Service Provider SPI)

如何注册Keycloak密码哈希服务提供商SPI(How to Register Keycloak Password Hash Service Provider SPI)

背景

我需要将定制应用程序的用户数据库迁移到Keycloak。 我创建了一个成功导入用户的keycloak-add-user.json文件。 迁移的用户密码在原始系统中进行哈希处理,但是我实现了Keycloak Password Hash SPI服务类,该服务类使用现有算法来验证迁移用户的哈希值和salt值。 Hash SPI类从Keycloak SPI实现PasswordHashProviderFactoryPasswordHashProvider ,并基于`Pbkdf2PasswordHashProvider'。

public class MyPasswordHashProvider implements PasswordHashProviderFactory, PasswordHashProvider {
public static final String ID = "XXXX";

问题

当迁移的用户尝试使用keycloak进行身份验证时,org.keycloak.hash.PasswordHashManager会记录错误

Could not find hash provider XXXX for password

我的jar包含一个初始化文件META-INF/services/org.keycloak.models.PasswordHashProviderFactory ,其中一行包含HashProvider实现的完整类名。

my.folder.MyPasswordHashProvider

这是基于联邦SPI doco,但Keycloak Password Hash SPI的文档似乎不存在。 我错过了什么,或者我需要做些什么来注册和使用我的Hash Provider与Keycloak?


Background

I need to migrate a user database for a bespoke app into Keycloak. I have created a keycloak-add-user.json file that imports the users successfully. Migrated user passwords are hashed in the original system, however I've implemented a Keycloak Password Hash SPI service class that uses the existing algorithm to validate the hash and salt value of a migrated user. The Hash SPI class implements PasswordHashProviderFactory and PasswordHashProvider from the Keycloak SPI and is based on `Pbkdf2PasswordHashProvider'.

public class MyPasswordHashProvider implements PasswordHashProviderFactory, PasswordHashProvider {
public static final String ID = "XXXX";

The issue

When a migrated user tries to authenticate with keycloak an error is logged by org.keycloak.hash.PasswordHashManager

Could not find hash provider XXXX for password

My jar contains an initialisation file META-INF/services/org.keycloak.models.PasswordHashProviderFactory with a single line containing the full classname of the HashProvider implementation.

my.folder.MyPasswordHashProvider

This was based on the Federation SPI doco, but documentation for the Keycloak Password Hash SPI seems to be non-existent. What am I missing, or what do I need to do to register and use my Hash Provider with Keycloak?


原文:https://stackoverflow.com/questions/38693674
更新时间:2023-11-23 14:11

最满意答案

您可以利用sqlcmd的脚本变量 。 这些可以在脚本文件中使用,并用$()标记。 像这样,

-- Sql script file
use $(db);
select someting from somewhere;

调用sqlcmd ,使用-v参数分配变量。 像这样,

sqlcmd -S server\instance -E -v db ="MyDatabase" -i s.sql

编辑

设置变量时要注意Sql语法。 考虑下面的脚本:

DECLARE @dbName varchar(255)
SET @dbName = $(db)
select 'val' = @dbName

传递给Sql Server时,它看起来像这样(Profiler在这里帮助):

use master;

DECLARE @dbName varchar(255)
SET @dbName = foo
select 'val' = @dbName

这显然是无效的语法,因为SET @dbName = foo没有多大意义。 价值应该在单引号内,像这样,

sqlcmd -S server\instance -E -v db ="'foo'" -i s.sql

Just in case someone else needs to do this... here is a working example.

Power Shell Script:

sqlcmd -S uk-ldn-dt270 -U sa -P 1NetNasdf£! -v db = "'DatabaseNameHere'" -i $scriptFile -b | Tee-Object -filepath $sqlLog

Note the -v switch to assign the variables

And here is the MS SQL:

USE MASTER
GO

if db_id($(db)) is null

BEGIN
    EXEC('
    RESTORE DATABASE ' + $(db) + '
    FROM DISK = ''D:\DB Backup\EmptyLiveV5.bak''
    WITH MOVE ''LiveV5_Data'' TO ''C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\LiveV5_' + $(db) + '.MDF'',
    MOVE ''LiveV5_Log'' To ''C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\LiveV5_' + $(db) + '_log.LDF'', REPLACE,
    STATS =10')
END

Note: You do not have to assign the scripting varible to a normal sql varible like this.

SET @dbName = $(db)

you can just use it in your sql code. - Happy coding.

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)