maven tomcat插件以及josso相关配置

阅读本文的时候,相信你已经喜欢上了Maven优美的管理方式, 但却为构建webapp而需手动发布到Tomcat发愁,maven插件可以帮你优雅的解决这个问题。笔者最近因为项目需要,和team成员对gringotts原有项目进行改造,从ant移植到maven,本来是件很简单的事情,但因为关联到josso单点登陆,折腾了好久,现将整个过程以及遇到的一些问题做纪录,希望给碰到类似问题的同学一些参考。

1 安装josso agent

去官网下载,然后配置。请参考 http://lelglin.iteye.com/admin/blogs/1866968

2.maven tomcat插件

  • Tomcat Maven plugin
  • Cargo plugin

我首先试用了Tomcat Maven plugin,非常便利,但是他运行的tomcat是内嵌的,无法加载我们需要josso agent。

pom.xml文件增加配置

<build>
		<plugins>
			<!-- tomcat -->
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat6-maven-plugin</artifactId>
				<version>2.0</version>
			</plugin>
		</plugins>
	</build>
然后google查找maven tomcat插件运行外部tomcat的方法,网上确实也找到一下类似的问题,没有合适的解决方案,放弃。

然后我们又尝试了Cargo plugin,它是一个基于标准方式发布Web应用程序到Java EE容器的瘦包装器,它能发布到多种Web服务器,如Geronimo、Glassfish、JBoss、Tomcat、Jetty、WebLogic等。这正是我们想要的。

配置

<build>
	    <finalName>projectName</finalName>
		<plugins>
			<plugin>
				<groupId>org.codehaus.cargo</groupId>
				<artifactId>cargo-maven2-plugin</artifactId>
				<configuration>
					<wait>true</wait>
					<container>
						<containerId>tomcat6x</containerId>
						<type>installed</type>
						<home>/Library/Tomcat</home>
					</container>
					<configuration>
						<type>existing</type>
						<home>/Library/Tomcat</home>
						<properties>
							<cargo.tomcat.manager.url>https://localhost:8080/manager</cargo.tomcat.manager.url>
							<cargo.remote.username>admin</cargo.remote.username>
							<cargo.remote.password>password</cargo.remote.password>
							<cargo.jvmargs>-Djava.security.auth.login.config="/Library/Tomcat/conf/jaas.conf"</cargo.jvmargs>
						</properties>
					</configuration>
					
				</configuration>
				<executions>
					<execution>
						<id>start-container</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>deployer-deploy</goal>
							<!-- Only local containers can be started <goal>start</goal> -->
						</goals>
					</execution>
					<execution>
						<id>stop-container</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>deployer-undeploy</goal>
							<!-- Only local containers can be started <goal>stop</goal> -->
						</goals>
					</execution>
					<execution>
						<id>verify-deploy</id>
						<phase>install</phase>
						<goals>
							<goal>deployer-deploy</goal>
						</goals>
					</execution>
					<execution>
						<id>clean-undeploy</id>
						<phase>pre-clean</phase>
						<goals>
							<goal>deployer-undeploy</goal>
							<!-- Only local containers can be started <goal>stop</goal> -->
						</goals>
					</execution>

				</executions>
			</plugin>
		</plugins>
	</build>
	<dependencies>
问题和注意事项:

1.传递jvm参数,http://lelglin.iteye.com/admin/blogs/1866968 上的方式行不通,需要在<cargo.jvmargs>

<configuration>
						<type>existing</type>
						<home>/Library/Tomcat</home>
						<properties>
							<cargo.tomcat.manager.url>https://localhost:8080/manager</cargo.tomcat.manager.url>
							<cargo.remote.username>admin</cargo.remote.username>
							<cargo.remote.password>password</cargo.remote.password>
							<cargo.jvmargs>-Djava.security.auth.login.config="/Library/Tomcat/conf/jaas.conf"</cargo.jvmargs>
						</properties>
					</configuration>
2 安装josso agent的时候,会自动修改tomcat安装目录下server.xml

原本的这一行会被注释掉,改用josso自己的realm实现,这样就无法登陆tomcat manager,也就是无法通过插件部署。

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
josso agent修改后的配置
<Realm appName="josso" className="org.josso.tc60.agent.jaas.CatalinaJAASRealm" debug="1" roleClassNames="org.josso.gateway.identity.service.BaseRoleImpl" userClassNames="org.josso.gateway.identity.service.BaseUserImpl"/>
 

后来shijun同学发现 ,可以在某个context下面配置jossorealm实现,这样josso agent能够拦截到该context下的request,又不影响tomcatmanager管理应用,具体如下

 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Valve appName="josso" className="org.josso.tc60.agent.SSOAgentValve" debug="1">
    </Valve>
<Context path="/apiConsole" docBase="/Library/Tomcat/webapps/apiConsole" debug="1" reloadable="true">
        <Realm appName="josso" className="org.josso.tc60.agent.jaas.CatalinaJAASRealm" debug="1" roleClassNames="org.josso.gateway.identity.service.BaseRoleImpl" userClassNames="org.josso.gateway.identity.service.BaseUserImpl"/>
     </Context>
 

参考

http://jdonee.iteye.com/blog/774387

http://cargo.codehaus.org/Configuration+properties

猜你喜欢

转载自lelglin.iteye.com/blog/1866976
今日推荐