您的位置:首页 > 其它

jboss EAP-6.3.0下配置JAAS安全应用

2014-11-02 15:11 330 查看
1.配置jboss

1.1打开standalone\configuration下的standalone.xml文件,在security-domains标签下新增一个安全域,code也可以是自己实现的一个类,



1.2在standalone\configuration目录下新建users.properties,roles.properties两个文件,也就是上面配置的两个文件

users.properties中添加guan=123,也就是用户名和密码

roles.properties 中添加guan=JBossAdmin,也就是用户名和角色,角色后面会用到

2.用eclipse开发工具新建一个Dynamic Web Project

3.配置web应用:

打开web应用中的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<security-role>

<role-name>JBossAdmin</role-name>

</security-role>



<security-constraint>

<web-resource-collection>

<web-resource-name>HtmlAdaptor</web-resource-name>

<url-pattern>/*</url-pattern>

<http-method>GET</http-method>

<http-method>POST</http-method>

</web-resource-collection>

<auth-constraint>

<role-name>JBossAdmin</role-name>

</auth-constraint>

</security-constraint>



<login-config>

<auth-method>BASIC</auth-method>

<realm-name>JBoss JMX Console</realm-name>

</login-config>



<display-name>ServletTest</display-name>

<welcome-file-list>

<welcome-file>Login.jsp</welcome-file>

</welcome-file-list>

</web-app>

解释一下:

配置该应用中的角色,可以多个

<security-role>

<role-name>JBossAdmin</role-name>

</security-role>

配置应用中哪些页面可访问,哪些页面不可访问,什么方式(post,get)可以访问,什么方式不可以访问,什么角色可以访问等信息。

<security-constraint>

<web-resource-collection>

<web-resource-name>HtmlAdaptor</web-resource-name>

<url-pattern>/*</url-pattern>

<http-method>GET</http-method>

<http-method>POST</http-method>

</web-resource-collection>

<auth-constraint>

<role-name>JBossAdmin</role-name>

</auth-constraint>

</security-constraint>

配置登录方式,有两种一种是自定义的,一种为简单类型,下面的是简单类型

<login-config>

<auth-method>BASIC</auth-method>

<realm-name>JBoss JMX Console</realm-name>

</login-config>

4.在WEB-INF下新建一个jboss-web.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<jboss-web>

<security-domain>testJAAS</security-domain>

</jboss-web>

也就是指定使用jboss中的哪个安全域,testJAAS是一开始在jboss中配置的安全域

5.整个工程:



6.访问

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: