SecureAWebApplicationInJBoss

本文介绍如何使用基本认证为JBossAS中的Web应用程序设置安全域。包括修改web.xml添加安全约束,配置jboss-web.xml指向安全域等步骤。

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
跟网型逆变器小干扰稳定性分析与控制策略优化研究(Simulink仿真实现)内容概要:本文围绕跟网型逆变器的小干扰稳定性展开分析,重点研究其在电力系统中的动态响应特性及控制策略优化问题。通过构建基于Simulink的仿真模型,对逆变器在不同工况下的小信号稳定性进行建模与分析,识别系统可能存在的振荡风险,并提出相应的控制优化方法以提升系统稳定性和动态性能。研究内容涵盖数学建模、稳定性判据分析、控制器设计与参数优化,并结合仿真验证所提策略的有效性,为新能源并网系统的稳定运行提供理论支持和技术参考。; 适合人群:具备电力电子、自动控制或电力系统相关背景,熟悉Matlab/Simulink仿真工具,从事新能源并网、微电网或电力系统稳定性研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 分析跟网型逆变器在弱电网条件下的小干扰稳定性问题;② 设计并优化逆变器外环与内环控制器以提升系统阻尼特性;③ 利用Simulink搭建仿真模型验证理论分析与控制策略的有效性;④ 支持科研论文撰写、课题研究或工程项目中的稳定性评估与改进。; 阅读建议:建议读者结合文中提供的Simulink仿真模型,深入理解状态空间建模、特征值分析及控制器设计过程,重点关注控制参数变化对系统极点分布的影响,并通过动手仿真加深对小干扰稳定性机理的认识。
内容概要:本文是一份《智能花盆进阶版:零基础完整落地教程》的详细指南,涵盖从项目规划、材料采购、硬件连接、代码编写到系统集成与调试的全过程。该智能花盆系统具备土壤湿度监测、自动浇水、光照监测、智能补光、土壤温度监测、手动控制、数据串口显示及阈值可调等多项功能。教程通过分步讲解Arduino Uno与各类传感器(如电容式土壤湿度传感器、DS18B20温度传感器、BH1750光照传感器)和执行器(继电器控制水泵、MOSFET调光LED灯)的连接与编程,帮助读者构建一个全自动化的植物养护系统。同时提供测试代码、校准方法、故障排查和维护建议,确保项目可被零基础用户成功实现。 适合人群:零基础或具备初步电子与编程知识的爱好者,适合学生、创客、DIY爱好者以及希望入门物联网与嵌入式系统的初学者。 使用场景及目标:①学习Arduino开发与传感器集成应用;②实践自动化控制系统的设计与调试;③完成一个可实际部署的智能园艺项目,用于家庭植物养护;④掌握从硬件搭建到软件编程的完整项目落地流程。 阅读建议:建议读者严格按照文档步骤操作,先逐一测试各模块再进行系统集成,重视传感器校准与电源管理,配合串口调试信息排查问题,同时可基于教程提供的扩展建议(如添加WiFi、显示屏、数据记录等)进行二次开发。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值