tomcat8 访问 Host Manager时,role(角色)的授予

参考:http://blog.csdn.net/happy492/article/details/6069579

1.出错情形:

Host Manager,在访问时候,出现 403 拒绝访问,大意是,权限不够;

2.简单分析:

Host Manager,在访问时候,需要设定“特定的权限”,需要对 %apache-tomcat-8.0.8%conf 下,tomcat-users.xml web.xml 这2个文件内容作稍微调整。

3.大致思路:

(a). 访问 server 资源,首先确定哪个账号,具有哪些权限;

(b). 如何对 server 参数进行配置,已达到能够顺利访问资源的愿望?当然,你要了解 tomcat 的目录结构了(不是本篇重点,不再赘述,另行google)

本篇操作 server 涉及到的目录结构及文件:

%apache-tomcat-8.0.8%conftomcat-users.xml  (登陆服务器,账号信息)

%apache-tomcat-8.0.8%confweb.xml                 (web应用参数配置信息)

%apache-tomcat-8.0.8%confserver.xml               (服务器参数信息)

4.  具体操作流程:{a.b.c 三小步实现,对登陆账号的设定,及权限(身份)的授予(认证)。}

这一部分,最好结合 xml 文件对应的 java源码文件了解下,各个“组件”之间的关联。

(a). 先定义某个账号(用来访问 server资源),比如 admin/admin , 好,进入 tomcat-users.xml 设置相应账号。

下面内容可以跳过到(b).

Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html

A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html

An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html

This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.

(b).接下来,账号设置了,访问服务器,需要特定的“身份", roles 派上用场。(看上图)

当然,要用这些"身份"(roles),需要先对其定义。关于 用户的几个角色,可以另行 google

(c). 账号 + 角色,我们得到了。但需要让服务器知道我们可以访问哪些资源。

参考:

web.xml中<security-constraint>和四种认证类型 - - ITeye技术网站
http://yanghongxia9.iteye.com/blog/1217085

tomcat对于web.xml的security-constraint使用的处理机制 - 杨军的博客 - 博客频道 - CSDN.NET
http://blog.csdn.net/yangjun2/article/details/8211492

5. 总结:

出了问题不要怕,仔细看看问题的描述,自己能否理解大概什么问题。tomcat 这种开源服务器,自身在设计时候,作者对整个项目的思路,你可以通过整个目录结构的大意去揣测。比较重要的几点:

(a). 出错了,先自己理解,自己不能解决,一般90%以上问题,都是别人遇到过的,google之。解决问题的过程,就是锻炼思维,加深理解,提高自己的过程。

(b). 有空了解下目录结构,知道哪些文件存哪个目录,一些重要目录比如:logs conf 这些目录下的文件,其实会帮你解决80%的难题。

(c). 本篇只是讲了一些皮毛,至于底层的一些实现,可以看些tomcat相关专业的书籍。毕竟,好书还是节省不少时间的。

其他问题:

(a).tomcat 如何设置多个域名?

(b).tomcat 如何实现热部署?

http://wenku.baidu.com/link?url=hjBv-Vle08PAnFIGZHys4mB4BMGhpG_p86ZDAHAM3M6L8QzfPHaBZXsUL0LNANbzDwQvmf6G5GMD6cv4ibXrmFughvD1_24e-dEgkcKy6hS 

(c).与其他服务器性能对比

http://wenku.baidu.com/view/6cced2d8ce2f0066f53322c9.html

(d).tomcat 工作原理

http://wenku.baidu.com/view/bf35b52d7375a417866f8f06.html

越努力,越幸运.
原文地址:https://www.cnblogs.com/coding2ing/p/4003784.html