简体   繁体   中英

maven-tomcat plugin deploy on Remote server

I want to deploy my application with maven on a remote server in order to have a continuous integration system :).

I've checked many issues on stackoverflow but couldn't make it work. First I'll show you my error, then the configuration I've made. Here si the message about the upload, it seems to be correct : Uploaded: http://SERVEUR_IP/manager/text/deploy?path=%2FGiveMeAShow (49631 KB at 51.5 KB/sec)

The error :

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project GiveMeAShow: Tomcat return http status error: 401, Reason Phrase: Unauthorized:
[ERROR] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
[ERROR] <html>
[ERROR] <head>
[ERROR] <title>401 Unauthorized</title>
[ERROR] <style type="text/css">
[ERROR] <!--
[ERROR] BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;font-size:12px;}
[ERROR] H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
[ERROR] PRE, TT {border: 1px dotted #525D76}
[ERROR] A {color : black;}A.name {color : black;}
[ERROR] -->
[ERROR] </style>
[ERROR] </head>
[ERROR] <body>
[ERROR] <h1>401 Unauthorized</h1>
[ERROR] <p>
[ERROR] You are not authorized to view this page. If you have not changed
[ERROR] any configuration files, please examine the file
[ERROR] <tt>conf/tomcat-users.xml</tt> in your installation. That
[ERROR] file must contain the credentials to let you use this webapp.
[ERROR] </p>
[ERROR] <p>
[ERROR] For example, to add the <tt>manager-gui</tt> role to a user named
[ERROR] <tt>tomcat</tt> with a password of <tt>s3cret</tt>, add the following to the
[ERROR] config file listed above.
[ERROR] </p>
[ERROR] <pre>
[ERROR] &lt;role rolename="manager-gui"/&gt;
[ERROR] &lt;user username="tomcat" password="s3cret" roles="manager-gui"/&gt;
[ERROR] </pre>
[ERROR] <p>
[ERROR] Note that for Tomcat 7 onwards, the roles required to use the manager
[ERROR] application were changed from the single <tt>manager</tt> role to the
[ERROR] following four roles. You will need to assign the role(s) required for
[ERROR] the functionality you wish to access.
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li><tt>manager-gui</tt> - allows access to the HTML GUI and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-script</tt> - allows access to the text interface and the
[ERROR] status pages</li>
[ERROR] <li><tt>manager-jmx</tt> - allows access to the JMX proxy and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-status</tt> - allows access to the status pages only</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] The HTML interface is protected against CSRF but the text and JMX interfaces
[ERROR] are not. To maintain the CSRF protection:
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li>Users with the <tt>manager-gui</tt> role should not be granted either
[ERROR] the <tt>manager-script</tt> or <tt>manager-jmx</tt> roles.</li>
[ERROR] <li>If the text or jmx interfaces are accessed through a browser (e.g. for
[ERROR] testing since these interfaces are intended for tools not humans) then
[ERROR] the browser must be closed afterwards to terminate the session.</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] For more information - please see the
[ERROR] <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.
[ERROR] </p>
[ERROR] </body>
[ERROR]
[ERROR] </html>
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

It seems pretty clear, it's an authorization problem. Let's have a look at my remote tomcat7 tomcat-users.xml file :

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="admin-gui"/>
        <role rolename="manager-script"/>
        <role rolename="admin-script"/>
        <user username="admin" password="password" roles="manager-gui,manager-script,admin-gui,admin-script" />
</tomcat-users>

I know I should not grant all the roles, but hey it doesn't work so I'm trying :).

I am able to log into app manager/admin page via HTTP in my browser with "admin" and "password". I think this is fine.

Here is my configuration in maven-tomcat-plugin :

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <usernamee>admin</usernamee>
        <password>password</password>
        <url>http:SERVEUR_IP/manager/text</url>
        <server>TomcatServer</server>
        <path>/GiveMeAShow</path>
    </configuration>
</plugin>

When I started to try I was not able to upload the war file. Adding this has permitted me to do so. But it seems the authorization problem comes later.

I've also put a settings.xml file in my remote server in ~/.m2/settings.xml :

<?xml version='1.0' encoding='utf-8'?>
<servers>
        <server>
                <id>TomcatServer</id>
                <username>admin</username>
                <password>password</password>
        </server>
</servers>

The ~/.m2 folder only contains one subfolder and this file I created.

Note that I'm doing all this stuff using root user.

I don't know what to try now, thank's for your help !

EDIT

I did like @fatteddy said : - Created a deployment-only user. With only the role "manager-script" - Corrected my error in pom.xml, changing <usernamee> to </username>

I think creting a deployment-only user did the most of the job as I was testing on TRAVIS-CI at the same time with env variables in <username> tags written without errors.

actually this is an authentication issue. Try to define (for security reasons obviously) a separate deployment-user with the the manager-script (this an only this) role assigned. Don't forget to restart tomcat.

If this does not help change the path segment of the tomcat manager URL (combinations of manager/ , manager , manager/text , manager/text/ -> as far as i can remember there are/or have been issues with trailing slashes which have been fixed in later tomcat versions)

The simplest thing that I forgot to do is - to restart Tomcat after its settings changing. This phrase - "Don't forget to restart tomcat" helped a lot! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM