Rest example with authentication in WildFly
本示例演示 WildFly 中 Rest 服务安全认证相关的内容。
创建Security Domain
启动 WildFly,执行如下CLI命令:
/subsystem=security/security-domain=RestDomain:add(cache-type=default)
/subsystem=security/security-domain=RestDomain/authentication=classic:add(login-modules=[{"code"=>"RealmDirect", "flag"=>"required", "module-options"=>[("realm"=>"ManagementRealm"),("userProperties"=>"${jboss.server.config.dir}/mgmt-users.properties"),("rolesProperties"=>"${jboss.server.config.dir}/mgmt-groups.properties")]}])
生成 keystore
使用如下命令生成认证文件到configuration目录:
$ keytool -v -genkey -alias wildfly.ssl -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -keystore wildfly.ssl.keystore
$ keytool -list -v -keystore wildfly.ssl.keystore
创建 SSLRelm
启动 WildFly,执行如下CLI命令:
/core-service=management/security-realm=SSLRealm:add()
/core-service=management/security-realm=SSLRealm/server-identity=ssl:add(keystore-path=wildfly.ssl.keystore, keystore-relative-to=jboss.server.config.dir,keystore-password=redhat, alias=wildfly.ssl, key-password=redhat)
/subsystem=undertow/server=default-server/https-listener=https:add(socket-binding=https, security-realm=SSLRealm)
部署测试helloworld.war
- http://localhost:8080/helloworld/rest/json
- http://localhost:8080/helloworld/rest/xml
- https://localhost:8443/helloworld/rest/json
- https://localhost:8443/helloworld/rest/xml