- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我一直在关注 JBoss Picketlink 2.5.x documentation found here试图创建自定义 User
模型来对我的应用程序进行身份验证。我的应用程序是部署在 JBoss EAP 6.2 上的典型 JavaEE 6 应用程序。我已经能够成功创建自定义 User
模型类,并且能够毫无问题地保留用户。我看到我的自定义属性按预期反射(reflect)在数据库中。我的自定义 User
模型如下所示:
public class ExtendedUser extends User {
private static final long serialVersionUID = -9132382669181464122L;
@AttributeProperty
private String uniqueIdentifier = null;
...
}
...创建新用户帐户的代码如下所示:
ExtendedUser u = new ExtendedUser(username);
u.setFirstName(firstName);
u.setLastName(lastName);
u.setEmail(emailAddress);
u.setUniqueIdentifier(UUID.randomUUID().toString());
idm.add(u);
idm.updateCredential(u, new Password(password));
此外,我有一个用户帐户的自定义实体模型,如下所示:
@Entity(name = "UserAccount")
@Table(name = "tbl_user_account", uniqueConstraints = {
@UniqueConstraint(columnNames = { "email" }) })
@IdentityManaged({ ExtendedUser.class, Agent.class })
public class UserAccountBean extends BaseAccountIdentityBean implements
IdentifiedDomainEntity {
private static final long serialVersionUID = -537779599507513418L;
<snip... irrelevant fields...>
@Column(length = ValidationConstants.UUID_LEN, unique = true)
@Unique
@Length(max = ValidationConstants.UUID_LEN)
@Index(name = "idx_user_account_uniqueid")
@AttributeValue(name = "uniqueIdentifier")
// @NotEmpty
private String uniqueIdentifier = null;
...
我看到 uniqueIdentifier
属性按预期填充到数据库表中。但是,每当我尝试使用以这种方式创建的用户进行身份验证时,身份验证都会失败。每次。我还需要做些什么来使用我的自定义 User
对象吗?创建我的 Identity
或 IdentityManager
实例时是否必须在某处指定它?我的身份验证代码比较简单,如下所示:
@Inject
private DefaultLoginCredentials loginCredentials = null;
...
loginCredentials.setUserId(loginName);
loginCredentials.setPassword(password);
AuthenticationResult result = identity.login();
if (logger.isDebugEnabled()) {
logger.debug("authenticate(String, String, String) - AuthenticationResult result=" + result); //$NON-NLS-1$
}
正如我所提到的,这段代码每次都会失败。我已经对密码进行了完整性检查,我知道它们是正确的。我没有看到任何异常或错误写入日志,所以我不确定问题可能是什么。如果我使用 Picketlink 库提供的标准 User
对象,即使我对后端数据库使用相同的实体,代码也能正常工作。它仅在使用 ExtendedUser
时失败,所以我确信我遗漏了一些东西。有什么建议吗?
更新:Picketlink 2.6.0 似乎添加了更多的日志记录。我已经升级,但仍然失败,但现在我看到以下错误消息:
14:41:23,133 DEBUG [org.picketlink.idm.credential] (http-localhost/127.0.0.1:9080-3) Starting validation for credentials [class org.picketlink.idm.credential.UsernamePasswordCredentials][org.picketlink.idm.credential.UsernamePasswordCredentials@56370e07] using identity store [org.picketlink.idm.jpa.internal.JPAIdentityStore@22ef0c6c] and credential handler [org.picketlink.idm.credential.handler.PasswordCredentialHandler@387a19c9].
14:41:23,134 DEBUG [org.picketlink.idm.credential] (http-localhost/127.0.0.1:9080-3) PLIDM001003: Trying to find account [user6_4] using default account type [class org.picketlink.idm.model.basic.User] with property [loginName].
14:41:23,136 DEBUG [org.picketlink.idm.credential] (http-localhost/127.0.0.1:9080-3) PLIDM001003: Trying to find account [user6_4] using default account type [class org.picketlink.idm.model.basic.Agent] with property [loginName].
14:41:23,138 DEBUG [org.picketlink.idm.credential] (http-localhost/127.0.0.1:9080-3) Account NOT FOUND for credentials [class org.picketlink.idm.credential.UsernamePasswordCredentials][org.picketlink.idm.credential.UsernamePasswordCredentials@56370e07].
很明显,Picketlink 正在尝试使用标准的 User
对象进行身份验证,而不是我的自定义对象。也就是说,我如何告诉 Picketlink 使用我的自定义 ExtendedUser
对象进行身份验证?
最佳答案
我刚经历了和你一样的头痛。我也一直在尝试添加自己的用户帐户。我能够让它工作的唯一原因是您提到 PicketLink 正在尝试查找用户和代理类型的帐户!这意味着您必须实现自己的 PasswordCredentialHandler。不用担心!你可以只复制this class和 this class到你的项目。在 AbstractCredentialHandler 的“configureDefaultSupportedAccountTypes”方法中,您将看到以下内容:
if (!this.defaultAccountTypes.contains(User.class)) {
this.defaultAccountTypes.add(User.class);
}
if (!this.defaultAccountTypes.contains(Agent.class)) {
this.defaultAccountTypes.add(Agent.class);
}
只需像这样向其中添加您的自定义帐户类:
if (!this.defaultAccountTypes.contains(CustomUser.class)) {
this.defaultAccountTypes.add(CustomUser.class);
}
您要做的最后一件事是将 PasswordCredentialHandler 添加到 IDMConfigurtion:
private void initConfig() {
IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
builder
.named("default")
.stores()
.jpa()
.mappedEntity(
AccountTypeEntity.class,
RoleTypeEntity.class,
GroupTypeEntity.class,
IdentityTypeEntity.class,
RelationshipTypeEntity.class,
RelationshipIdentityTypeEntity.class,
PartitionTypeEntity.class,
PasswordCredentialTypeEntity.class,
AttributeTypeEntity.class,
CustomUserEntity.class
)
.supportGlobalRelationship(Relationship.class)
.addContextInitializer(this.contextInitializer)
.addCredentialHandler(PasswordCredentialHandler.class)
.supportAllFeatures();
identityConfig = builder.build();
希望对您有所帮助!
关于java - JBoss Picketlink - 自定义用户模型身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21267142/
我在使用以下代码时遇到问题: function http_file_exists($url){ $f=fopen($url,"r"); if($f){ fclose($f); retu
我已经通过 Git 部署到 Azure 几个月了,没有出现重大问题,但现在我似乎遇到了一个无法克服的错误。 我创建了一个新的 Azure 网站,为正在开发的项目创建单独的预览链接。我在新站点上设置了
我已经通过flutter创建了一个App并完成了它,我想在flutter文档中阅读时进行部署。 我收到此错误: FAILURE: Build failed with an exception. * W
我在Windows 10中使用一些简单的Powershell代码遇到了这个奇怪的问题,我认为这可能是我做错了,但我不是Powershell的天才。 我有这个: $ix = [System.Net.Dn
我正在尝试使用 RapidJSON 解析从服务器接收到的数据。以下是收到的确切字符串: [ { "Node": "9478149a08f9", "Address": "172.17
我尝试为 ios 编译 OpenCV。我总是收到这些错误。我用不同版本的opencv试了一下,结果都是一样的。 我运行这个:python 平台/ios/build_framework.py ios_o
我在一台机器上做基本的发布/订阅,我的客户端是 StackExchange-Redis 的 C# 客户端,我在同一台机器上运行基于 Windows 的 Redis 服务器(服务器版本 2.8.4) 当
我有这段代码,但无法执行,请帮我解决这个问题 连接 connect_error) { die ("connection failed: " . $terhubung->connect_erro
我在 tomcat 上运行并由 maven 编译的 Web 应用程序给出了以下警告和错误。我可以在本地存储库中看到所有 JAR,但有人可以帮忙吗。 WARNING: Failed to scan JA
我正在 Windows 8 上使用 Android Studio 开发一个 android 应用程序,我正在使用一些 native 代码。突然间我无法编译我的 C 文件。当我运行 ndk-build
下面的代码对类和结构的成员进行序列化和反序列化。序列化工作正常,但我在尝试使用 oarch >> BOOST_SERIALIZATION_NVP(outObj); 反序列化时遇到了以下错误; 代码中是
如果我运行此命令“rspec ./spec/requests/api/v1/password_reset_request_spec.rb”,此文件中的所有测试都会通过。 但是,当我运行“rspec”时
我在尝试执行测试以使用 Protractor 上传文件时出错,我的代码是这个 it('it should be possible to upload a file', function() {
System.loadLibrary("nativefaceswap"); 当我运行我的应用程序时,我在 Android Studio 中发现了此类错误。在logcat中显示: java.lang.U
我希望有人能帮助我!使用任何方法或命令行的任何 SSL/HTTPS 调用均无效。 我在 Windows 10 中使用 Ubuntu Server 18.04 作为子系统。我的问题是昨天才开始出现的,因
通过删除这两个值将日期字段从 null=True 和 Blank=True 更改为 required 时,使用 db.alter 命令时遇到问题。 当以下行被注释掉时,迁移运行不会出现问题。
我第一次使用 Heroku 尝试创建应用程序(使用 SendGrid 的 Inbound Parse Webhook"和 Twilio SMS 通过电子邮件发送和接收 SMS 消息)。通过 Virtu
我正在将我的 swift 项目更新到 Xcode 7 上的 Swift 2.0。xcode 在构建项目时报告了以下错误: 命令/Applications/Xcode.app/Contents/Deve
在我的代码中,SSL 库函数 SSL_library_init() 没有按预期返回 1。我如何才能看到它返回了什么错误? 我在 SSL_library_init() 之后调用了 SSL_load_er
我正在尝试运行在以下链接中找到的答案: Asynchronously Load the Contents of a Div 但是当我这样做时,我会遇到我不太理解的错误。 我的代码: $(documen
我是一名优秀的程序员,十分优秀!