Authentication Wildfly 8基本身份验证

Authentication Wildfly 8基本身份验证,authentication,jax-rs,resteasy,wildfly,Authentication,Jax Rs,Resteasy,Wildfly,我在Wildfly 8上运行了一个Java Web应用程序。我试图用resteasy注释保护我的restful Web服务。我使用命令行工具curl来测试restapi 基本的身份验证设置似乎可以工作。对带有注释“@PermitAll”的Web服务的Http请求工作正常。Curl说: ~ % curl -v http://localhost:8080/ItilityServer-web/rest/account > GET /ItilityServer-web/rest/account

我在Wildfly 8上运行了一个Java Web应用程序。我试图用resteasy注释保护我的restful Web服务。我使用命令行工具curl来测试restapi

基本的身份验证设置似乎可以工作。对带有注释“@PermitAll”的Web服务的Http请求工作正常。Curl说:

~ % curl -v http://localhost:8080/ItilityServer-web/rest/account 
> GET /ItilityServer-web/rest/account HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 200 OK
< Connection: keep-alive
< X-Powered-By: Undertow/1
< Server: WildFly/8
< Content-Length: 0
< Date: Wed, 28 Jan 2015 10:47:11 GMT
< 
* Connection #0 to host localhost left intact
但事实并非如此。解密的授权详细信息“aGFuczpoZWxtaWhlbG1paGVsbWk=”是hans:helmihelmihelmi,此用户名和密码存储在我的数据库中。与安全域使用相同的jpql查询会导致一个unsername“hans”和他的密码“helmihelmi”

这里是我的设置:

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

<context-param>
    <param-name>resteasy.role.based.security</param-name>
    <param-value>true</param-value>
</context-param>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Application</realm-name>
</login-config>

<security-role>
    <role-name>store</role-name>
</security-role>

</web-app>
和import.xml在启动时创建用户

insert into Account(id, name, email, password, user_role) values (0, 'hans', 'john.smith@mailinator.com', 'helmihelmihelmi', 'store') 
insert into Store(id, name, zipcode, street, housenumber, town, account_id) values(0, 'Edeka', 72622, 'stephanstraße', 10, 'Reudern', 0);

我不知道如何找到解决方案,因为我甚至不知道问题所在。希望有人能帮忙。

你不能将未加密的密码存储在数据库中。WildFly希望您使用
登录模块
配置中指定的哈希算法和编码来存储经过哈希处理的密码

创建新的
帐户时,请使用

org.jboss.security.auth.spi.Util.createPasswordHash()
获取要存储的哈希密码


通常,存储原始密码存在安全风险。

这就是解决方案!非常感谢。如今,存储未经处理或不安全的散列密码应被视为刑事过失。
@GET
@RolesAllowed(AuthRole.STORE)
@Produces(MediaType.APPLICATION_JSON)
public Response getAccountByName() {
    Response.ResponseBuilder builder = Response.ok();
    return builder.build();
}
insert into Account(id, name, email, password, user_role) values (0, 'hans', 'john.smith@mailinator.com', 'helmihelmihelmi', 'store') 
insert into Store(id, name, zipcode, street, housenumber, town, account_id) values(0, 'Edeka', 72622, 'stephanstraße', 10, 'Reudern', 0);
org.jboss.security.auth.spi.Util.createPasswordHash()