如何配置Jboss7.1简单认证(How to configure simple authentic

2019-08-17 20:12发布

我的工作,而无需使用任何框架由纯JSP页面(小脚本)编写的项目。

JBoss的版本:jboss-as-7.1.0.Final

我现在想给它添加简单的验证。 因此,当用户尝试浏览器中的JSP页面,说, http://localhost/myContextPath/hello.jsp ,它需要首先登录。

web.xml中

<security-constraint>
    <web-resource-collection>
        <web-resource-name>All Access</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
</login-config>

的jboss-web.xml中

<jboss-web>
<security-domain>other</security-domain>
</jboss-web>

standalone.xml([JBOSS_HOME] \独立\配置文件夹)

<subsystem xmlns="urn:jboss:domain:security:1.1">
        <security-domains>
            <security-domain name="other" cache-type="default">
                <authentication>
                    <login-module code="UsersRoles" flag="required">
                        <module-option name="usersProperties" value="users.properties"/>
                        <module-option name="rolesProperties" value="roles.properties"/>
                    </login-module>
                </authentication>
            </security-domain>
            <security-domain name="form-auth">
                <authentication>
                    <login-module code="UsersRoles" flag="required">
                        <module-option name="usersProperties" value="users.properties"/>
                        <module-option name="rolesProperties" value="roles.properties"/>
                    </login-module>
                </authentication>
            </security-domain>
        </security-domains>
    </subsystem>

users.properties(web应用classes目录下,把)

user1=jboss7

roles.properties(web应用classes目录下,把)

user1=Admin

所有这些修改之后,我尝试浏览我打招呼的jsp。 我照常工作。 无身份验证,也没有例外。

我不知道我该怎么一个正确的方向,或安全约束是一个完全不同的事情。 请帮帮忙,谢谢!

Answer 1:

刚刚成立的基本身份验证此7.1以下步骤文章 。

试试这个。

组态

在web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>All Access</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>ApplicationRealm</realm-name>
</login-config>

<security-role>
    <role-name>user</role-name>
</security-role>

的jboss-web.xml中

<jboss-web>
    <security-domain>java:/jaas/other</security-domain>
</jboss-web>

standalone.xml

不需要,如果你正在使用ApplicationRealm做任何事情。

添加用户

您可以添加用户使用由JBoss提供的工具来ApplicationRealm。

%JBOSS_HOME%/箱中。 使用附加user.bat(或)add-user.sh工具。

C:\dev\jboss-eap-6.2\bin>add-user

What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a): b

Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : johngalt
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: user
About to add user 'johngalt' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Added user 'johngalt' to file 'C:\dev\jboss-eap-6.2\standalone\configuration\application-users.properties'
Added user 'johngalt' to file 'C:\dev\jboss-eap-6.2\domain\configuration\application-users.properties'
Added user 'johngalt' with groups user to file 'C:\dev\jboss-eap-6.2\standalone\configuration\application-roles.properties'
Added user 'johngalt' with groups user to file 'C:\dev\jboss-eap-6.2\domain\configuration\application-roles.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? no
Press any key to continue . . .

C:\dev\jboss-eap-6.2\bin>

这为我工作



Answer 2:

这是我的作品。 这个加到web.xml

    <security-constraint>
    <web-resource-collection>
        <web-resource-name>HtmlAuth</web-resource-name>
        <description>application security constraints
        </description>
        <url-pattern>/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>ApplicationRealm</realm-name>
</login-config>
<security-role>
    <role-name>user</role-name>
</security-role>

然后加入或创建的jboss-web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>java:/jaas/other</security-domain>
</jboss-web>

添加用户名到JBoss:C:\ jboss的\ jboss的-EAP-6.2 \ BIN>附加user.bat

What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a): b

Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : testid
User 'testid' already exits, would you like to update the existing user password
 and roles
Is this correct yes/no? yes
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated
list, or leave blank for none)[user]: user,Manager
Updated user 'testid' to file 'C:\jboss\jboss-eap-6.2\standalone\configuration\a
pplication-users.properties'
Updated user 'testid' to file 'C:\jboss\jboss-eap-6.2\domain\configuration\appli
cation-users.properties'
Updated user 'testid' with groups user,Manager to file 'C:\jboss\jboss-eap-6.2\s
tandalone\configuration\application-roles.properties'
Updated user 'testid' with groups user,Manager to file 'C:\jboss\jboss-eap-6.2\d
omain\configuration\application-roles.properties'
Is this new user going to be used for one AS process to connect to another AS pr
ocess?
 e.g. for a slave host controller connecting to the master or for a Remoting conn
ection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <sec
ret value="TWF2ZXJpY2sjMDE=" />
Press any key to continue . . .


Answer 3:

我没有看到改变的JBoss配置的要求,如果你想以后更改服务器容器,配置也需要改变。 取而代之的是,使用会话对象来检查是否已经存在会话。 如果它不重定向页面登录页面。 这将返回当前会话。

request.getSession();

在您的登录页面,设置当前会话属性

session.setAttribute('sess',request.getSession());

使用这种比较,用户将不能够直接访问任何其他页面。



Answer 4:

在JBoss上AS6 web应用基本身份验证

http://middlewaremagic.com/jboss/?p=220

应该是很相似7



文章来源: How to configure simple authentication in Jboss7.1