You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tb...@apache.org on 2006/12/12 16:24:14 UTC
svn commit: r486187 [41/49] - in /directory/trunks/triplesec: ./ admin-api/
admin-api/src/ admin-api/src/main/ admin-api/src/main/java/
admin-api/src/main/java/org/ admin-api/src/main/java/org/safehaus/
admin-api/src/main/java/org/safehaus/triplesec/ a...
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecConfigTool.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecConfigTool.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecConfigTool.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecConfigTool.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,836 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.util;
+
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.directory.server.core.configuration.SyncConfiguration;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.util.Base64;
+import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.apache.tools.ant.Project;
+//import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.dom4j.io.OutputFormat;
+
+import org.safehaus.triplesec.TriplesecInstallationLayout;
+import org.safehaus.triplesec.configui.model.TriplesecConfigSettings;
+import org.safehaus.triplesec.configuration.ContextParameter;
+import org.safehaus.triplesec.configuration.FilterConfiguration;
+import org.safehaus.triplesec.configuration.MutableTriplesecStartupConfiguration;
+import org.safehaus.triplesec.configuration.ServerXmlUtils;
+import org.safehaus.triplesec.configuration.ServletConfiguration;
+import org.safehaus.triplesec.configuration.WebappConfiguration;
+import org.safehaus.triplesec.configuration.XmlUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Used to generate the server.xml file, update the web.xml files of installed
+ * webapps, and setup the ldif files loaded on startup.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class TriplesecConfigTool
+{
+ private static final Logger log = LoggerFactory.getLogger( TriplesecConfigTool.class );
+
+ public static void writeConfiguration( TriplesecInstallationLayout layout, TriplesecConfigSettings settings )
+ throws Exception
+ {
+ // -------------------------------------------------------------------
+ // save the new password and revert to the default one
+ // -------------------------------------------------------------------
+
+ String password = settings.getAdminPassword();
+ settings.setAdminPassword( "secret" );
+ settings.setAdminPassword2( "secret" );
+
+ // -------------------------------------------------------------------
+ // write out the server.xml file but use old password
+ // -------------------------------------------------------------------
+
+ TriplesecConfigBuilder builder = new TriplesecConfigBuilder();
+ TriplesecPropBuilder propBuilder = new TriplesecPropBuilder();
+ Properties props = propBuilder.build( settings );
+ MutableTriplesecStartupConfiguration config = builder.build( settings );
+ ServerXmlUtils.writeConfiguration( layout.getConfigurationFile(), config, props );
+
+ // -------------------------------------------------------------------
+ // start up the server to change the password within the database & shutdown
+ // -------------------------------------------------------------------
+
+ File wkDir = new File( layout.getVarDirectory(), "partitions" );
+ wkDir.mkdirs();
+ setAdminPassword( config, wkDir, password );
+
+ // -------------------------------------------------------------------
+ // rewrite configuration with the new password
+ // -------------------------------------------------------------------
+
+ settings.setAdminPassword( password );
+ settings.setAdminPassword2( password );
+ props = propBuilder.build( settings );
+ config = builder.build( settings );
+ ServerXmlUtils.writeConfiguration( layout.getConfigurationFile(), config, props );
+
+ // -------------------------------------------------------------------
+ // If demo is enabled and installed move it's LDIF files to conf else
+ // delete the entire demo application from the webapps directory
+ // -------------------------------------------------------------------
+
+ // ApacheDS Bug in LDIF File Loading prevents us from using this code
+ // the order of LDIF file loading is not predictable across systems and
+ // this needs to be fixed before we can enable this code here.
+
+// File demo = new File( layout.getWebappsDirectory(), "demo" );
+// if ( settings.isEnableDemo() && demo.exists() )
+// {
+// File demoWebinfDir = new File( demo, "WEB-INF" );
+// File[] ldifFiles = demoWebinfDir.listFiles( new FileFilter() {
+// public boolean accept( File pathname )
+// {
+// if ( pathname.getName().lastIndexOf( ".ldif" ) != -1 )
+// {
+// return true;
+// }
+// return false;
+// }
+// } );
+//
+// // Copy all LDIF files to the conf directory to be loaded on startup
+// Project project = new Project();
+// for ( int ii = 0; ii < ldifFiles.length; ii++ )
+// {
+// Copy cp = new Copy();
+// cp.setProject( project );
+// cp.setFile( ldifFiles[ii] );
+// cp.setTodir( layout.getConfigurationDirectory() );
+// cp.execute();
+// }
+// }
+// else if ( ! settings.isEnableDemo() && demo.exists() )
+// {
+// Project project = new Project();
+// Delete del = new Delete();
+// del.setProject( project );
+// del.setDir( demo );
+// del.execute();
+// }
+
+ // Here's the HACK: we append any LDIF files we find to the server.xml
+ // remove this after fixing the apacheds bug.
+
+ // note we open the file for appending
+ FileOutputStream out = new FileOutputStream(
+ new File( layout.getConfigurationDirectory(), "00server.ldif" ), true );
+
+ File demo = new File( layout.getWebappsDirectory(), "demo" );
+ if ( settings.isEnableDemo() && demo.exists() )
+ {
+ File demoWebinfDir = new File( demo, "WEB-INF" );
+ File[] ldifFiles = demoWebinfDir.listFiles( new FileFilter()
+ {
+ public boolean accept( File pathname )
+ {
+ if ( pathname.getName().lastIndexOf( ".ldif" ) != -1 )
+ {
+ return true;
+ }
+ return false;
+ }
+ } );
+
+ // open the file and read then write bytes to server.ldif
+ for ( int ii = 0; ii < ldifFiles.length; ii++ )
+ {
+ FileInputStream in = new FileInputStream( ldifFiles[ii] );
+ int ch = -1;
+ out.write( '\n' );
+ out.write( '\n' );
+ while ( ( ch = in.read() ) != -1 )
+ {
+ out.write( ch );
+ }
+ out.write( '\n' );
+ out.write( '\n' );
+ in.close();
+ }
+
+ out.close();
+
+ // -------------------------------------------------------------------
+ // Yet another hack! Here we slurp up the spring applicationContext
+ // for the spring based wicket demo application and replace macros
+ // -------------------------------------------------------------------
+
+ File appCtxFile = new File( demo, "WEB-INF" );
+ appCtxFile = new File( appCtxFile, "classes" );
+ appCtxFile = new File( appCtxFile, "applicationContext.xml" );
+ String appCtxTemplate = FileUtils.readFileToString( appCtxFile, "UTF-8" );
+
+ StringBuffer buf = new StringBuffer();
+ String ldapBaseDn = NamespaceTools.inferLdapName( settings.getPrimaryRealmName() );
+ buf.append( "appName=demo,ou=Applications," ).append( ldapBaseDn );
+ appCtxTemplate = appCtxTemplate.replaceAll( "APPLICATION_PRINCIPAL_DN", buf.toString() );
+
+ buf.setLength( 0 );
+ buf.append( "ldap://localhost:" ).append( settings.getLdapPort() ).append( "/" ).append( ldapBaseDn );
+ appCtxTemplate = appCtxTemplate.replaceAll( "CONNECTION_URL", buf.toString() );
+ appCtxTemplate = appCtxTemplate.replaceAll( "REALM", settings.getPrimaryRealmName().toUpperCase() );
+ appCtxTemplate = appCtxTemplate.replaceAll( "SMS_TRANSPORT_URL", settings.getSmsTransportUrl() );
+ appCtxTemplate = appCtxTemplate.replaceAll( "SMS_PASSWORD", settings.getSmsPassword() );
+ appCtxTemplate = appCtxTemplate.replaceAll( "SMS_USERNAME", settings.getSmsUsername() );
+ appCtxTemplate = appCtxTemplate.replaceAll( "SMS_ACCOUNT_NAME", settings.getSmsAccountName() );
+ FileUtils.writeByteArrayToFile( appCtxFile, appCtxTemplate.getBytes( "UTF-8" ) );
+
+ }
+ else if ( !settings.isEnableDemo() && demo.exists() )
+ {
+ Project project = new Project();
+ Delete del = new Delete();
+ del.setProject( project );
+ del.setDir( demo );
+ del.execute();
+ }
+
+ // -------------------------------------------------------------------
+ // read and alter all the ldif file contents
+ // -------------------------------------------------------------------
+
+ File confDir = layout.getConfigurationDirectory();
+ File[] ldifFiles = confDir.listFiles( new FileFilter() {
+ public boolean accept( File pathname )
+ {
+ if ( pathname.getName().lastIndexOf( ".ldif" ) != -1 )
+ {
+ return true;
+ }
+ return false;
+ }
+ } );
+
+ for ( int ii = 0; ii < ldifFiles.length; ii++ )
+ {
+ alterLdifFile( NamespaceTools.inferLdapName( settings.getPrimaryRealmName() ),
+ settings.getPrimaryRealmName(), ldifFiles[ii] );
+ }
+
+ // -------------------------------------------------------------------
+ // scan for webapps other than this one to modify their web.xml
+ // -------------------------------------------------------------------
+
+ File[] webapps = layout.getWebappsDirectory().listFiles( new FileFilter() {
+ public boolean accept( File pathname )
+ {
+ if ( pathname.isDirectory() && ! pathname.getName().endsWith( "config" ) )
+ {
+ return true;
+ }
+ return false;
+ }
+ } );
+
+ for ( int ii = 0; ii < webapps.length; ii++ )
+ {
+ File webXml = new File( new File( webapps[ii], "WEB-INF" ), "web.xml" );
+ alterWebXmlFile( webXml, settings, props );
+ }
+ }
+
+
+ private static void alterWebXmlFile( File webXml, TriplesecConfigSettings settings, Properties props )
+ throws Exception
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "altering webapp configuration: " + webXml.getAbsolutePath() );
+ }
+
+ boolean hasChanged = false;
+ String ldapHost = "localhost";
+ WebappConfiguration webconfig = new WebappConfiguration( webXml );
+
+ String ldapBaseDn = null;
+ if ( settings.getPrimaryRealmName() != null )
+ {
+ ldapBaseDn = NamespaceTools.inferLdapName( settings.getPrimaryRealmName().toLowerCase() );
+ }
+ else
+ {
+ ldapBaseDn = "example.com";
+ }
+
+ try
+ {
+ InetAddress localMachine = InetAddress.getLocalHost();
+ ldapHost = localMachine.getHostName();
+ }
+ catch ( UnknownHostException uhe )
+ {
+ uhe.printStackTrace();
+ }
+
+ for ( Iterator ii = webconfig.getContextParameters(); ii.hasNext(); /****/ )
+ {
+ ContextParameter parameter = ( ContextParameter ) ii.next();
+
+ if ( parameter.getName().equals( "realm" ) && settings.getPrimaryRealmName() != null )
+ {
+ parameter.setValue( settings.getPrimaryRealmName().toUpperCase() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "presentationBaseUrl" ) && settings.getPresentationBaseUrl() != null )
+ {
+ parameter.setValue( settings.getPresentationBaseUrl() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "redirectUrl" ) && settings.getRegRedirectUrl() != null )
+ {
+ parameter.setValue( settings.getRegRedirectUrl() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "ldapCredentials" ) && settings.getAdminPassword() != null )
+ {
+ parameter.setValue( settings.getAdminPassword() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "ldapPort" ) )
+ {
+ parameter.setValue( String.valueOf( settings.getLdapPort() ) );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "ldapBaseDn" ) )
+ {
+ parameter.setValue( ldapBaseDn );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "ldapHost" ) )
+ {
+ parameter.setValue( ldapHost );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMS configuration init parameters
+ // ---------------------------------------------------------------
+
+ else if ( parameter.getName().equals( "smsAccountName" ) && settings.getSmsAccountName() != null )
+ {
+ parameter.setValue( settings.getSmsAccountName() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "smsPassword" ) && settings.getSmsPassword() != null )
+ {
+ parameter.setValue( settings.getSmsPassword() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "smsTransportUrl" ) && settings.getSmsTransportUrl() != null )
+ {
+ parameter.setValue( settings.getSmsTransportUrl() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "smsUsername" ) && settings.getSmsUsername() != null )
+ {
+ parameter.setValue( settings.getSmsUsername() );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMTP configuration init parameters
+ // ---------------------------------------------------------------
+
+ else if ( parameter.getName().equals( "smtpFrom" ) && settings.getSmtpFrom() != null )
+ {
+ parameter.setValue( settings.getSmtpFrom() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "smtpSubject" ) && settings.getSmtpSubject() != null )
+ {
+ parameter.setValue( settings.getSmtpSubject() );
+ hasChanged = true;
+ }
+
+ else if ( parameter.getName().equals( "smtpHost" ) && settings.getSmtpHost() != null )
+ {
+ parameter.setValue( settings.getSmtpHost() );
+ hasChanged = true;
+ }
+
+ // @todo some issues here: below will add these parameters even if they exist
+ // we need a lookup to see if the parameter exists then need to create it
+ if ( settings.isSmtpAuthenticate() &&
+ settings.getSmtpUsername() != null &&
+ settings.getSmtpPassword() != null )
+ {
+ if ( parameter.getName().equals( "smtpUsername" ) )
+ {
+ parameter.setValue( settings.getSmtpUsername() );
+ }
+// else
+// {
+// webconfig.addContextParameter( "smtpUsername", settings.getSmtpUsername() );
+// }
+
+ if ( parameter.getName().equals( "smtpPassword" ) )
+ {
+ parameter.setValue( settings.getSmtpPassword() );
+ }
+// else
+// {
+// webconfig.addContextParameter( "smtpPassword", settings.getSmtpPassword() );
+// }
+
+ hasChanged = true;
+ }
+ else
+ {
+ // check for the presence of init parameters here and if present delete them
+ }
+ }
+
+ for ( Iterator ii = webconfig.getServletConfigurations(); ii.hasNext(); /****/ )
+ {
+ ServletConfiguration sconf = ( ServletConfiguration ) ii.next();
+
+ if ( sconf.hasInitParameter( "realm" ) && settings.getPrimaryRealmName() != null )
+ {
+ sconf.setInitParameterValue( "realm", settings.getPrimaryRealmName().toUpperCase() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "presentationBaseUrl" ) && settings.getPresentationBaseUrl() != null )
+ {
+ sconf.setInitParameterValue( "presentationBaseUrl", settings.getPresentationBaseUrl() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "redirectUrl" ) && settings.getRegRedirectUrl() != null )
+ {
+ sconf.setInitParameterValue( "redirectUrl", settings.getRegRedirectUrl() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "ldapCredentials" ) && settings.getAdminPassword() != null )
+ {
+ sconf.setInitParameterValue( "ldapCredentials", settings.getAdminPassword() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "ldapPort" ) )
+ {
+ sconf.setInitParameterValue( "ldapPort", String.valueOf( settings.getLdapPort() ) );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "ldapBaseDn" ) )
+ {
+ sconf.setInitParameterValue( "ldapBaseDn", ldapBaseDn );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "ldapHost" ) )
+ {
+ sconf.setInitParameterValue( "ldapHost", ldapHost );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMS configuration init parameters
+ // ---------------------------------------------------------------
+
+ if ( sconf.hasInitParameter( "smsAccountName" ) && settings.getSmsAccountName() != null )
+ {
+ sconf.setInitParameterValue( "smsAccountName", settings.getSmsAccountName() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "smsPassword" ) && settings.getSmsPassword() != null )
+ {
+ sconf.setInitParameterValue( "smsPassword", settings.getSmsPassword() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "smsTransportUrl" ) && settings.getSmsTransportUrl() != null )
+ {
+ sconf.setInitParameterValue( "smsTransportUrl", settings.getSmsTransportUrl() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "smsUsername" ) && settings.getSmsUsername() != null )
+ {
+ sconf.setInitParameterValue( "smsUsername", settings.getSmsUsername() );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMTP configuration init parameters
+ // ---------------------------------------------------------------
+
+ if ( sconf.hasInitParameter( "smtpFrom" ) && settings.getSmtpFrom() != null )
+ {
+ sconf.setInitParameterValue( "smtpFrom", settings.getSmtpFrom() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "smtpSubject" ) && settings.getSmtpSubject() != null )
+ {
+ sconf.setInitParameterValue( "smtpSubject", settings.getSmtpSubject() );
+ hasChanged = true;
+ }
+
+ if ( sconf.hasInitParameter( "smtpHost" ) && settings.getSmtpHost() != null )
+ {
+ sconf.setInitParameterValue( "smtpHost", settings.getSmtpHost() );
+ hasChanged = true;
+ }
+
+ if ( settings.isSmtpAuthenticate() &&
+ settings.getSmtpUsername() != null &&
+ settings.getSmtpPassword() != null )
+ {
+ if ( sconf.hasInitParameter( "smtpUsername" ) )
+ {
+ sconf.setInitParameterValue( "smtpUsername", settings.getSmtpUsername() );
+ }
+ else
+ {
+ sconf.addInitParameter( "smtpUsername", settings.getSmtpUsername() );
+ }
+
+ if ( sconf.hasInitParameter( "smtpPassword" ) )
+ {
+ sconf.setInitParameterValue( "smtpPassword", settings.getSmtpPassword() );
+ }
+ else
+ {
+ sconf.addInitParameter( "smtpPassword", settings.getSmtpPassword() );
+ }
+
+ hasChanged = true;
+ }
+ else
+ {
+ // check for the presence of init parameters here and if present delete them
+ }
+ }
+
+ for ( Iterator ii = webconfig.getFilterConfigurations(); ii.hasNext(); /****/ )
+ {
+ FilterConfiguration fconf = ( FilterConfiguration ) ii.next();
+
+ if ( fconf.hasInitParameter( "presentationBaseUrl" ) && settings.getPresentationBaseUrl() != null )
+ {
+ fconf.setInitParameterValue( "presentationBaseUrl", settings.getPresentationBaseUrl() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "redirectUrl" ) && settings.getRegRedirectUrl() != null )
+ {
+ fconf.setInitParameterValue( "redirectUrl", settings.getRegRedirectUrl() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "ldapCredentials" ) && settings.getAdminPassword() != null )
+ {
+ fconf.setInitParameterValue( "ldapCredentials", settings.getAdminPassword() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "ldapPort" ) )
+ {
+ fconf.setInitParameterValue( "ldapPort", String.valueOf( settings.getLdapPort() ) );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "ldapBaseDn" ) )
+ {
+ fconf.setInitParameterValue( "ldapBaseDn", ldapBaseDn );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "ldapHost" ) )
+ {
+ fconf.setInitParameterValue( "ldapHost", ldapHost );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMS configuration init parameters
+ // ---------------------------------------------------------------
+
+ if ( fconf.hasInitParameter( "smsAccountName" ) && settings.getSmsAccountName() != null )
+ {
+ fconf.setInitParameterValue( "smsAccountName", settings.getSmsAccountName() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "smsPassword" ) && settings.getSmsPassword() != null )
+ {
+ fconf.setInitParameterValue( "smsPassword", settings.getSmsPassword() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "smsTransportUrl" ) && settings.getSmsTransportUrl() != null )
+ {
+ fconf.setInitParameterValue( "smsTransportUrl", settings.getSmsTransportUrl() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "smsUsername" ) && settings.getSmsUsername() != null )
+ {
+ fconf.setInitParameterValue( "smsUsername", settings.getSmsUsername() );
+ hasChanged = true;
+ }
+
+ // ---------------------------------------------------------------
+ // Handle setup of SMTP configuration init parameters
+ // ---------------------------------------------------------------
+
+ if ( fconf.hasInitParameter( "smtpFrom" ) && settings.getSmtpFrom() != null )
+ {
+ fconf.setInitParameterValue( "smtpFrom", settings.getSmtpFrom() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "smtpSubject" ) && settings.getSmtpSubject() != null )
+ {
+ fconf.setInitParameterValue( "smtpSubject", settings.getSmtpSubject() );
+ hasChanged = true;
+ }
+
+ if ( fconf.hasInitParameter( "smtpHost" ) && settings.getSmtpHost() != null )
+ {
+ fconf.setInitParameterValue( "smtpHost", settings.getSmtpHost() );
+ hasChanged = true;
+ }
+
+ if ( settings.isSmtpAuthenticate() &&
+ settings.getSmtpUsername() != null &&
+ settings.getSmtpPassword() != null )
+ {
+ if ( fconf.hasInitParameter( "smtpUsername" ) )
+ {
+ fconf.setInitParameterValue( "smtpUsername", settings.getSmtpUsername() );
+ }
+ else
+ {
+ fconf.addInitParameter( "smtpUsername", settings.getSmtpUsername() );
+ }
+
+ if ( fconf.hasInitParameter( "smtpPassword" ) )
+ {
+ fconf.setInitParameterValue( "smtpPassword", settings.getSmtpPassword() );
+ }
+ else
+ {
+ fconf.addInitParameter( "smtpPassword", settings.getSmtpPassword() );
+ }
+
+ hasChanged = true;
+ }
+ else
+ {
+ // check for the presence of init parameters here and if present delete them
+ }
+ }
+
+ if ( hasChanged )
+ {
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ format.setTrimText( false );
+ XmlUtils.writeDocument( webconfig.getDocument(), webXml, format );
+ }
+ }
+
+
+ public static void alterLdifFile( String suffix, String realm, File ldifFile ) throws Exception
+ {
+ List entries = new ArrayList();
+ LdifReader reader = new LdifReader();
+ List entryList = reader.parseLdifFile( ldifFile.getAbsolutePath() );
+ for ( int ii = 0; ii < entryList.size(); ii++ )
+ {
+ Entry entry = ( Entry ) entryList.get( ii );
+ Attributes attrs = entry.getAttributes();
+
+ // old legacy stuff expecting DN in attributes
+ attrs.put( "dn", entry.getDn() );
+ entries.add( alter( suffix, realm, attrs ) );
+ }
+
+ FileWriter out = new FileWriter( ldifFile );
+ for ( int ii = 0; ii < entries.size(); ii++ )
+ {
+ Attributes attrs = ( Attributes ) entries.get( ii );
+ String dn = ( String ) attrs.remove( "dn" ).get();
+ String ldif = getEntryLdif( dn, attrs );
+ out.write( ldif );
+ }
+ out.flush();
+ out.close();
+ }
+
+
+ public static String getEntryLdif( String dn, Attributes attrs ) throws NamingException
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "dn: " ).append( dn ).append( "\n" );
+
+ for ( NamingEnumeration ids = attrs.getIDs(); ids.hasMore(); /****/ )
+ {
+ String id = ( String ) ids.next();
+ Attribute attr = attrs.get( id );
+
+ for ( int ii = 0; ii < attr.size(); ii++ )
+ {
+ Object value = attr.get( ii );
+
+ if ( value instanceof String )
+ {
+ buf.append( id ).append( ": " ).append( value ).append( "\n" );
+ }
+ else
+ {
+ value = new String ( Base64.encode( ( byte[] ) value ) );
+ buf.append( id ).append( ":: " ).append( value ).append( "\n" );
+ }
+ }
+ }
+
+ buf.append( "\n" );
+ return buf.toString();
+ }
+
+
+ public static Attributes alter( String suffix, String realm, Attributes attrs ) throws NamingException
+ {
+ String realmLowerCase = realm.toLowerCase();
+ String realmUpperCase = realm.toUpperCase();
+
+ for ( NamingEnumeration ids = attrs.getIDs(); ids.hasMore(); /****/ )
+ {
+ String id = ( String ) ids.next();
+ Attribute attr = attrs.remove( id );
+
+ if ( id.equalsIgnoreCase( "dn" ) )
+ {
+ String dn = ( String ) attr.get();
+ dn = dn.replaceAll( "dc=example,.*dc=com", suffix );
+ attrs.put( "dn", dn );
+ }
+ else if ( id.equalsIgnoreCase( "krb5PrincipalName" ) )
+ {
+ String pname = ( String ) attr.get();
+ pname = pname.replaceAll( "EXAMPLE\\.COM", realmUpperCase );
+ pname = pname.replaceAll( "example\\.com", realmLowerCase );
+ attrs.put( "krb5PrincipalName", pname );
+ }
+ else if ( id.equalsIgnoreCase( "mail" ) )
+ {
+ String mail = ( String ) attr.get();
+ mail = mail.replaceAll( "example\\.com", realmLowerCase );
+ attrs.put( "mail", mail );
+ }
+ else if ( id.equalsIgnoreCase( "prescriptiveACI" ) )
+ {
+ String prescriptiveACI = ( String ) attr.get();
+ prescriptiveACI = prescriptiveACI.replaceAll( "dc=example,.*dc=com", suffix );
+ attrs.put( "prescriptiveACI", prescriptiveACI );
+ }
+ else if ( id.equalsIgnoreCase( "safehausRealm" ) )
+ {
+ attrs.put( "safehausRealm", realm.toUpperCase() );
+ }
+ else
+ {
+ attrs.put( attr );
+ }
+ }
+ return attrs;
+ }
+
+
+ public static void setAdminPassword( MutableTriplesecStartupConfiguration config, File wkDir, String newPassword )
+ throws Exception
+ {
+ // Build the environment and set the working directory
+ Hashtable env = new Hashtable();
+ env.put( "java.naming.factory.initial", "org.apache.directory.server.core.jndi.CoreContextFactory" );
+ env.put( "java.naming.provider.url", "ou=system" );
+ env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+ env.put( "java.naming.security.credentials", "secret" );
+ env.put( "java.naming.security.authentication", "simple" );
+ config.setWorkingDirectory( wkDir );
+ env.putAll( config.toJndiEnvironment() );
+
+ // Fire up the server without services and set the admin user password
+ InitialDirContext ctx = new InitialDirContext( env );
+ ctx.modifyAttributes( "uid=admin", DirContext.REPLACE_ATTRIBUTE, new BasicAttributes( "userPassword",
+ newPassword, true ) );
+ ctx.close();
+
+ // Synch the database to persist changes
+ SyncConfiguration syncConfig = new SyncConfiguration();
+ env.putAll( syncConfig.toJndiEnvironment() );
+ env.put( "java.naming.security.credentials", newPassword );
+ ctx = new InitialDirContext( env );
+ ctx.close();
+
+ // Shutdown the database
+ env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
+ ctx = new InitialDirContext( env );
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecPropBuilder.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecPropBuilder.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecPropBuilder.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/util/TriplesecPropBuilder.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.util;
+
+
+import java.util.Properties;
+
+import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.safehaus.triplesec.configui.model.TriplesecConfigSettings;
+
+
+/**
+ * Used to build the server's properties from configuration settings filled in by a wizard.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class TriplesecPropBuilder
+{
+ public Properties build( TriplesecConfigSettings settings )
+ {
+ Properties props = getDefault();
+
+ /*
+ * Alter the properties here according to new config settings
+ */
+ // variables reused all over
+ String password = settings.getAdminPassword();
+ String realm = settings.getPrimaryRealmName();
+ String baseDn = NamespaceTools.inferLdapName( settings.getPrimaryRealmName() );
+ baseDn = baseDn.toLowerCase();
+
+ props.put( "java.naming.security.credentials", password );
+ props.put( "kdc.java.naming.security.credentials", password );
+ props.put( "changepw.java.naming.security.credentials", password );
+
+ props.put( "java.naming.provider.url", baseDn );
+ props.put( "kdc.primary.realm", realm.toUpperCase() );
+ props.put( "kdc.principal", "krbtgt/" + realm + "@" + realm.toUpperCase() );
+ props.put( "kdc.entryBaseDn", "ou=users," + baseDn );
+ props.put( "changepw.entryBaseDn", "ou=users," + baseDn );
+ props.put( "changepw.principal", "kadmin/changepw@" + realm.toUpperCase() );
+
+ props.put( "kdc.allowable.clockskew", String.valueOf( settings.getClockSkew() ) );
+ props.put( "safehaus.entry.basedn", "ou=Users," + baseDn );
+ props.put( "safehaus.load.testdata", String.valueOf( settings.isEnableDemo() ) );
+
+ props.put( "kdc.tgs.maximum.ticket.lifetime", String.valueOf( settings.getTicketLifetime() ) );
+ props.put( "kdc.tgs.maximum.renewable.lifetime", String.valueOf( settings.getRenewableLifetime() ) );
+
+ return props;
+ }
+
+
+ public Properties getDefault()
+ {
+ Properties props = new Properties();
+ props.put( "java.naming.security.authentication", "simple" );
+ props.put( "java.naming.security.principal", "uid=admin,ou=system" );
+ props.put( "java.naming.security.credentials", "secret" );
+ props.put( "java.naming.provider.url", "dc=example,dc=com" );
+ props.put( "java.naming.factory.state", "org.safehaus.triplesec.store.ProfileStateFactory" );
+ props.put( "java.naming.factory.object", "org.safehaus.triplesec.store.ProfileObjectFactory" );
+ props.put( "kdc.primary.realm", "EXAMPLE.COM" );
+ props.put( "kdc.principal", "krbtgt/EXAMPLE.COM@EXAMPLE.COM" );
+ props.put( "kdc.encryption.types", "des-cbc-md5 des3-cbc-sha1 des3-cbc-md5 des-cbc-md4 des-cbc-crc" );
+ props.put( "kdc.entryBaseDn", "ou=users,dc=example,dc=com" );
+ props.put( "kdc.java.naming.security.credentials", "secret" );
+ props.put( "changepw.entryBaseDn", "ou=users,dc=example,dc=com" );
+ props.put( "changepw.java.naming.security.credentials", "secret" );
+ props.put( "changepw.principal", "kadmin/changepw@EXAMPLE.COM" );
+ props.put( "kdc.allowable.clockskew", "5" );
+
+ props.put( "kdc.tgs.maximum.ticket.lifetime", "1440" );
+ props.put( "kdc.tgs.maximum.renewable.lifetime", "10080" );
+ props.put( "kdc.pa.enc.timestamp.required", "true" );
+ props.put( "kdc.tgs.empty.addresses.allowed", "true" );
+ props.put( "kdc.tgs.forwardable.allowed", "true" );
+ props.put( "kdc.tgs.proxiable.allowed", "true" );
+ props.put( "kdc.tgs.postdate.allowed", "true" );
+ props.put( "kdc.tgs.renewable.allowed", "true" );
+
+ props.put( "safehaus.entry.basedn", "ou=Users,dc=example,dc=com" );
+ props.put( "safehaus.load.testdata", "true" );
+ props.put( "kerberos.sam.type.7", "org.safehaus.triplesec.verifier.hotp.DefaultHotpSamVerifier" );
+ return props;
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigApplication.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigApplication.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigApplication.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigApplication.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view;
+
+
+import wicket.protocol.http.WebApplication;
+import org.safehaus.triplesec.configui.view.pages.WizardPage;
+
+public class TriplesecConfigApplication extends WebApplication
+{
+ public Class getHomePage()
+ {
+ return WizardPage.class;
+ }
+
+ protected void init() {
+ getMarkupSettings().setStripWicketTags(true);
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigWizard.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigWizard.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigWizard.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/TriplesecConfigWizard.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view;
+
+import wicket.examples.wizard.ezwizard.impl.Wizard;
+import wicket.examples.wizard.ezwizard.impl.WizardTransition;
+import wicket.examples.wizard.ezwizard.intf.IWizardStep;
+import wicket.util.string.Strings;
+import org.safehaus.triplesec.configui.model.TriplesecConfigSettings;
+import org.safehaus.triplesec.configui.util.CertificateUtil;
+
+import java.io.File;
+
+/**
+ * This class defines the configuration wizard of the TripleSec
+ * server.
+ */
+public class TriplesecConfigWizard extends Wizard {
+ // Raw model so wizard can query it to find out model status
+ private TriplesecConfigSettings model;
+
+ // Friendly indices in the array of wizard panels
+ public static int STEP_INTRO = 0;
+ public static int STEP_REALM = 1;
+ public static int STEP_LDAP = 2;
+ public static int STEP_LDAPS = 3;
+ public static int STEP_SMS = 4;
+ public static int STEP_SMTP = 5;
+ public static int STEP_USER = 6;
+ public static int STEP_ADMIN = 7;
+ public static int STEP_DEMO = 8;
+ public static int STEP_FINISH = 9;
+
+ public static String NO_CERT_PATH_ERR =
+ "Certificate path required when Secure LDAP is enabled.";
+ public static String NO_CERT_PSWD_ERR =
+ "Certificate password required when Secure LDAP is enabled";
+ public static String BAD_CERT_PATH_ERR =
+ "Failed to create certificate file: ";
+ public static String NO_SMTP_USERNAME =
+ "SMTP Account username required when SMTP authentication enabled";
+ public static String NO_SMTP_PASSWORD =
+ "SMPT Account password required when SMTP authentication enabled";
+ public static String ADMIN_PSWD_MISMATCH =
+ "Must provide admin password that match";
+ public static String NO_SMS_PSWD =
+ "Password required for SMS configuration";
+ /**
+ * Constructs a TripleSec configuration wizard.
+ */
+ public TriplesecConfigWizard(
+ final TriplesecConfigSettings model,
+ IWizardStep[] wizardSteps) {
+
+ // Store a reference to the model, so steps and transitions
+ // can use it.
+ this.model = model;
+
+ // set a reference to this master controller in each wizard
+ // step, so steps can refer to common wizard data -- like model
+ for (int i = 0; i < wizardSteps.length; i++) {
+ wizardSteps[i].setOwner(this);
+ }
+
+ // Start wizard from the INTRO node. The fact that steps are
+ // defined in an array does not imply the wizard flow sequence.
+ // Sequence is controlled by transition objects.
+ sourceState = wizardSteps[STEP_INTRO];
+
+ // Set the current state to source node...
+ currentState = sourceState;
+
+ // wizard steps and transitions...
+ wizardSteps[STEP_INTRO].addOutgoingTransition(
+ new WizardTransition(this, "INTRO to REALM", wizardSteps[STEP_REALM]) {
+ // no validation needed for this transition
+ public boolean validate() {
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_REALM].addOutgoingTransition(
+ new WizardTransition(this, "REALM TO LDAP", wizardSteps[STEP_LDAP]) {
+ public boolean validate() {
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_LDAP].addOutgoingTransition(
+ new WizardTransition(this, "LDAP TO LDAPS", wizardSteps[STEP_LDAPS]) {
+ public boolean validate() {
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_LDAPS].addOutgoingTransition(
+ new WizardTransition(this, "LDAPS TO SMS", wizardSteps[STEP_SMS]) {
+ public boolean validate()
+ {
+ String certPath = model.getLdapCertFilePath();
+ String certPswd = model.getLdapCertPassword();
+ if ( model.isEnableLdaps() )
+ {
+ // No certificate path...
+ if ( Strings.isEmpty( certPath ) )
+ {
+ errors.put( "noCertPath", NO_CERT_PATH_ERR );
+ return false;
+ }
+ // No certificate password
+ if ( Strings.isEmpty( certPswd ) )
+ {
+ errors.put( "noCertPswd", NO_CERT_PSWD_ERR );
+ return false;
+ }
+ // Invalid certificate path...
+ File certFile = new File( certPath );
+ if ( !certFile.exists() )
+ {
+ try
+ {
+ CertificateUtil.create( certFile, model );
+ }
+ catch ( Exception e )
+ {
+ errors.put("badCertPath",
+ BAD_CERT_PATH_ERR + certFile.getAbsolutePath() );
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_SMS].addOutgoingTransition(
+ new WizardTransition(this, "SMS TO SMTP", wizardSteps[STEP_SMTP]) {
+ public boolean validate() {
+ if ( Strings.isEmpty( model.getSmsPassword() ) )
+ {
+ errors.put( "noSmsPswd", NO_SMS_PSWD );
+ return false;
+ }
+ if ( Strings.isEmpty( model.getSmsUsername() ) )
+ {
+ errors.put( "noSmsUsername", "An SMS account username is required." );
+ }
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_SMTP].addOutgoingTransition(
+ new WizardTransition(this, "SMTP TO USER", wizardSteps[STEP_USER]) {
+ public boolean validate() {
+ if ( model.isSmtpAuthenticate() ) {
+ // No SMTP username
+ if ( Strings.isEmpty( model.getSmtpUsername() ) )
+ {
+ errors.put( "noSmtpUser", NO_SMTP_USERNAME );
+ return false;
+ }
+ if ( Strings.isEmpty( model.getSmtpPassword() ) )
+ {
+ errors.put( "noSmtpPswd", NO_SMTP_PASSWORD );
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_USER].addOutgoingTransition(
+ new WizardTransition(this, "USER TO ADMIN", wizardSteps[STEP_ADMIN]) {
+ public boolean validate() {
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_ADMIN].addOutgoingTransition(
+ new WizardTransition(this, "ADMIN TO DEMO", wizardSteps[STEP_DEMO]) {
+ public boolean validate() {
+ if ( Strings.isEmpty( model.getAdminPassword() ) )
+ {
+ errors.put("badAdminPswd", ADMIN_PSWD_MISMATCH);
+ return false;
+ }
+ if ( Strings.isEmpty( model.getAdminPassword2() ) )
+ {
+ errors.put("badAdminPswd", ADMIN_PSWD_MISMATCH);
+ return false;
+ }
+ if ( !model.getAdminPassword().equals( model.getAdminPassword2() ) )
+ {
+ errors.put("badAdminPswd", ADMIN_PSWD_MISMATCH);
+ return false;
+ }
+ return true;
+ }
+ }
+ );
+ wizardSteps[STEP_DEMO].addOutgoingTransition(
+ new WizardTransition(this, "DEMO TO FINISH", wizardSteps[STEP_FINISH]) {
+ public boolean validate() {
+ return true;
+ }
+ }
+ );
+ }
+
+ /**
+ * Returns the raw model bean for the TripleSec configuration wizard.
+ */
+ public TriplesecConfigSettings getModel() {
+ return model;
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/AppPageBorder.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/AppPageBorder.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/AppPageBorder.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/AppPageBorder.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.borders;
+
+
+import wicket.markup.html.border.Border;
+import wicket.model.IModel;
+
+
+public class AppPageBorder extends Border
+{
+ private static final long serialVersionUID = 1L;
+
+
+ public AppPageBorder( String id )
+ {
+ this( id, null );
+ }
+
+
+ public AppPageBorder( String id, IModel model )
+ {
+ super( id, model );
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/WizardPanelBorder.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/WizardPanelBorder.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/WizardPanelBorder.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/borders/WizardPanelBorder.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.borders;
+
+
+import wicket.markup.html.border.Border;
+import wicket.markup.html.basic.Label;
+import wicket.model.IModel;
+
+
+public class WizardPanelBorder extends Border
+{
+ private static final long serialVersionUID = -2684017282683778591L;
+
+
+ public WizardPanelBorder( String id, IModel titleModel )
+ {
+ super( id );
+
+ // add the panel title to the panel border...
+ add( new Label( "title", titleModel ) );
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/BasePage.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/BasePage.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/BasePage.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/BasePage.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.pages;
+
+import wicket.markup.html.WebPage;
+import wicket.markup.html.border.Border;
+import org.safehaus.triplesec.configui.view.borders.AppPageBorder;
+
+public abstract class BasePage extends WebPage
+{
+ private static final long serialVersionUID = -2684017282683778591L;
+
+ public BasePage()
+ {
+ // create border and add it to the page
+ Border border = new AppPageBorder("border");
+ border.setTransparentResolver(true);
+ super.add(border);
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/WizardPage.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/WizardPage.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/WizardPage.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/pages/WizardPage.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.pages;
+
+
+import org.safehaus.triplesec.configui.view.TriplesecConfigWizard;
+import org.safehaus.triplesec.configui.view.panels.*;
+import org.safehaus.triplesec.configui.model.TriplesecConfigSettings;
+import wicket.model.IModel;
+import wicket.model.CompoundPropertyModel;
+import wicket.protocol.http.WebApplication;
+
+import java.io.File;
+
+
+/**
+ * Page that contains all the panels that represent the app's wizard steps.
+ */
+public class WizardPage extends BasePage
+{
+ private static final long serialVersionUID = 1L;
+
+ private TriplesecConfigWizard wizard;
+
+ // array of wizard panels
+ WizardPanel[] wizardPanels = new WizardPanel[10];
+
+
+ public WizardPage()
+ {
+ // always turn versioning off...
+ setVersioned( false );
+
+ // raw wizard model is just a javabean
+ TriplesecConfigSettings rawModel = new TriplesecConfigSettings();
+
+ // set the default value for the LDAP cert file path...
+ WebApplication application = ( WebApplication ) this.getApplication();
+ File configDir = new File( application.getWicketServlet().getServletContext().getRealPath( "" ) );
+ File sslDir = new File( new File( configDir.getParentFile().getParentFile(), "var" ), "ssl" );
+ File certFile = new File( sslDir, "default.cert" );
+ rawModel.setLdapCertFilePath( certFile.getAbsolutePath() );
+
+ // wrap raw model with IModel so Wicket can work with it
+ IModel wizardModel = new CompoundPropertyModel( rawModel );
+
+ // Each panel is a wizard step. Initialization in the loop
+ // cannot be used, because each step defines different model-
+ // related methods, thus all steps have different types.
+ wizardPanels[TriplesecConfigWizard.STEP_INTRO] = new WizardPanelIntro( "wp" + TriplesecConfigWizard.STEP_INTRO,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_REALM] = new WizardPanelRealm( "wp" + TriplesecConfigWizard.STEP_REALM,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_LDAP] = new WizardPanelLdap( "wp" + TriplesecConfigWizard.STEP_LDAP,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_LDAPS] = new WizardPanelSecureLdap( "wp"
+ + TriplesecConfigWizard.STEP_LDAPS, wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_SMS] = new WizardPanelSms( "wp" + TriplesecConfigWizard.STEP_SMS,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_SMTP] = new WizardPanelSmtp( "wp" + TriplesecConfigWizard.STEP_SMTP,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_USER] = new WizardPanelUser( "wp" + TriplesecConfigWizard.STEP_USER,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_ADMIN] = new WizardPanelAdmin( "wp" + TriplesecConfigWizard.STEP_ADMIN,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_DEMO] = new WizardPanelDemo( "wp" + TriplesecConfigWizard.STEP_DEMO,
+ wizardModel );
+ wizardPanels[TriplesecConfigWizard.STEP_FINISH] = new WizardPanelFinish( "wp"
+ + TriplesecConfigWizard.STEP_FINISH, wizardModel );
+
+ // Wizard controller is ok with raw model... also sets reference to
+ // wizard controller in each step
+ wizard = new TriplesecConfigWizard( rawModel, wizardPanels );
+
+ // add all panels to wizard page...
+ for ( int i = 0; i < wizardPanels.length; i++ )
+ {
+ add( wizardPanels[i] );
+ }
+
+ // hide all panels except the first one
+ updatePanels();
+ }
+
+
+ public void onCancel()
+ {
+ wizard = null;
+ updatePanels();
+ }
+
+
+ public boolean onBack()
+ {
+ boolean movedBack = false;
+ if ( wizard != null )
+ {
+ movedBack = wizard.back();
+ }
+ updatePanels();
+ return movedBack;
+ }
+
+
+ public boolean onNext()
+ {
+ boolean movedNext = false;
+ if ( wizard != null )
+ {
+ movedNext = wizard.forward();
+ }
+ updatePanels();
+ return movedNext;
+ }
+
+
+ public void updatePanels()
+ {
+ for ( int i = 0; i < wizardPanels.length; i++ )
+ {
+ wizardPanels[i].setVisible( wizard != null && ( "wp" + i ).equals( wizard.getCurrentStepName() ) );
+ }
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanel.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,349 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+import wicket.markup.html.panel.Panel;
+import wicket.markup.html.panel.FeedbackPanel;
+import wicket.markup.html.form.Form;
+import wicket.markup.html.form.Button;
+import wicket.examples.wizard.ezwizard.intf.IWizardStep;
+import wicket.examples.wizard.ezwizard.intf.IWizardTransition;
+import wicket.examples.wizard.ezwizard.intf.IWizard;
+import wicket.model.IModel;
+import wicket.model.Model;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Iterator;
+
+import org.safehaus.triplesec.configui.view.borders.WizardPanelBorder;
+import org.safehaus.triplesec.configui.view.pages.WizardPage;
+
+/**
+ * Wizard steps are usually derived from a panel, and implement
+ * IWizardStep. Steps usually are panels, so this class should
+ * serve as a base class for any wizard panel.
+ */
+public abstract class WizardPanel extends Panel implements IWizardStep {
+ private Button next;
+ private Button cancel;
+ private Button back;
+
+ /**
+ * Master wizard object -- can be used to access common data
+ */
+ protected IWizard wizard;
+ /**
+ * Outgoing transitions are implemented as an array list for
+ * the easy adding of new transitions.
+ */
+ private ArrayList outgoingTransitions = new ArrayList();
+ /**
+ * Incoming transition.
+ */
+ protected IWizardTransition incomingTransition;
+ /**
+ * The wizard panel's form.
+ */
+ private Form form;
+
+ public WizardPanel( String id, IModel model, String title )
+ {
+ this(id, model, title, false, false);
+ }
+
+ public WizardPanel( String id, IModel model, String title,
+ boolean hideBack, boolean hideNext )
+ {
+ super( id, model );
+
+ // create border and add it to the page
+ WizardPanelBorder border = new WizardPanelBorder( "border", new Model( title ) );
+ border.setTransparentResolver( true );
+ super.add( border );
+
+ // create feedback panel and add it to the panel
+ add( new FeedbackPanel( "feedback" ) );
+
+ // create form and add it to the panel
+ add( form = new Form( "form", model ) );
+
+ // create cancel button and add it to the panel
+ cancel = newCancelButton( "cancel" );
+ cancel.setDefaultFormProcessing( false );
+ form.add( cancel );
+
+ // create back button and add it to the panel
+ back = newBackButton( "back" );
+ if ( hideBack )
+ {
+ back.setVisible(false);
+ }
+ back.setDefaultFormProcessing( false );
+ form.add( back );
+
+ next = newNextButton( "next" );
+ if ( hideNext )
+ {
+ next.setVisible(false);
+ }
+ form.add( next );
+ }
+
+ protected Form newForm( String id, IModel model ) {
+ return new Form( id, model );
+ }
+
+ protected Button newCancelButton( String id ) {
+ return new Button( id )
+ {
+ private static final long serialVersionUID = -2684017282683778591L;
+
+ protected void onSubmit()
+ {
+ getWizardPage().onCancel();
+ }
+ };
+ }
+
+ protected Button newBackButton( String id ) {
+ return new Button( id )
+ {
+ private static final long serialVersionUID = -2684017282683778591L;
+
+ protected void onSubmit()
+ {
+ getWizardPage().onBack();
+ }
+ };
+ }
+
+ protected Button newNextButton( String id ) {
+ return new Button( id )
+ {
+ private static final long serialVersionUID = -2684017282683778591L;
+
+ protected void onSubmit()
+ {
+ boolean success = getWizardPage().onNext();
+ if ( !success )
+ {
+ Map errors = getWizard().getWizardErrors();
+ for ( Iterator iter = errors.values().iterator(); iter.hasNext(); )
+ {
+ form.error( (String) iter.next() );
+ }
+ }
+ }
+ };
+ }
+
+
+ protected void hideButtons()
+ {
+ if ( next != null )
+ {
+ next.setVisible( false );
+ }
+
+ if ( cancel != null )
+ {
+ cancel.setVisible( false );
+ }
+
+ if ( back != null )
+ {
+ back.setVisible( false );
+ }
+ }
+
+ protected Form getForm()
+ {
+ return form;
+ }
+
+ protected WizardPage getWizardPage()
+ {
+ return (WizardPage) this.getPage();
+ }
+
+ /**
+ * Returns array of outgoing transitions in the same order in which
+ * they were added by addOutgoingTransition() method.
+ *
+ * @return array of outgoing transitions, the transition with the most
+ * weight is returned first
+ */
+ public IWizardTransition[] getOutgoingTransitions()
+ {
+ return ( IWizardTransition[] )
+ outgoingTransitions.toArray( new IWizardTransition[0] );
+ }
+
+ /**
+ * Returns a transition which will be chosen if a "next" command
+ * is selected for this node.
+ * <p>
+ * All outbound transitions are validated in the order they were
+ * added to this state. The first valid transition is chosen.
+ *
+ * @return a first valid outgoing transition or null if no valid
+ * transitions found
+ */
+ public IWizardTransition getOutgoingTransition()
+ {
+ IWizardTransition[] edges = this.getOutgoingTransitions();
+ for ( int i = 0; i < edges.length; i++ ) {
+ if ( edges[i].validate() )
+ {
+ return edges[i];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the incoming transition for this state; used
+ * during actual wizard traversal.
+ *
+ * @return incoming transition
+ */
+ public IWizardTransition getIncomingTransition()
+ {
+ return incomingTransition;
+ }
+
+ /**
+ * Sets the incoming transition. Used during forward traversal
+ * to mark the way through the wizard. The incoming transition
+ * is used for backward traversal.
+ *
+ * @param value incoming transition
+ */
+ public void setIncomingTransition(IWizardTransition value)
+ {
+ incomingTransition = value;
+ }
+
+ /**
+ * Adds an outgoing transition. Transitions must be added in the
+ * same order should be validated.
+ *
+ * @param value outgoing transition
+ */
+ public void addOutgoingTransition(IWizardTransition value)
+ {
+ outgoingTransitions.add( value );
+ value.setSource( this );
+ }
+
+ /**
+ * Returns true if this state has been marked as checkpoint. This means
+ * that a wizard cannot return back from this state.
+ *
+ * @return true if this state is a checkpoint
+ */
+ public boolean isCheckpoint()
+ {
+ // checkpoints not supported...
+ return false;
+ }
+
+ /**
+ * Returns the name of this state. Each state must have a unique name..
+ *
+ * @return state name
+ */
+ public String getStateName()
+ {
+ // use Wicket component ID as step name
+ return getId();
+ }
+
+ /**
+ * Returns the wizard, which contains this state as part
+ * of the wizard sequence.
+ *
+ * @return wizard which owns this node
+ */
+ public IWizard getWizard()
+ {
+ return wizard;
+ }
+
+ /**
+ * Verifies that this state is included in the path to the current state.
+ *
+ * @return true if this state is present in the actual path to the current
+ * state, but is not a current state itself; false otherwise.
+ */
+ public boolean isStateInPath()
+ {
+ return (
+ this == wizard.getCurrentStep() ||
+ checkTraverseBack( wizard.getCurrentStep(), this )
+ );
+ }
+
+ /**
+ * Instructs the state to clear all its boolean properties.
+ * Usually called before the properties are about to be set.
+ * <br><br>
+ * The reason for this method is that browsers/HTTP do not notify
+ * server about cleared checkboxes or radiobuttons. So, these values
+ * should be cleared before they are set with client values.
+ * <br><br>
+ * This method is used in Struts; not used in JSF and Wicket.
+ */
+ public void resetBooleans()
+ {
+ /* no-op */
+ }
+
+ /**
+ * Sets master wizard controller for this step.
+ */
+ public void setOwner(IWizard owner)
+ {
+ wizard = owner;
+ }
+
+ /**
+ * Verifies if a state is included in the path to the current state.
+ *
+ * @param startState the state where to start backward traversal
+ * @param searchState the state which we are looking for in the
+ * traversal path
+ * @return true if search node is found in the actual path while
+ * traversing back from start node; false otherwise
+ */
+ private static boolean checkTraverseBack( IWizardStep startState,
+ IWizardStep searchState )
+ {
+
+ IWizardTransition incomingEdge = startState.getIncomingTransition();
+ if ( incomingEdge == null )
+ {
+ return false;
+ }
+ IWizardStep srcState = incomingEdge.getSource();
+ return srcState == searchState || checkTraverseBack( srcState, searchState );
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelAdmin.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelAdmin.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelAdmin.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelAdmin.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+import wicket.model.IModel;
+import wicket.markup.html.form.PasswordTextField;
+
+public class WizardPanelAdmin extends WizardPanel
+{
+ private static final long serialVersionUID = -2684017282683778591L;
+
+ public WizardPanelAdmin( String id, IModel model )
+ {
+ super( id, model, "Admin Password Configuration" );
+
+ getForm().add( new PasswordTextField( "adminPassword" ) );
+ getForm().add( new PasswordTextField( "adminPassword2" ) );
+
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelDemo.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelDemo.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelDemo.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelDemo.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+
+import wicket.markup.html.form.CheckBox;
+import wicket.model.IModel;
+
+
+public class WizardPanelDemo extends WizardPanel
+{
+ private static final long serialVersionUID = 1L;
+
+
+ public WizardPanelDemo( String id, IModel model )
+ {
+ super( id, model, "Demo Accounts Configuration" );
+
+ getForm().add( new CheckBox( "enableDemo" ) );
+
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelFinish.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelFinish.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelFinish.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelFinish.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+
+import java.io.File;
+
+import wicket.model.IModel;
+import wicket.model.Model;
+import wicket.markup.html.form.Button;
+import wicket.markup.html.basic.Label;
+import wicket.protocol.http.WebApplication;
+import wicket.Component;
+
+import org.apache.commons.io.FileUtils;
+import org.safehaus.triplesec.TriplesecInstallationLayout;
+import org.safehaus.triplesec.configui.model.TriplesecConfigSettings;
+import org.safehaus.triplesec.configui.util.TriplesecConfigTool;
+
+
+public class WizardPanelFinish extends WizardPanel
+{
+ private static final long serialVersionUID = 1L;
+ private String message = "Click the Done button to apply settings to the TripleSec server.";
+
+
+ public WizardPanelFinish( String id, IModel model )
+ {
+ super( id, model, "Finished!" );
+ getForm().add( new Label( "message", new Model()
+ {
+ private static final long serialVersionUID = 5029629236706738579L;
+
+ public Object getObject(Component component)
+ {
+ return message;
+ }
+ }
+ ) );
+ }
+
+
+ protected Button newNextButton( String id )
+ {
+ Button done = new Button( id )
+ {
+ private static final long serialVersionUID = -2684017282683778591L;
+
+
+ protected void onSubmit()
+ {
+ WebApplication app = ( WebApplication ) this.getApplication();
+ String realPath = app.getWicketServlet().getServletContext().getRealPath( "" );
+ File configuiDir = new File( realPath );
+ File webappsDir = configuiDir.getParentFile();
+ File installDir = webappsDir.getParentFile();
+ TriplesecInstallationLayout layout = new TriplesecInstallationLayout( installDir );
+ try
+ {
+ TriplesecConfigTool.writeConfiguration( layout, ( TriplesecConfigSettings ) getForm()
+ .getModelObject() );
+ FileUtils.touch( new File( configuiDir, "configured" ) );
+ message = "Triplesec Server will now start automatically...";
+ hideButtons();
+ info( "Server configuration completed." );
+ }
+ catch ( Exception e )
+ {
+ error( e.toString() );
+ }
+ }
+ };
+ done.setModel( new Model( "Done" ) );
+ return done;
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelIntro.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelIntro.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelIntro.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelIntro.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+import wicket.model.IModel;
+
+public class WizardPanelIntro extends WizardPanel
+{
+ private static final long serialVersionUID = 8371966017154004708L;
+
+ public WizardPanelIntro(String id, IModel model)
+ {
+ super( id, model, "Introduction", true, false );
+ }
+}
Added: directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelLdap.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelLdap.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelLdap.java (added)
+++ directory/trunks/triplesec/webapp-config/src/main/java/org/safehaus/triplesec/configui/view/panels/WizardPanelLdap.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+package org.safehaus.triplesec.configui.view.panels;
+
+import wicket.model.IModel;
+import wicket.markup.html.form.CheckBox;
+import wicket.markup.html.form.TextField;
+
+public class WizardPanelLdap extends WizardPanel
+{
+ private static final long serialVersionUID = 370256949857642718L;
+
+ public WizardPanelLdap(String id, IModel model) {
+ super(id, model, "LDAP Configuration");
+
+ getForm().add( new CheckBox( "enableLdap" ) );
+ getForm().add( new TextField( "ldapPort", Integer.class ) );
+ getForm().add( new CheckBox( "allowAnonymousAccess" ) );
+ }
+}