Author: snicoll
Date: Tue Apr 11 10:00:18 2006
New Revision: 393260
URL: http://svn.apache.org/viewcvs?rev=393260&view=rev
Log:
MEAR-8: Added security-roles management for the generated application.xml
Added:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SecurityRole.java
Modified:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
maven/plugins/trunk/maven-ear-plugin/src/site/apt/howto.apt
Modified:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java?rev=393260&r1=393259&r2=393260&view=diff
==============================================================================
---
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
(original)
+++
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
Tue Apr 11 10:00:18 2006
@@ -52,7 +52,8 @@
this.encoding = encoding;
}
- public void write( File destinationFile, List earModules, String
displayName, String description )
+ public void write( File destinationFile, List earModules, List
securityRoles, String displayName,
+ String description )
throws EarPluginException
{
FileWriter w;
@@ -70,28 +71,36 @@
if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) )
{
writer = initializeRootElementOneDotThree( w );
- writeDisplayName(displayName, writer);
- writeDescription(description, writer);
+ writeDisplayName( displayName, writer );
+ writeDescription( description, writer );
}
else if ( GenerateApplicationXmlMojo.VERSION_1_4.equals( version ) )
{
writer = initializeRootElementOneDotFour( w );
- writeDescription(description, writer);
- writeDisplayName(displayName, writer);
+ writeDescription( description, writer );
+ writeDisplayName( displayName, writer );
}
- Iterator i = earModules.iterator();
- while ( i.hasNext() )
+ final Iterator moduleIt = earModules.iterator();
+ while ( moduleIt.hasNext() )
{
- EarModule module = (EarModule) i.next();
+ EarModule module = (EarModule) moduleIt.next();
module.appendModule( writer, version );
}
+
+ final Iterator securityRoleIt = securityRoles.iterator();
+ while ( securityRoleIt.hasNext() )
+ {
+ SecurityRole securityRole = (SecurityRole) securityRoleIt.next();
+ securityRole.appendSecurityRole( writer );
+ }
+
writer.endElement();
close( w );
}
- private void writeDescription(String description, XMLWriter writer)
+ private void writeDescription( String description, XMLWriter writer )
{
if ( description != null )
{
@@ -101,7 +110,7 @@
}
}
- private void writeDisplayName(String displayName, XMLWriter writer)
+ private void writeDisplayName( String displayName, XMLWriter writer )
{
if ( displayName != null )
{
Modified:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=393260&r1=393259&r2=393260&view=diff
==============================================================================
---
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
(original)
+++
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
Tue Apr 11 10:00:18 2006
@@ -18,10 +18,14 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
/**
* A Mojo that generates the application.xml deployment descriptor file.
@@ -82,12 +86,21 @@
private String encoding = UTF_8;
/**
+ * The security-roles to be added to the auto-generated
+ * application.xml file.
+ *
+ * @parameter
+ */
+ private PlexusConfiguration security;
+
+ /**
* Directory where the application.xml file will be auto-generated.
*
* @parameter expression="${project.build.directory}"
*/
private String generatedDescriptorLocation;
+
public void execute()
throws MojoExecutionException, MojoFailureException
{
@@ -101,6 +114,7 @@
getLog().debug( "description[" + description + "]" );
getLog().debug( "encoding[" + encoding + "]" );
getLog().debug( "generatedDescriptorLocation[" +
generatedDescriptorLocation + "]" );
+ getLog().debug( "security[" + security + "]" );
if ( !generateApplicationXml.booleanValue() )
{
@@ -151,6 +165,48 @@
File descriptor = new File( outputDir, "application.xml" );
ApplicationXmlWriter writer = new ApplicationXmlWriter( version,
encoding );
- writer.write( descriptor, getModules(), displayName, description );
+ writer.write( descriptor, getModules(), buildSecurityRoles(),
displayName, description );
+ }
+
+ /**
+ * Builds the security roles based on the configuration.
+ *
+ * @return a list of SecurityRole object(s)
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private List buildSecurityRoles()
+ throws EarPluginException
+ {
+ try
+ {
+ final PlexusConfiguration[] securityRoles = security.getChildren(
SecurityRole.SECURITY_ROLE );
+ final List result = new ArrayList();
+ for ( int i = 0; i < securityRoles.length; i++ )
+ {
+ PlexusConfiguration securityRole = securityRoles[i];
+ final String id = securityRole.getAttribute(
SecurityRole.ID_ATTRIBUTE );
+ final String roleName = securityRole.getChild(
SecurityRole.ROLE_NAME ).getValue();
+ final String roleNameId =
+ securityRole.getChild( SecurityRole.ROLE_NAME
).getAttribute( SecurityRole.ID_ATTRIBUTE );
+ final String description = securityRole.getChild(
SecurityRole.DESCRIPTION ).getValue();
+ final String descriptionId =
+ securityRole.getChild( SecurityRole.DESCRIPTION
).getAttribute( SecurityRole.ID_ATTRIBUTE );
+
+ if ( roleName == null )
+ {
+ throw new EarPluginException( "Invalid security-role
configuration, role-name could not be null." );
+ }
+ else
+ {
+ result.add( new SecurityRole( roleName, roleNameId, id,
description, descriptionId ) );
+ }
+ }
+ return result;
+ }
+ catch ( PlexusConfigurationException e )
+ {
+ throw new EarPluginException( "Invalid security-role
configuration", e );
+ }
+
}
}
Added:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SecurityRole.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SecurityRole.java?rev=393260&view=auto
==============================================================================
---
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SecurityRole.java
(added)
+++
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SecurityRole.java
Tue Apr 11 10:00:18 2006
@@ -0,0 +1,134 @@
+package org.apache.maven.plugin.ear;
+
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The representation of a security-role entry within an
+ * application.xml file.
+ *
+ * @author <a href="[EMAIL PROTECTED]">Stephane Nicoll</a>
+ * @version $Id: SecurityRole.java 332974 2005-11-13 12:42:44Z snicoll $
+ */
+class SecurityRole
+{
+
+ protected static final String SECURITY_ROLE = "security-role";
+
+ protected static final String ID_ATTRIBUTE = "id";
+
+ protected static final String DESCRIPTION = "description";
+
+ protected static final String ROLE_NAME = "role-name";
+
+ private final String roleName;
+
+ private final String roleNameId;
+
+ private final String roleId;
+
+ private final String description;
+
+ private final String descriptionId;
+
+ public SecurityRole( String roleName, String roleNameId, String roleId,
String description, String descriptionId )
+ {
+ if ( roleName == null )
+ {
+ throw new NullPointerException( "role-name in security-role
element could not be null." );
+ }
+ this.roleName = roleName;
+ this.roleNameId = roleNameId;
+ this.roleId = roleId;
+ this.description = description;
+ this.descriptionId = descriptionId;
+ }
+
+ public String getRoleName()
+ {
+ return roleName;
+ }
+
+ public String getRoleNameId()
+ {
+ return roleNameId;
+ }
+
+ public String getRoleId()
+ {
+ return roleId;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public String getDescriptionId()
+ {
+ return descriptionId;
+ }
+
+ /**
+ * Appends the <tt>XML</tt> representation of this security role.
+ *
+ * @param writer the writer to use
+ */
+ public void appendSecurityRole( XMLWriter writer )
+ {
+ writer.startElement( SECURITY_ROLE );
+
+ // role id
+ if ( getRoleId() != null )
+ {
+ writer.addAttribute( ID_ATTRIBUTE, getRoleId() );
+ }
+
+ // description
+ if ( getDescription() != null )
+ {
+ writer.startElement( DESCRIPTION );
+ if ( getDescriptionId() != null )
+ {
+ writer.addAttribute( ID_ATTRIBUTE, getDescriptionId() );
+ }
+ writer.writeText( getDescription() );
+ writer.endElement();
+
+ }
+
+ // role name
+ writer.startElement( ROLE_NAME );
+ if ( getRoleNameId() != null )
+ {
+ writer.addAttribute( ID_ATTRIBUTE, getRoleNameId() );
+ }
+ writer.writeText( getRoleName() );
+ writer.endElement();
+
+ // end of security-role
+ writer.endElement();
+ }
+
+ public String toString()
+ {
+ return "Security role " + getRoleName();
+ }
+
+
+}
Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/howto.apt
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ear-plugin/src/site/apt/howto.apt?rev=393260&r1=393259&r2=393260&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/site/apt/howto.apt (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/howto.apt Tue Apr 11
10:00:18 2006
@@ -12,9 +12,7 @@
application.xml. This generation is already customized by the goal's
parameters,
see {{{index.html}the goals description}}.
- Ear modules might be further customized as follows:
-
- * contextRoot: the custom context root for a web application
+ Any Ear module might be further customized as follows:
* bundleDir: the directory in the EAR structure where the artifact will be
stored
@@ -22,15 +20,18 @@
* uri: the complete path in the EAR structure for the artifact
- Also, a dependency might be excluded from the generated EAR file by
specifying the
- excluded flag.
+ * excluded: excludes the artifact from the generated ear
+
+ The context root of a Web module might be customized using the contextRoot
parameter.
Please note that third party libraries are not included in the generated
application.xml (only ejb-client should be included in a <java> entry).
However, a
jar dependency could be included in the generated application.xml by
specifying the
includeInApplicationXml flag.
- It is also possible to specify a default bundle directory for all third
party libraries
+ It is also possible to specify a default bundle directory for all third
party libraries.
+
+ The security settings might be specified under the security parameter.
Customizing the context root
@@ -209,6 +210,34 @@
<includeInApplicationXml>true</includeInApplicationXml>
</javaModule>
</modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
++---------
+
+
+Specifying security roles for the generated application.xml
+
+ Security roles might be specified as follows
+
++--------
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ [...]
+ <security>
+ <security-role id="SecurityRole_1234">
+ <role-name>manager</role-name>
+ </security-role>
+ <security-role id="SecurityRole_5678">
+ <description>My cool description</description>
+ <role-name id="RoleName_12">teller</role-name>
+ </security-role>
+ </security>
</configuration>
</plugin>
</plugins>