为什么 Ant 在部署时返回 403? [英] Why is Ant returning a 403 on deploy?

查看:23
本文介绍了为什么 Ant 在部署时返回 403?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Tomcat 7 中部署到一个 war 文件.它给了我以下错误.

I'm attempting to deploy to a war file in Tomcat 7. It's giving me the following error.

deploy:
   [echo] Deploying on Tomcat.

BUILD FAILED
   C:\Users\coder\workspace\projectName\build.xml:84: java.io.IOException: Server returned    
   HTTP response code: 403 for URL: http://localhost:8090/manager/deploy?path=%2FprojectName

这是我的构建文件

<project name="ProjectName" default="main"
                basedir=".">

                <!-- Tell ant to use my environment variables -->
                <property environment="env"/>

                <property file="./build.properties"/>
                <property name="username" value="someUsername"/>
                <property name="password" value="somePassword"/>

                <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/>

                <property name="tomcat.home"
                value="${env.CATALINA_HOME}"/>
                <property name="hibernate.home"
                value="${env.CATALINA_HOME}"/>
                <property name="servlet.jar"
                value="${tomcat.home}/common/lib/servlet-api.jar"/>
                <property name="jsp.jar"
                value="${tomcat.home}/common/lib/jsp-api.jar"/>
                <property name="hibernate.jar" value="C:/hibernate-distribution-3.6.4.Final/hibernate3.jar"/>

                <property name="deploy.dir"
                value="${tomcat.home}/webapps"/>
                <property name="build.compiler" value="modern"/>
                <property name="build.dir" value="build" />
                <property name="src.dir" value="src"/>
                <property name="war.file" value="projectName"/>
                <property name="war.file.name" value="${war.file}.war"/>

                <path id="project.class.path">
                <fileset dir="./WEB-INF/lib/">
                <include name="**/*.jar"/>
                </fileset>
                <pathelement path="${src.dir}"/>
                <pathelement path="${servlet.jar}"/>
                <pathelement path="${jsp.jar}"/>
                <pathelement path="${hibernate.jar}"/>
                </path>

                <target name="clean">
                <delete dir="${build.dir}" includeEmptyDirs="true" />
                </target>

                <target name="prep">
                <mkdir dir="${build.dir}"/>
                </target>

                <target name="compile">
                <javac srcdir="${src.dir}"
                destdir="${build.dir}"
                debug="on"
                deprecation="on">
                <include name="**/*.java"/>
                <classpath refid="project.class.path"/>
                </javac>
                </target>

                <target name="cleanWebApp">
                <delete file="${deploy.dir}/${war.file.name}" />
                <delete dir="${deploy.dir}/${war.file}"
                includeEmptyDirs="true" />
                </target>

                <target name="war">
                <war warfile="${war.file.name}"
                webxml="./WEB-INF/web.xml">
                <fileset dir="./" includes="**/*.*" excludes="*.war,
                **/*.nbattrs, web.xml, **/WEB-INF/**/*.*,
                **/project-files/**/*.*"/>
                <webinf dir="./WEB-INF" includes="**/*"
                excludes="web.xml, **/*.jar, **/*.class"/>
                <lib dir="./WEB-INF/lib"/>
                <classes dir="${build.dir}"/>
                <classes dir="${src.dir}">
                <include name="**/*.properties"/>
                </classes>
                </war>
                </target>

                <target name="deploy">
                    <echo message="Deploying on Tomcat." />
                    <deploy url="http://localhost:8090/manager" username="someUsername"
                     password="somePassword" path="/projectName" war="./${war.file.name}" />
                </target>

                <target name="main" depends="clean, prep, cleanWebApp,
                compile, war, deploy"/>

                </project>

推荐答案

manager.username 和 manager.password 中提到的帐号,必须是manager-script"(或者admin-script"也可以,如果这不起作用).

The account mentioned in manager.username and manager.password, has to be in the role of "manager-script" (or "admin-script" also if that does't work).

好像把manager"和admin"角色改成了manager-gui"、admin-gui"、manager-script"(用于文本连接)、admin-script"(用于文本连接)在 Tomcat 7 中.

It seems that "manager" and "admin" roles are changed to "manager-gui", "admin-gui", "manager-script" (for text connection), "admin-script" (for text connection) in Tomcat 7.

我从下面的错误页面中找到了 4 个与经理相关的角色:

I found 4 roles relevant to manager from below error page:

403 访问被拒绝

您无权查看此页面.

如果您已经将 Manager 应用程序配置为允许访问,并且您使用了浏览器的后退按钮、保存的书签或类似的东西,那么您可能触发了已启用的跨站点请求伪造 (CSRF) 保护用于管理器应用程序的 HTML 界面.您需要通过返回主管理器页面来重置此保护.返回此页面后,您将能够继续正常使用管理器应用程序的 HTML 界面.如果您继续看到此访问被拒绝消息,请检查您是否拥有访问此应用程序所需的权限.

If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager appliction's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.

如果您没有更改任何配置文件,请检查安装中的文件 conf/tomcat-users.xml.该文件必须包含允许您使用此网络应用程序的凭据.

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

例如,要将 manager-gui 角色添加到名为 tomcat 且密码为 s3cret 的用户,请将以下内容添加到上面列出的配置文件中.

For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

请注意,从 Tomcat 7 开始,使用管理器应用程序所需的角色已从单一管理器角色更改为以下四个角色.您需要为要访问的功能分配所需的角色.

Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - 允许访问 HTML GUI 和状态页面

manager-gui - allows access to the HTML GUI and the status pages

manager-script - 允许访问文本界面和状态页面

manager-script - allows access to the text interface and the status pages

manager-jmx - 允许访问 JMX 代理和状态页面

manager-jmx - allows access to the JMX proxy and the status pages

manager-status - 只允许访问状态页面

manager-status - allows access to the status pages only

HTML 界面受 CSRF 保护,但文本和 JMX 界面不受保护.维护 CSRF 保护:

The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

具有 manager-gui 角色的用户不应被授予 manager-script 或 manager-jmx 角色.如果 text 或 jmx 接口是通过浏览器访问的(例如用于测试,因为这些接口是为工具而非人类设计的),那么浏览器必须随后关闭以终止会话.如需了解更多信息 - 请参阅 Manager App HOW-TO.

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles. If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session. For more information - please see the Manager App HOW-TO.

这篇关于为什么 Ant 在部署时返回 403?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆