PicketLink:' ERROR:编码的无效字节序列" UTF8":0x00'设置密码时

时间:2016-08-04 16:12:25

标签: postgresql jpa picketlink

我有一个Java EE应用程序,配置为使用PicketLink作为其安全框架。该应用程序在JBoss EAP 7(或Wildfly 10)上运行,并使用PostgreSQL 9.4作为其后端数据存储区。我正在初始化PicketLink IDM框架以使用PBKDF2密码编码,如下所示:

builder.named("MyApp").stores().jpa()
        .setCredentialHandlerProperty(PasswordCredentialHandler.PASSWORD_ENCODER,
                new PBKDF2PasswordEncoder("salty".getBytes(), 10000, 128))
        .addContextInitializer(new PicketLinkContextInitializer(this.entityManager));

但是,使用此配置时,我在尝试设置密码时会定期收到以下异常:

Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000201: Credential update failed for account [net.odyssi.identity.security.model.ExtendedUser@ac8b3d20] and type [org.picketlink.idm.credential.Password@17321a51].
    at org.picketlink.idm.internal.ContextualIdentityManager.updateCredential(ContextualIdentityManager.java:235) [picketlink-idm-impl-2.7.0.Final.jar:]
    at org.picketlink.idm.internal.ContextualIdentityManager.updateCredential(ContextualIdentityManager.java:217) [picketlink-idm-impl-2.7.0.Final.jar:]
    at net.odyssi.identity.services.security.CredentialManager.changeAccountPassword(CredentialManager.java:75) [IdentityPlatform-ejb-0.1-SNAPSHOT.jar:]
    ... 175 more
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute statement
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) [hibernate-entitymanager-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) [hibernate-entitymanager-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608) [hibernate-entitymanager-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1303) [hibernate-entitymanager-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.jboss.as.jpa.container.AbstractEntityManager.flush(AbstractEntityManager.java:459) [wildfly-jpa-7.0.0.GA-redhat-2.jar:7.0.0.GA-redhat-2]
    at org.picketlink.idm.jpa.internal.JPAIdentityStore.storeCredential(JPAIdentityStore.java:912) [picketlink-idm-impl-2.7.0.Final.jar:]
    at org.picketlink.idm.credential.handler.AbstractCredentialHandler.update(AbstractCredentialHandler.java:225) [picketlink-idm-api-2.7.0.Final.jar:]
    at org.picketlink.idm.credential.handler.AbstractCredentialHandler.update(AbstractCredentialHandler.java:51) [picketlink-idm-api-2.7.0.Final.jar:]
    at org.picketlink.idm.internal.AbstractIdentityStore.updateCredential(AbstractIdentityStore.java:145) [picketlink-idm-impl-2.7.0.Final.jar:]
    at org.picketlink.idm.internal.ContextualIdentityManager.updateCredential(ContextualIdentityManager.java:231) [picketlink-idm-impl-2.7.0.Final.jar:]
    ... 177 more
Caused by: org.hibernate.exception.DataException: could not execute statement
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:118) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2886) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3386) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1300) [hibernate-entitymanager-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    ... 183 more
Caused by: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:365)
    at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:537)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204) [hibernate-core-5.0.9.Final-redhat-1.jar:5.0.9.Final-redhat-1]
    ... 193 more

我会定期说,因为每次都不会出现错误。我可以毫无问题地设置少量密码(< 5)。但是,如果我尝试批量创建用户帐户,则每次都会发生错误。不管我创造了多少账户,我也偶尔会看到它。

知道为什么会出现这种错误或我如何纠正错误?

1 个答案:

答案 0 :(得分:0)

您正试图在表列中使用字符串数据类型存储零字节,这在PostgreSQL中是不允许的。

使用PostgreSQL数据类型bytea代替可用于存储任意二进制数据的数据类型。