Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WildFly Swarm中的JAAS认证_Java_Authentication_Jakarta Ee_Jaas_Wildfly Swarm - Fatal编程技术网

Java WildFly Swarm中的JAAS认证

Java WildFly Swarm中的JAAS认证,java,authentication,jakarta-ee,jaas,wildfly-swarm,Java,Authentication,Jakarta Ee,Jaas,Wildfly Swarm,我正在开发一个小型网站,在后端使用angular前端和JAX-RS REST服务。 我想保护所有页面和REST服务,这样只有经过身份验证的用户才能访问页面和REST服务。我使用WildFly Swarm作为我的应用服务器,并希望将用户和角色存储在自定义(MySQL)数据库中。 我以前只使用过JSF和WebSphere application server,我使用过Windows Active Directory进行身份验证,所以我在这里迷路了,没有找到任何关于我应该做什么的相关教程或文章 以下是

我正在开发一个小型网站,在后端使用angular前端和JAX-RS REST服务。 我想保护所有页面和REST服务,这样只有经过身份验证的用户才能访问页面和REST服务。我使用WildFly Swarm作为我的应用服务器,并希望将用户和角色存储在自定义(MySQL)数据库中。 我以前只使用过JSF和WebSphere application server,我使用过Windows Active Directory进行身份验证,所以我在这里迷路了,没有找到任何关于我应该做什么的相关教程或文章

以下是我到目前为止所做的

web.xml:

<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>My Web App</display-name>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Admin Resource</web-resource-name>
        <url-pattern>/administration/*</url-pattern>
    </web-resource-collection>

    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>

    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>User Resource</web-resource-name>
        <url-pattern>/pages/*</url-pattern>
    </web-resource-collection>

    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>

    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>../login.html</form-login-page>
        <form-error-page>../login-failed.html</form-error-page>
    </form-login-config>
</login-config>

<security-role>
    <role-name>admin</role-name>
</security-role>

<security-role>
    <role-name>user</role-name>
</security-role>
</web-app>
我有两个问题:

  • 如何将数据库和表指定为用户和角色的源
  • 如何实现实际的登录过程?我已经创建了一个LoginServlet,在提交login.html页面时调用它,并尝试了下面的一行,但没有成功

        response.sendRedirect("j_security_check?j_username=" + username + "&j_password=" + password);
    
  • 任何帮助都将不胜感激

    看看这个

  • 它显示了如何为用户和角色指定数据库表查询
  • 定义表单登录配置
  •     response.sendRedirect("j_security_check?j_username=" + username + "&j_password=" + password);