SecureAWebApplicationInJBoss

本文介绍如何通过基本认证为JBossAS中的Web应用程序设置安全保护。主要包括创建简单的安全域、配置Web应用程序的安全约束及登录配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Securing a Web Application in JBoss AS

Securing web resources basically involves setting some stuff in the web deployment descriptor, and in jboss-web.xml. You also have to do a little prep work to the server itself to configure a security domain for JBoss SX. These instructions assume that you have JBoss AS installed, and you have a server instance created with at least Tomcat included. The "default" instance is a good choice here. The variable ${jboss.dist} refers to the location you extracted/installed JBoss AS to, and ${server.name} cooresponds to the name of the server instance you are configuring for security. The first part of these instructions refers to setting up JBoss SX for security, and the second part deals with setting up the web application for security using basic authentication.

Create a simple security domain for JBoss SX

Securing the Web Application with Basic Authentication

Note:Attached is a sample application that can be used to test out securing a web application. There are two files that need to be added/modified in your web application to attach it to the security domain we defined in the previous steps. The web.xml and jboss-web.xml file contain commented out versions of the text to add to a web application that are covered in the next two steps. Also included, is a simple index.jsp that outputs the name of the authenticated JAAS Subject via HttpServletRequest.getRemoteUser().

1. Configure the web application for security by adding constraints to the web deployment descriptor.

You need to modify the web.xml in the WEB-INF directory of the web application you are securing to add in the following:

	<security-constraint>
<web-resource-collection>
<web-resource-name>All resources</web-resource-name>
<description>Protects all resources</description>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>WebAppUser</role-name>
</auth-constraint>
</security-constraint>

<security-role>
<role-name>WebAppUser</role-name>
</security-role>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Test Realm</realm-name>
</login-config>
The "security-constraint" section is what is used to define what resources in the web application are protected. You can have multiple security-constraint elements in the web.xml that have different protections for different resources. You have to have at least one web-resource-collection element to specify what this constraint it protecting. The "url-pattern" element specifies the URL pattern to protect. The example above protects _all_ resources in the web application. The auth-contstraint element specifies which roles have access to the protected resource. The example just specifies one role, but multiple roles can be included by specifying additional role-name elements. This role name needs to match the name of the role you specified in the my-web-roles.properties file. There are ways to have a level of indirection with this role name by using the "security-role-ref" element instead. Finally, the "login-config" element specifies how authentication occurs with the web application. The "auth-method" element specifies how the browser gets credentials from the user. The spec defines "BASIC", "DIGEST", "FORM", and "CLIENT-CERT" as the possible methods to retrieve data from the browser user. The example uses "BASIC" since it is the simplest, but this method shouldn't be used in a production app unless you are also using SSL/TLS since user names and passwords are transmitted in clear text over the network. The "realm-name" element just specifies the authentication realm name that is given to the browser for authentication. This realm is just shown to a user when the authentication dialog is presented.

2. Configure the jboss-web.xml file to point to the "my-web" application.

Add/edit the jboss-web.xml in the WEB-INF directory of the web application you are securing to add the following in the "jboss-web" element:

<security-domain>java:/jaas/my-web</security-domain>
This element tells JBoss AS to connect the web application to the "my-web" security domain we defined in the login-config.xml file earlier. JBoss AS exposes security domains via JNDI by prepending "java:/jaas/" to the name element in the application-policy element in the login-config.xml file.

3. Start up the application server, navigate to your application.

The browser should prompt you for username and password. Enter "chris" for the username, and "secure" for the password. You should then be allowed access to the web application. You can verify this by closing the browser, opening it back up and navigating back to your protected application. When the browser prompts you, you can either enter no credentials, or use the "admin" user account that was in the file originally (password: admin), and see that the web application won't be presented because you didn't log in with a user that had the "WebAppUser?" role.

Related:

JavaWorld JAAS article by Scott Stark: http://prdownloads.sourceforge.net/jboss/jaashowto-32x.zip?download
Attachments:
test.warInfo on test.war1147 bytes
 
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 行列式是线性代数的核心概念,在求解线性方程组、分析矩阵特性以及几何计算中都极为关键。本教程将讲解如何用C++实现行列式的计算,重点在于如何输出分数形式的结果。 行列式定义如下:对于n阶方阵A=(a_ij),其行列式由主对角线元素的乘积,按行或列的奇偶性赋予正负号后求和得到,记作det(A)。例如,2×2矩阵的行列式为det(A)=a11×a22-a12×a21,而更高阶矩阵的行列式可通过Laplace展开或Sarrus规则递归计算。 在C++中实现行列式计算时,首先需定义矩阵类或结构体,用二维数组存储矩阵元素,并实现初始化、加法、乘法、转置等操作。为支持分数形式输出,需引入分数类,包含分子和分母两个整数,并提供与整数、浮点数的转换以及加、减、乘、除等运算。C++中可借助std::pair表示分数,或自定义结构体并重载运算符。 计算行列式的函数实现上,3×3及以下矩阵可直接按定义计算,更大矩阵可采用Laplace展开或高斯 - 约旦消元法。Laplace展开是沿某行或列展开,将矩阵分解为多个小矩阵的行列式乘积,再递归计算。在处理分数输出时,需注意避免无限循环和除零错误,如在分数运算前先约简,确保分子分母互质,且所有计算基于整数进行,最后再转为浮点数,以避免浮点数误差。 为提升代码可读性和可维护性,建议采用面向对象编程,将矩阵类和分数类封装,每个类有明确功能和接口,便于后续扩展如矩阵求逆、计算特征值等功能。 总结C++实现行列式计算的关键步骤:一是定义矩阵类和分数类;二是实现矩阵基本操作;三是设计行列式计算函数;四是用分数类处理精确计算;五是编写测试用例验证程序正确性。通过这些步骤,可构建一个高效准确的行列式计算程序,支持分数形式计算,为C++编程和线性代数应用奠定基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值