`
j2ee_zhongqi
  • 浏览: 206886 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

<login-config><auth-method>BASIC</auth-method></login-config>

阅读更多
web实现basic与FORM验证
在web应用中,要经常对用户的身份进行验证的,但其实TOMCAT下配合SERVLET的话,也可以实现一些简单的验证,以往
可能大家都会忽略之,现再简单总结学习之。

1、BASIC验证机制
     这有点象WINDOWS集成验证机制,就是验证时弹出一个窗口,要你输入用户名和密码。做法如下
     首先建立在webapps下建立目录member,下面放一个需要假设要权限才能查看的页面test.html,
然后在tomcat的\conf目录下找到tomcat-users.xml文件,在其中增加
<user username="test" password="test" roles="member"/>
这里我们定义了角色member

然后再在web.xml里,如下定义
 
<web-app>
<security-constraint>
  <web-resource-collection>
     <web-resource-name>
        Member Area
     </web-resource-name>
     <description>
        Only registered members can access this area.
     </description>
     <url-pattern>/member/*</url-pattern>
     <http-method>GET</http-method>
     <http-method>POST</http-method>
  </web-resource-collection>
  <auth-constraint>
     <role-name>member</role-name>
  </auth-constraint>
</security-constraint>
<login-config>
  <auth-method>BASIC</auth-method>
</login-config>
<security-role>
  <role-name>member</role-name>
</security-role>
</web-app>

这里用<login-config>
  <auth-method>BASIC</auth-method>
</login-config>
指出采用basic验证方式,并指出了对于访问/member/*下的文件时,都需要获得 member角色的授权。

2、form表单验证
     这里首先搞一个要输入用户名和密码的页面a.html,再搞一个当出错时显示的页面error.html,注意用户名和密码的文本框的设计中,
要规定name='j_username'  name='j_password',,并要设定<form action='j_security_check' method='POST'>

然后在tomcat-users.html中设定用户帐号member(同上),web.xml设定如下
<web-app>
<security-constraint>
  <web-resource-collection>
     <web-resource-name>
        Member Area
     </web-resource-name>
     <description>
        Only registered members can access this area.
     </description>
     <url-pattern>/member/*</url-pattern>
     <http-method>GET</http-method>
     <http-method>POST</http-method>
  </web-resource-collection>
  <auth-constraint>
     <role-name>member</role-name>
  </auth-constraint>
</security-constraint>
<login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
     <form-login-page>/login/a.html
     </form-login-page>
     <form-error-page>/login/error.html
     </form-error-page>
  </form-login-config>
</login-config>
<security-role>
  <role-name>member</role-name>
</security-role>
</web-app>
最后设定web.xml
分享到:
评论

相关推荐

    启用了不安全的http方法漏洞

    在web.xml文件中配置下面一段内容 &lt;security-constraint&gt; &lt;web-resource-collection&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;http-method&gt;PUT&lt;/http-method&gt; ... &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt;

    基于Tomcat的安全验证机制

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; ``` 2. **DIGEST认证**:比BASIC认证更安全,因为它使用MD5加密对请求数据进行认证。配置如下: ```xml &lt;login-config&gt; &lt;auth-method&gt;DIGEST&lt;/auth-method&gt;...

    各中间件禁用不安全的HTTP方法

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; ``` 3. **修改TOMCAT配置文件**:最后,还需要修改TOMCAT自身的配置文件,通常是位于`conf`目录下的`web.xml`,按照上述步骤进行操作。 完成上述配置后,...

    struts2.3.3运行配置

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; &lt;/web-app&gt; ``` 7. **编写 Java 动作类**:创建动作类 `Test.java`,用于处理用户的登录请求: ```java package com.zhu.login.action; import ...

    tomcat禁止PUT等方法

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; &lt;/web-app&gt; ``` 总结 在本文中,我们讨论了如何禁止 Tomcat 上的 PUT 等方法,以确保应用程序的安全性。我们修改了 web.xml 文件,添加了 security-...

    web.xml配置文件详解

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; &lt;/web-app&gt; ``` #### 五、总结 通过对`web.xml`文件的详细分析,我们可以看出它是Web应用配置的关键所在。正确地配置`web.xml`不仅可以帮助我们更好地组织和...

    apache-tomcat-9.0.35-solr7.7.3.rar

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;/login-config&gt; ``` 6. **重启Tomcat**:保存更改并重启Tomcat,现在访问`http://localhost:8080/solr/`时,浏览器将提示输入用户名和密码。输入你在`tomcat-users.xml`中...

    webService添加basic验证

    3. **指定认证方式**:在`&lt;login-config&gt;`元素中设置`&lt;auth-method&gt;`为`BASIC`,并定义`&lt;realm-name&gt;`来标识验证区域。 4. **定义角色**:通过`&lt;security-role&gt;`元素定义角色名称,例如`bank_member`。 5. **完整...

    Tomcat 的安全方面设置 简单配置过程 说明

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;SessiontestRealm&lt;/realm-name&gt; &lt;/login-config&gt; ``` 2. **FORM认证**: ```xml &lt;login-config&gt; &lt;auth-method&gt;FORM&lt;/auth-method&gt; &lt;realm-name&gt;...

    Tomcat Basic Form认证实例!

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;MyRealm&lt;/realm-name&gt; &lt;/login-config&gt; ``` 2. **服务器配置**:创建一个`context.xml`文件,定义 Realm(域)信息,如数据库连接或其他身份验证源。例如,使用...

    web.xml详解(txt)

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;MyRealm&lt;/realm-name&gt; &lt;/login-config&gt; ``` ##### 2.19 `&lt;security-role&gt;` - **定义**:定义安全角色。 - **用途**:用于指定角色名称及其权限。 - **子元素**:...

    tomcat文档

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;My Realm&lt;/realm-name&gt; &lt;/login-config&gt; ``` **3.2.10 配置对安全验证角色的引用** 角色引用配置示例: ```xml &lt;security-role&gt; &lt;role-name&gt;admin&lt;/role-name&gt; ...

    web.xml详细说明

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;Secure App&lt;/realm-name&gt; &lt;/login-config&gt; ``` 18. **`&lt;security-role&gt;`** - **作用**:定义安全角色。 - **示例**: ```xml &lt;security-role&gt; &lt;role-name&gt;...

    XML配置详解

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;My Realm&lt;/realm-name&gt; &lt;/login-config&gt; ``` ##### 13. `&lt;security-role&gt;` 和 `&lt;env-entry&gt;` - **`&lt;security-role&gt;`**:定义了安全角色列表,这些角色将在...

    web.xml文件详解

    - 示例:`&lt;login-config&gt;&lt;auth-method&gt;BASIC&lt;/auth-method&gt;&lt;realm-name&gt;Secure App&lt;/realm-name&gt;&lt;/login-config&gt;`。 19. **security-role**:`&lt;security-role&gt;` 元素定义角色名称,这些角色可用于 `&lt;security-...

    Web.xml配置详解精华

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;My Realm&lt;/realm-name&gt; &lt;/login-config&gt; ``` **16. security-role** ```xml &lt;security-role&gt; &lt;role-name&gt;admin&lt;/role-name&gt; &lt;/security-role&gt; ``` #### 四、...

    用web.xml控制Web应用的行为

    - **指定验证的方法**:通过`&lt;login-config&gt;`元素定义认证机制,如`&lt;auth-method&gt;BASIC&lt;/auth-method&gt;`。 - **限制对Web资源的访问**:使用`&lt;security-constraint&gt;`元素定义安全约束,限制URL或资源的访问权限。 ...

    JBOSS4.2 基本配置(全)

    &lt;auth-method&gt;BASIC&lt;/auth-method&gt; &lt;realm-name&gt;JBoss Realm&lt;/realm-name&gt; &lt;/login-config&gt; ``` 并在`server/default/conf/login-config.xml`中配置相应的角色和用户。 6. **其他高级配置**:除了以上基础配置...

Global site tag (gtag.js) - Google Analytics