directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbenn...@apache.org
Subject svn commit: r486187 [43/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...
Date Tue, 12 Dec 2006 15:24:14 GMT
Added: directory/trunks/triplesec/webapp-config/src/test/resources/server.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-config/src/test/resources/server.xml?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-config/src/test/resources/server.xml (added)
+++ directory/trunks/triplesec/webapp-config/src/test/resources/server.xml Tue Dec 12 07:23:31 2006
@@ -0,0 +1,250 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
+  "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+  <bean id="environment" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
+    <property name="properties">
+      <props>
+        <prop key="java.naming.security.authentication">simple</prop>
+        <prop key="java.naming.security.principal">uid=admin,ou=system</prop>
+        <prop key="java.naming.security.credentials">secret</prop>
+        <prop key="java.naming.provider.url">dc=example,dc=com</prop>
+        <prop key="java.naming.factory.state">org.safehaus.triplesec.store.ProfileStateFactory</prop>
+        <prop key="java.naming.factory.object">org.safehaus.triplesec.store.ProfileObjectFactory</prop>
+
+        <prop key="kdc.primary.realm">EXAMPLE.COM</prop>
+        <prop key="kdc.principal">krbtgt/EXAMPLE.COM@EXAMPLE.COM</prop>
+        <prop key="kdc.encryption.types">des-cbc-md5 des3-cbc-sha1 des3-cbc-md5 des-cbc-md4 des-cbc-crc</prop>
+        <prop key="kdc.entryBaseDn">ou=users,dc=example,dc=com</prop>
+        <prop key="kdc.java.naming.security.credentials">secret</prop>
+
+        <prop key="changepw.entryBaseDn">ou=users,dc=example,dc=com</prop>
+        <prop key="changepw.java.naming.security.credentials">secret</prop>
+        <prop key="changepw.principal">kadmin/changepw@EXAMPLE.COM</prop>
+
+        <!-- All times are in minutes -->
+        <prop key="kdc.allowable.clockskew">5</prop>
+        <prop key="kdc.tgs.maximum.ticket.lifetime">1440</prop>
+        <prop key="kdc.tgs.maximum.renewable.lifetime">10080</prop>
+        <prop key="kdc.pa.enc.timestamp.required">true</prop>
+        <prop key="kdc.tgs.empty.addresses.allowed">true</prop>
+        <prop key="kdc.tgs.forwardable.allowed">true</prop>
+        <prop key="kdc.tgs.proxiable.allowed">true</prop>
+        <prop key="kdc.tgs.postdate.allowed">true</prop>
+        <prop key="kdc.tgs.renewable.allowed">true</prop>
+
+        <prop key="safehaus.entry.basedn">ou=Users,dc=example,dc=com</prop>
+        <prop key="safehaus.load.testdata">true</prop>
+        <prop key="kerberos.sam.type.7">org.safehaus.triplesec.verifier.hotp.DefaultHotpSamVerifier</prop>
+      </props>
+    </property>
+  </bean>
+
+  <bean id="configuration" class="org.safehaus.triplesec.configuration.MutableTriplesecStartupConfiguration">
+    <property name="workingDirectory"><value>partitions</value></property>
+    <property name="allowAnonymousAccess"><value>false</value></property>
+    <property name="accessControlEnabled"><value>true</value></property>
+    <property name="ldapPort"><value>10389</value></property>
+    <property name="enableKerberos"><value>true</value></property>
+    <property name="enableNtp"><value>false</value></property>
+    <property name="enableChangePassword"><value>true</value></property>
+
+    <!-- Uncomment below to have the server load entries on startup!        -->
+    <!-- ldifDirectory property can point to a relative file, directory or  -->
+    <!-- can point to an absolute path to either using the URL path         -->
+    <!-- notation: i.e. file:///Users/jack/apacheds/ldifs                   -->
+
+    <!-- Entries will optionally be filtered using LdifLoadFilters in the   -->
+    <!-- order specified.  The included Krb5KdcEntryFilter will filter      -->
+    <!-- kerberos principals creating keys for them using their             -->
+    <!-- userPassword attribute if present.                                 -->
+
+    <!-- If missing the Triplesec server will use LDIF files under the conf -->
+    <!-- directory where it has been installed.                             -->
+
+    <!--
+    <property name="ldifDirectory">
+      <value>example.ldif</value>
+    </property>
+    -->
+    <property name="ldifFilters">
+      <list>
+        <bean class="org.apache.directory.server.protocol.shared.store.Krb5KdcEntryFilter"/>
+      </list>
+    </property>
+
+    <property name="activationConfiguration">
+      <bean class="org.safehaus.triplesec.configuration.ActivationConfiguration">
+        <property name="enableDecoyMidlet"><value>true</value></property>
+        <property name="otpLength"><value>6</value></property>
+        <property name="midletNameAttribute"><value>midletNameAttribute</value></property>
+      </bean>  
+    </property>    
+    
+    <property name="smsConfiguration">
+      <bean class="org.safehaus.triplesec.configuration.SmsConfiguration">
+        <property name="smsUsername"><value>hauskeys</value></property>
+        <property name="smsPassword"><value>secret</value></property>
+        <property name="smsAccountName"><value>demo</value></property>
+        <property name="smsTransportUrl"><value>http://www.nbroadcasting.com/customers/messages/Sender.asp</value></property>
+      </bean>  
+    </property>    
+    
+    <property name="smtpConfiguration">
+      <bean class="org.safehaus.triplesec.configuration.SmtpConfiguration">
+        <property name="smtpAuthenticate"><value>false</value></property>
+        <!-- uncomment and set above property if authentication is required by mail server
+             <property name="smtpUsername"><value>hauskeys</value></property>
+             <property name="smtpPassword"><value>secret</value></property>
+             -->
+             <property name="smtpHost"><value>localhost</value></property>
+             <property name="smtpSubject"><value>Triplesec Account Activated</value></property>
+             <property name="smtpFrom"><value>dev@safehaus.org</value></property>
+           </bean>  
+         </property>    
+         
+    <property name="contextPartitionConfigurations">
+      <set>
+        <ref bean="examplePartitionConfiguration"/>
+      </set>
+    </property>
+    <property name="bootstrapSchemas">
+      <set>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.CorbaSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.CoreSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.CosineSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.ApacheSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.CollectiveSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.InetorgpersonSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.JavaSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.Krb5kdcSchema"/>
+        <bean class="org.apache.directory.server.core.schema.bootstrap.SystemSchema"/>
+        <bean class="org.safehaus.triplesec.store.schema.SafehausSchema"/>
+      </set>
+    </property>
+    
+    <property name="extendedOperationHandlers">
+      <list>
+        <bean class="org.apache.directory.server.ldap.support.extended.GracefulShutdownHandler"/>
+        <bean class="org.apache.directory.server.ldap.support.extended.LaunchDiagnosticUiHandler"/>
+      </list>
+    </property>  
+
+    <property name="interceptorConfigurations">
+      <list>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>normalizationService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.normalization.NormalizationService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>authenticationService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.authn.AuthenticationService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>referralService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.referral.ReferralService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>authorizationService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.authz.AuthorizationService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>defaultAuthorizationService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.authz.DefaultAuthorizationService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>exceptionService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.exception.ExceptionService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>schemaService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.schema.SchemaService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>subentryService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.subtree.SubentryService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>operationalAttributeService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.operational.OperationalAttributeService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>collectiveAttributeService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.collective.CollectiveAttributeService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>eventService</value></property>
+          <property name="interceptor">
+            <bean class="org.apache.directory.server.core.event.EventService" />
+          </property>
+        </bean>
+        <bean class="org.apache.directory.server.core.configuration.MutableInterceptorConfiguration">
+          <property name="name"><value>policyProtectionService</value></property>
+          <property name="interceptor">
+            <bean class="org.safehaus.triplesec.store.interceptor.PolicyProtectionInterceptor" />
+          </property>
+        </bean>
+      </list>
+    </property>
+  </bean>
+  
+  <bean id="examplePartitionConfiguration" class="org.apache.directory.server.core.configuration.MutablePartitionConfiguration">
+    <property name="name"><value>example</value></property>
+    <property name="suffix"><value>dc=example,dc=com</value></property>
+    <property name="indexedAttributes">
+      <set>
+        <value>objectClass</value>
+        <value>ou</value>
+        <value>dc</value>
+        <value>uid</value>
+        <value>profileId</value>
+        <value>roles</value>
+        <value>grants</value>
+        <value>denials</value>
+        <value>krb5PrincipalName</value>
+      </set>
+    </property>
+    <property name="contextEntry">
+      <value>
+        objectClass: top
+        objectClass: domain
+        objectClass: extensibleObject
+        dc: example
+        administrativeRole: accessControlSpecificArea
+        administrativeRole: collectiveAttributeSpecificArea
+      </value>
+    </property>
+  </bean>
+
+  <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
+    <property name="customEditors">
+      <map>
+        <entry key="javax.naming.directory.Attributes">
+          <bean class="org.apache.directory.server.core.configuration.AttributesPropertyEditor"/>
+        </entry>
+      </map>
+   </property>
+  </bean>
+</beans>

Added: directory/trunks/triplesec/webapp-demo/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/pom.xml?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/pom.xml (added)
+++ directory/trunks/triplesec/webapp-demo/pom.xml Tue Dec 12 07:23:31 2006
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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. 
+-->
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.safehaus.triplesec</groupId>
+    <artifactId>build</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>triplesec-webapp-demo</artifactId>
+  <name>Triplesec Webapp Demo (Wicket Based)</name>
+  <packaging>war</packaging>  
+  <build>
+    <finalName>demo</finalName>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>wicket</groupId>
+      <artifactId>wicket-spring</artifactId>
+      <version>1.2-rc3</version>
+    </dependency>
+    <dependency>
+      <groupId>wicket</groupId>
+      <artifactId>wicket-extensions</artifactId>
+      <version>1.2-rc3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <version>10.1.1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>triplesec-jaas</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>triplesec-guardian-ldap</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>servletapi</groupId>
+      <artifactId>servletapi</artifactId>
+      <version>2.3</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.11</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>triplesec-integration</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>triplesec-main</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>nlog4j</artifactId>
+      <version>1.2.25</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>jcharts</groupId>
+      <artifactId>jcharts</artifactId>
+      <version>0.6.0</version>
+    </dependency>
+   <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>3.0.1</version>
+   </dependency>
+  </dependencies>
+  <profiles>
+    <profile>
+      <id>default</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <build>
+        <plugins>
+           <plugin>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                <excludes>
+                  <!-- Do not run this test since it never exists -->
+                  <exclude>**/RunDemoUI.java</exclude>
+				  <!-- Avoid normal integration tests -->
+                  <exclude>**/*ITest.java</exclude>
+                  <exclude>**/*IntegrationTest.java</exclude>
+                </excludes>
+              </configuration>
+            </plugin>
+         </plugins>
+       </build>
+    </profile>
+    <profile>
+      <id>integration</id>
+      <activation>
+        <property><name>integration</name></property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <systemProperties>
+                <property>
+                  <name>org.safehaus.triplesec.integration.resourcesDirectory</name>
+                  <value>${basedir}/src/test/resources</value>
+                </property>
+              </systemProperties>
+              <excludes>
+                <!-- Do not run this test since it never exists -->
+                <exclude>**/RunDemoUI.java</exclude>
+              </excludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>ui</id>
+      <activation>
+        <property><name>ui</name></property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <systemProperties>
+                <property>
+                  <name>org.safehaus.triplesec.integration.resourcesDirectory</name>
+                  <value>${basedir}/src/test/resources</value>
+                </property>
+                <property>
+                  <name>org.safehaus.triplesec.integration.webapps</name>
+                  <value>demo</value>
+                </property>
+                <property>
+                  <name>org.safehaus.triplesec.integration.webappWarBase.demo</name>
+                  <value>${basedir}/target/demo.war</value>
+                </property>
+              </systemProperties>
+              <includes>
+                <include>**/RunDemoUI.java</include>
+              </includes>
+              <excludes>
+                <exclude>**/*Test.java</exclude>
+              </excludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/AccountDao.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/AccountDao.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/AccountDao.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/AccountDao.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,52 @@
+/*
+ *  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.demo.dao;
+
+import org.safehaus.triplesec.demo.model.Account;
+
+import java.util.Iterator;
+
+/**
+ * Interface for retrieving investment accounst from a database.
+ */
+public interface AccountDao
+{
+    /**
+     * @return total number of accounts available
+     */
+    int count();
+
+    /**
+     * @param qp sorting and paging info
+     * @return iterator over accounts
+     */
+    Iterator find( QueryParam qp );
+
+    /**
+     * @param uid user identifier for the account
+     * @return account with matching uid
+     */
+    Account get( String uid );
+
+    /**
+     * @param account to update
+     */
+    void update( Account account );
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/InvestmentsDao.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/InvestmentsDao.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/InvestmentsDao.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/InvestmentsDao.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.demo.dao;
+
+import org.safehaus.triplesec.demo.model.Investments;
+
+public interface InvestmentsDao
+{
+    void build() throws Exception;
+
+    void clean() throws Exception;
+    
+    Investments get( String uid ) throws Exception;
+
+    void insert( Investments investments ) throws Exception;
+
+    void update( Investments investments ) throws Exception;
+
+    void delete( String uid ) throws Exception;
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/QueryParam.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/QueryParam.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/QueryParam.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/QueryParam.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,85 @@
+/*
+ *  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.demo.dao;
+
+/**
+ * Encapsulates the query parameters to be passed to the daos.
+ */
+public class QueryParam
+{
+    private int first;
+    private int count;
+    private String sort;
+    private boolean sortAsc;
+
+    /**
+     * Set to return <tt>count</tt> elements, starting at the
+     * <tt>first</tt> element.
+     *
+     * @param first first element to return
+     * @param count number of elements to return
+     */
+    public QueryParam( int first, int count )
+    {
+        this( first, count, null, true );
+    }
+
+    /**
+     * Set to return <tt>count</tt> sorted elements, starting at the
+     * <tt>first</tt> element.
+     *
+     * @param first first element to return
+     * @param count number of elements to return
+     * @param sort column to sort on
+     * @param sortAsc sort ascending or descending
+     */
+    public QueryParam( int first, int count, String sort, boolean sortAsc )
+    {
+        this.first = first;
+        this.count = count;
+        this.sort = sort;
+        this.sortAsc = sortAsc;
+    }
+
+    public int getFirst()
+    {
+        return first;
+    }
+
+    public int getCount()
+    {
+        return count;
+    }
+
+    public String getSort()
+    {
+        return sort;
+    }
+
+    public boolean isSortAsc()
+    {
+        return sortAsc;
+    }
+
+    public boolean hasSort()
+    {
+        return sort != null;
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/jdbc/JdbcInvestmentsDao.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/jdbc/JdbcInvestmentsDao.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/jdbc/JdbcInvestmentsDao.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/jdbc/JdbcInvestmentsDao.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,147 @@
+/*
+ *  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.demo.dao.jdbc;
+
+import org.safehaus.triplesec.demo.dao.InvestmentsDao;
+import org.safehaus.triplesec.demo.model.Investments;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+public class JdbcInvestmentsDao implements InvestmentsDao
+{
+    private final Connection connection;
+
+
+    public JdbcInvestmentsDao ( Connection c )
+    {
+        connection = c;
+    }
+
+
+    public void clean() throws SQLException
+    {
+        Statement st = null;
+
+        try
+        {
+            st = connection.createStatement();
+            st.execute( "DROP TABLE INVESTMENTS" );
+        }
+        finally
+        {
+            if ( st != null ) { st.close(); }
+        }
+    }
+
+
+    public void build() throws SQLException
+    {
+        Statement st = null;
+
+        try
+        {
+            st = connection.createStatement();
+            st.execute( "CREATE TABLE INVESTMENTS ( UID CHAR(128), BONDS INT, TBILLS INT, EMERGING_MARKETS INT, TECH_STOCKS INT, VOLATILE_HIGH_YIELD INT )" );
+            st.execute( "CREATE UNIQUE INDEX uid_index ON INVESTMENTS ( UID )" );
+        }
+        finally
+        {
+            if ( st != null ) { st.close(); }
+        }
+    }
+
+
+    public Investments get( String uid ) throws SQLException
+    {
+        Investments investments;
+        Statement st = null;
+        ResultSet rs = null;
+
+        try
+        {
+            st = connection.createStatement();
+            rs = st.executeQuery( "SELECT * FROM INVESTMENTS WHERE UID = '" + uid + "'" );
+
+            while( rs.next() )
+            {
+                investments = new Investments( uid );
+                investments.setBonds( rs.getInt( "BONDS" ) );
+                investments.setTbills( rs.getInt( "TBILLS" ) );
+                investments.setEmergingMarkets( rs.getInt( "EMERGING_MARKETS" ) );
+                investments.setTechStocks( rs.getInt( "TECH_STOCKS" ) );
+                investments.setVolatileHighYield( rs.getInt( "VOLATILE_HIGH_YIELD" ) );
+                return investments;
+            }
+        }
+        finally
+        {
+            if ( st != null ) { st.close(); }
+            if ( rs != null ) { rs.close(); }
+        }
+
+        return null;
+    }
+
+
+    public void insert( Investments investments ) throws SQLException
+    {
+        Statement st = null;
+
+        try
+        {
+            st = connection.createStatement();
+            st.execute( "INSERT INTO INVESTMENTS VALUES ( '" + investments.getUid() + "', "
+                    + investments.getBonds() + ", " + investments.getTbills() + ", "
+                    + investments.getEmergingMarkets() + ", " + investments.getTechStocks() + ", "
+                    + investments.getVolatileHighYield() + " ) " );
+        }
+        finally
+        {
+            if ( st != null ) { st.close(); }
+        }
+    }
+
+
+    public void update( Investments investments ) throws SQLException
+    {
+        delete( investments.getUid() );
+        insert( investments );
+    }
+
+
+    public void delete( String uid ) throws SQLException
+    {
+        Statement st = null;
+
+        try
+        {
+            st = connection.createStatement();
+            st.execute( "DELETE FROM INVESTMENTS WHERE UID = '" + uid + "'" );
+        }
+        finally
+        {
+            if ( st != null ) { st.close(); }
+        }
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/mock/MockAccountDao.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/mock/MockAccountDao.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/mock/MockAccountDao.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/dao/mock/MockAccountDao.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,162 @@
+/*
+ *  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.demo.dao.mock;
+
+import org.safehaus.triplesec.demo.dao.AccountDao;
+import org.safehaus.triplesec.demo.dao.QueryParam;
+import org.safehaus.triplesec.demo.model.Account;
+import org.safehaus.triplesec.demo.service.Registry;
+import org.safehaus.triplesec.guardian.ApplicationPolicy;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Comparator;
+
+/**
+ * A Dao implementation with an auto-generated embedded database. In
+ * a true implementation, this Dao would interface with a real database,
+ * but because we want to keep dependencies to a minimum, we generate our
+ * own database here.
+ */
+public class MockAccountDao implements AccountDao
+{
+    private Map map = Collections.synchronizedMap( new HashMap() );
+    private List uidIdx = Collections.synchronizedList( new ArrayList() );
+    private List uidDescIdx = Collections.synchronizedList( new ArrayList() );
+
+    public MockAccountDao()
+    {
+        ApplicationPolicy policy = Registry.policyManager().getAppPolicy();
+        for ( Iterator iter = policy.getProfileIdIterator(); iter.hasNext(); )
+        {
+            add( new Account( (String) iter.next() ) );
+        }
+        updateIndecies();
+    }
+
+    /**
+     * @return total number of accounts available
+     */
+    public int count()
+    {
+        return uidIdx.size();
+    }
+
+    /**
+     * @param qp sorting and paging info
+     * @return iterator over accounts
+     */
+    public Iterator find(QueryParam qp)
+    {
+        List sublist = getIndex( qp.getSort(), qp.isSortAsc() )
+                .subList( qp.getFirst(), qp.getFirst() + qp.getCount() );
+        return sublist.iterator();
+    }
+
+    protected List getIndex( String prop, boolean asc )
+    {
+        if ( prop == null )
+        {
+            return uidIdx;
+        }
+        return (asc) ? uidIdx : uidDescIdx;
+    }
+
+    /**
+     * Find account by user ID.
+     *
+     * @param uid user identifier for the account
+     * @return account with matching uid
+     */
+    public Account get( String uid )
+    {
+        Account accnt = (Account) map.get( uid );
+        if ( accnt == null )
+        {
+            // hmmmmmm... no account found... create one..
+            accnt = new Account( uid );
+            add( accnt );
+            updateIndecies();
+        }
+        return accnt;
+    }
+
+    /**
+     * @param newAccount account to update
+     */
+    public void update( final Account newAccount )
+    {
+        Account oldAccount = get( newAccount.getUid() );
+        delete( oldAccount );
+        save( newAccount );
+    }
+
+    protected void add( final Account account )
+    {
+        map.put( account.getUid(), account );
+        uidIdx.add( account );
+        uidDescIdx.add( account );
+    }
+
+    /**
+     * Add account to the database.
+     *
+     * @param account
+     */
+    public void save( final Account account )
+    {
+        // TODO probably should make sure there's not duplicates
+        add( account );
+        updateIndecies();
+    }
+
+    public void delete( final Account account )
+    {
+        map.remove( account.getUid() );
+
+        uidIdx.remove( account );
+        uidDescIdx.remove( account );
+    }
+
+    private void updateIndecies()
+    {
+        Collections.sort( uidIdx, new Comparator()
+        {
+            public int compare( Object arg0, Object arg1 )
+            {
+                return ( (Account) arg0 ).getUid().compareTo(
+                        ( (Account) arg1 ).getUid() );
+            }
+        });
+
+        Collections.sort( uidDescIdx, new Comparator()
+        {
+            public int compare( Object arg0, Object arg1 )
+            {
+                return ( (Account) arg1 ).getUid().compareTo(
+                        ( (Account) arg0 ).getUid() );
+            }
+        });
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Account.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Account.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Account.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Account.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,231 @@
+/*
+ *  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.demo.model;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+
+public class Account implements Serializable
+{
+    private static final long serialVersionUID = 1316820604362304663L;
+
+    private String uid;
+    private int bonds;
+    private int techStocks;
+    private int volatileHighYield;
+    private int tBills;
+    private int foreign;
+
+    /** a constant unmodifiable list of funds */
+    public static final List FUNDS;
+
+    /** a constant unmodifiable Map of fund indices */
+    public static final Map INDICES;
+
+    static
+    {
+        ArrayList list = new ArrayList( 5 );
+        list.add( "Bonds" );
+        list.add( "T-Bills" );
+        list.add( "Foreign" );
+        list.add( "Tech Stocks" );
+        list.add( "Volatile High Yield" );
+        FUNDS = Collections.unmodifiableList( list );
+        HashMap map = new HashMap( 5 );
+        map.put( list.get( 0 ), new Integer( 0 ) );
+        map.put( list.get( 1 ), new Integer( 1 ) );
+        map.put( list.get( 2 ), new Integer( 2 ) );
+        map.put( list.get( 3 ), new Integer( 3 ) );
+        map.put( list.get( 4 ), new Integer( 4 ) );
+        INDICES = Collections.unmodifiableMap( map );
+    }
+
+    public Account( String uid )
+    {
+        this.uid = uid;
+        this.bonds = rint( 0, 1000 );
+        this.techStocks = rint( 0, 1000 );
+        this.volatileHighYield = rint( 0, 1000 );
+        this.tBills = rint( 0, 1000 );
+        this.foreign  = rint( 0, 1000 );
+    }
+
+    public String getUid()
+    {
+        return uid;
+    }
+
+    public int getBonds()
+    {
+        return bonds;
+    }
+
+    public void setBonds( int bonds )
+    {
+        this.bonds = bonds;
+    }
+
+    public int getTechStocks()
+    {
+        return techStocks;
+    }
+
+    public void setTechStocks( int techStocks )
+    {
+        this.techStocks = techStocks;
+    }
+
+    public int getVolatileHighYield()
+    {
+        return volatileHighYield;
+    }
+
+    public void setVolatileHighYield( int volatileHighYield )
+    {
+        this.volatileHighYield = volatileHighYield;
+    }
+
+    public int getTBills()
+    {
+        return tBills;
+    }
+
+    public void setTBills( int tBills )
+    {
+        this.tBills = tBills;
+    }
+
+    public int getForeign()
+    {
+        return foreign;
+    }
+
+    public void setForeign( int foreign )
+    {
+        this.foreign = foreign;
+    }
+
+    public static int getNumberOfFunds()
+    {
+        return FUNDS.size();
+    }
+
+    public static String getFund( int index )
+    {
+        return (String) FUNDS.get( index );
+    }
+
+    public static int getIndex( String fund )
+    {
+        return ( ( Integer ) INDICES.get( fund ) ).intValue();
+    }
+
+    public void set( int index, int value )
+    {
+        switch ( index )
+        {
+        case( 0 ):
+            setBonds( value );
+            break;
+        case( 1 ):
+            setTBills( value );
+            break;
+        case( 2 ):
+            setForeign( value );
+            break;
+        case( 3 ):
+            setTechStocks( value );
+            break;
+        case( 4 ):
+            setVolatileHighYield( value );
+            break;
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+
+    public int get( int index )
+    {
+        switch ( index )
+        {
+        case( 0 ):
+            return getBonds();
+        case( 1 ):
+            return getTBills();
+        case( 2 ):
+            return getForeign();
+        case( 3 ):
+            return getTechStocks();
+        case( 4 ):
+            return getVolatileHighYield();
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+
+    public void set( String fund, int value )
+    {
+        int index = getIndex( fund );
+
+        switch ( index )
+        {
+        case( 0 ):
+            setBonds( value );
+            break;
+        case( 1 ):
+            setTBills( value );
+            break;
+        case( 2 ):
+            setForeign( value );
+            break;
+        case( 3 ):
+            setTechStocks( value );
+            break;
+        case( 4 ):
+            setVolatileHighYield( value );
+            break;
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+    private int rint( int min, int max )
+    {
+        return (int) ( Math.random() * ( max - min ) + max );
+    }
+
+
+    public String toString() {
+        return "Account{" +
+                "uid='" + uid + '\'' +
+                ", bonds=" + bonds +
+                ", techStocks=" + techStocks +
+                ", volatileHighYield=" + volatileHighYield +
+                ", tBills=" + tBills +
+                ", foreign=" + foreign +
+                '}';
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Investments.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Investments.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Investments.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/model/Investments.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,229 @@
+/*
+ *  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.demo.model;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.io.Serializable;
+
+
+public class Investments implements Serializable
+{
+    private static final long serialVersionUID = 144993312912085394L;
+
+    private final String uid;
+    private int bonds = 10000;
+    private int techStocks = 10000;
+    private int volatileHighYield = 10000;
+    private int tbills = 10000;
+    private int emergingMarkets = 10000;
+
+
+    /** a constant unmodifiable list of funds */
+    public static final List FUNDS;
+
+    /** a constant unmodifiable Map of fund indices */
+    public static final Map INDICES;
+
+
+    static
+    {
+        ArrayList list = new ArrayList( 5 );
+        list.add( "Bonds" );
+        list.add( "T-Bills" );
+        list.add( "Emerging Markets" );
+        list.add( "Tech Stocks" );
+        list.add( "Volatile High Yield" );
+        FUNDS = Collections.unmodifiableList( list );
+        HashMap map = new HashMap( 5 );
+        map.put( list.get( 0 ), new Integer( 0 ) );
+        map.put( list.get( 1 ), new Integer( 1 ) );
+        map.put( list.get( 2 ), new Integer( 2 ) );
+        map.put( list.get( 3 ), new Integer( 3 ) );
+        map.put( list.get( 4 ), new Integer( 4 ) );
+        INDICES = Collections.unmodifiableMap( map );
+    }
+
+
+    public static int getNumberOfFunds()
+    {
+        return FUNDS.size();
+    }
+
+
+    public static String getFund( int index )
+    {
+        return ( String ) FUNDS.get( index );
+    }
+
+
+    public static int getIndex( String fund )
+    {
+        return ( ( Integer ) INDICES.get( fund ) ).intValue();
+    }
+
+
+    public void set( int index, int value )
+    {
+        switch ( index )
+        {
+        case( 0 ):
+            setBonds( value );
+            break;
+        case( 1 ):
+            setTbills( value );
+            break;
+        case( 2 ):
+            setEmergingMarkets( value );
+            break;
+        case( 3 ):
+            setTechStocks( value );
+            break;
+        case( 4 ):
+            setVolatileHighYield( value );
+            break;
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+
+    public int get( int index )
+    {
+        switch ( index )
+        {
+        case( 0 ):
+            return getBonds();
+        case( 1 ):
+            return getTbills();
+        case( 2 ):
+            return getEmergingMarkets();
+        case( 3 ):
+            return getTechStocks();
+        case( 4 ):
+            return getVolatileHighYield();
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+
+    public void set( String fund, int value )
+    {
+        int index = getIndex( fund );
+
+        switch ( index )
+        {
+        case( 0 ):
+            setBonds( value );
+            break;
+        case( 1 ):
+            setTbills( value );
+            break;
+        case( 2 ):
+            setEmergingMarkets( value );
+            break;
+        case( 3 ):
+            setTechStocks( value );
+            break;
+        case( 4 ):
+            setVolatileHighYield( value );
+            break;
+        default:
+            throw new IndexOutOfBoundsException( "Index value out of bounds: " + index );
+        }
+    }
+
+
+    public Investments( String uid )
+    {
+        this.uid = uid;
+    }
+
+
+    public String getUid()
+    {
+        return this.uid;
+    }
+
+
+    public void setBonds( int bonds )
+    {
+        this.bonds = bonds;
+    }
+
+
+    public int getBonds()
+    {
+        return bonds;
+    }
+
+
+    public void setTechStocks( int techStocks )
+    {
+        this.techStocks = techStocks;
+    }
+
+
+    public int getTechStocks()
+    {
+        return techStocks;
+    }
+
+
+    public void setVolatileHighYield( int volatileHighYield )
+    {
+        this.volatileHighYield = volatileHighYield;
+    }
+
+
+    public int getVolatileHighYield()
+    {
+        return volatileHighYield;
+    }
+
+
+    public void setTbills( int tbills )
+    {
+        this.tbills = tbills;
+    }
+
+
+    public int getTbills()
+    {
+        return tbills;
+    }
+
+
+    public void setEmergingMarkets( int emergingMarkets )
+    {
+        this.emergingMarkets = emergingMarkets;
+    }
+
+
+    public int getEmergingMarkets()
+    {
+        return emergingMarkets;
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedPage.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedPage.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedPage.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedPage.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,28 @@
+/*
+ *  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.demo.security;
+
+/**
+ * Simple tagging interface that denotes a web page as requiring
+ * authentication to access.
+ */
+public interface AuthenticatedPage
+{
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedWebSession.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedWebSession.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedWebSession.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/AuthenticatedWebSession.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,144 @@
+/*
+ *  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.demo.security;
+
+import org.safehaus.triplesec.demo.service.Registry;
+import org.safehaus.triplesec.guardian.Profile;
+import org.safehaus.triplesec.jaas.AccountLockedOutException;
+import org.safehaus.triplesec.jaas.PreauthFailedException;
+import org.safehaus.triplesec.jaas.ResynchInProgressException;
+import org.safehaus.triplesec.jaas.ResynchStartingException;
+import org.safehaus.triplesec.jaas.SafehausPrincipal;
+import wicket.protocol.http.WebApplication;
+import wicket.protocol.http.WebSession;
+import wicket.util.string.Strings;
+
+import javax.security.auth.login.LoginException;
+
+/**
+ * Basic authenticated web session.
+ */
+public class AuthenticatedWebSession extends WebSession
+{
+    private static final long serialVersionUID = -6787285847550864854L;
+
+    private String errorMessage = null;
+    private String username;
+    private String password;
+    private SafehausPrincipal principal = null;
+
+    /**
+     * Construct the authenticated web session.
+     *
+     * @param application the web application
+     */
+    public AuthenticatedWebSession(final WebApplication application)
+    {
+        super( application );
+    }
+
+
+    /**
+     * Authenticates this session.
+     *
+     * @param username the username
+     * @param password the password
+     * @param passcode the passcode
+     * @return <b>true</b> if the user was authenticated successfully
+     */
+    public boolean authenticate( String username, String password, String passcode )
+    {
+        this.username = username;
+        if ( Strings.isEmpty( username ) )
+        {
+            errorMessage = "Missing credentials: Username not provided.";
+            principal = null;
+            return isAuthenticated();
+        }
+        this.password = password;
+        if ( Strings.isEmpty( password ) )
+        {
+            errorMessage = "Missing credentials: Password not provided.";
+            principal = null;
+            return isAuthenticated();
+        }
+
+        try
+        {
+            principal = Registry.policyManager().getPrincipal( username,
+                    password, passcode );
+        }
+        catch ( AccountLockedOutException e )
+        {
+            errorMessage = "Account locked for user '" + username + "'!";
+        }
+        catch ( PreauthFailedException e )
+        {
+            errorMessage = "Hotp authentication failed for user '" + username + "'!";
+        }
+        catch ( ResynchInProgressException e )
+        {
+            errorMessage = "User '" + username + "' is still out of sych! Please " +
+                    "enter another consecutive single-use password.";
+        }
+        catch ( ResynchStartingException e )
+        {
+            errorMessage = "User '" + username + "' is out of synch! Initiating " +
+                    "resynch protocol. Enter another consecutive single-use " +
+                    "password.";
+        }
+        catch ( LoginException e )
+        {
+            errorMessage = "User '" + username + "' failed authentication: " +
+                    e.getMessage();
+        }
+        return isAuthenticated();
+    }
+
+
+    public boolean isAuthenticated()
+    {
+        return principal != null;
+    }
+
+
+    public String getErrorMessage()
+    {
+        return errorMessage;
+    }
+
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+
+    public Profile getUserProfile()
+    {
+        return principal != null ? principal.getAuthorizationProfile() : null;
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/PageAuthorizationStrategy.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/PageAuthorizationStrategy.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/PageAuthorizationStrategy.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/security/PageAuthorizationStrategy.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.demo.security;
+
+import wicket.authorization.strategies.page.SimplePageAuthorizationStrategy;
+import wicket.Session;
+
+/**
+ * Implementation of a web page authorization strategy.
+ */
+public class PageAuthorizationStrategy extends SimplePageAuthorizationStrategy
+{
+    public PageAuthorizationStrategy( Class securePageType, Class loginPageClass )
+    {
+        super( securePageType, loginPageClass );
+    }
+
+    protected boolean isAuthorized()
+    {
+        return (((AuthenticatedWebSession) Session.get()).isAuthenticated());
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultPolicyManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultPolicyManager.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultPolicyManager.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultPolicyManager.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,163 @@
+/*
+ *  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.demo.service;
+
+import org.safehaus.triplesec.guardian.ApplicationPolicy;
+import org.safehaus.triplesec.guardian.ApplicationPolicyFactory;
+import org.safehaus.triplesec.jaas.SafehausPrincipal;
+import org.safehaus.triplesec.jaas.RealmCallback;
+import org.safehaus.triplesec.jaas.PolicyCallback;
+import org.safehaus.triplesec.jaas.PasscodeCallback;
+import org.safehaus.triplesec.jaas.SafehausLoginModule;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.spi.LoginModule;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginException;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.IOException;
+
+public class DefaultPolicyManager implements PolicyManager
+{
+    private String realm;
+    private String ldapDriver;
+    private String url;
+    private Properties ldapProperties;
+
+    public ApplicationPolicy getAppPolicy()
+    {
+        try
+        {
+            Class.forName( ldapDriver );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new RuntimeException( e );
+        }
+        return ApplicationPolicyFactory.newInstance( url, ldapProperties );
+    }
+
+    public void setLdapDriver( String ldapDriver )
+    {
+        this.ldapDriver = ldapDriver;
+    }
+
+    public void setUrl( String url )
+    {
+        this.url = url;
+    }
+
+    public void setLdapProperties( Properties ldapProperties )
+    {
+        this.ldapProperties = ldapProperties;
+    }
+
+    public String getRealm()
+    {
+        return realm;
+    }
+
+    public SafehausPrincipal getPrincipal( String userid,
+                                           String password,
+                                           String passcode ) throws LoginException
+    {
+        SafehausPrincipal principal = null;
+        LoginModule module = new SafehausLoginModule();
+        Subject subject = new Subject();
+        Map options = new HashMap();
+        options.put( SafehausLoginModule.ALLOW_ADMIN, "true" );
+        module.initialize( subject,
+                new DemoHandler( userid, password, passcode ),
+                new HashMap(), options );
+        boolean result = module.login();
+        result &= module.commit();
+        if ( result )
+        {
+            Object[] principals = subject.getPrincipals().toArray();
+            if ( principals.length > 0 )
+            {
+                principal = (SafehausPrincipal) principals[0];
+            }
+        }
+        return principal;
+    }
+
+    public void setRealm( String realm )
+    {
+        this.realm = realm;
+    }
+
+    /**
+     * Simple handler implementation for this Demo.
+     */
+    private class DemoHandler implements CallbackHandler
+    {
+        private String userId;
+        private String password;
+        private String passcode;
+
+        public DemoHandler( String userId, String password, String passcode )
+        {
+            this.userId = userId;
+            this.password = password;
+            this.passcode = passcode;
+        }
+
+        public void handle(Callback[] callbacks)
+                throws IOException, UnsupportedCallbackException
+        {
+            for ( int i = 0; i < callbacks.length; i++ )
+            {
+                if ( callbacks[i] instanceof NameCallback )
+                {
+                    NameCallback ncb = ( NameCallback ) callbacks[i];
+                    ncb.setName( userId );
+                }
+                else if ( callbacks[i] instanceof PasswordCallback )
+                {
+                    PasswordCallback pcb = ( PasswordCallback ) callbacks[i];
+                    pcb.setPassword( password.toCharArray() );
+                }
+                else if ( callbacks[i] instanceof RealmCallback )
+                {
+                    RealmCallback rcb = ( RealmCallback ) callbacks[i];
+                    rcb.setRealm( realm.toUpperCase() );
+                }
+                else if ( callbacks[i] instanceof PolicyCallback )
+                {
+                    PolicyCallback pcb = ( PolicyCallback ) callbacks[i];
+                    pcb.setPolicy( getAppPolicy() );
+                }
+                else if ( callbacks[i] instanceof PasscodeCallback )
+                {
+                    PasscodeCallback pcb = ( PasscodeCallback ) callbacks[i];
+                    pcb.setPasscode( passcode );
+                }
+            }
+        }
+    }
+
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultSmsManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultSmsManager.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultSmsManager.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/DefaultSmsManager.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,137 @@
+/*
+ *  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.demo.service;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+public class DefaultSmsManager implements SmsManager {
+    private String smsTransportUrl;
+    private String smsUsername;
+    private String smsPassword;
+    private String smsAccountName;
+    private String wapUrl;
+
+    public void sendSmsMessage( String mobile, String carrier, String username )
+            throws Exception
+    {
+        // Note: we will rely on clients to provide non-null input variables
+        // and just throw RuntimeExceptions if we get a null value
+        if ( mobile == null || carrier == null || username == null )
+        {
+            throw new RuntimeException( "Input variable(s) have illegal NULL values" );
+        }
+
+        // trim mobile number if necessary...
+        if ( mobile.startsWith( "+" ) )
+        {
+            mobile = mobile.substring( 1 );
+        }
+        if ( mobile.startsWith( "1" ) )
+        {
+            mobile = mobile.substring( 1 );
+        }
+        if ( mobile.length() < 10 )
+        {
+            throw new RuntimeException( "Mobile number was less than 10 digits in length" );
+        }
+
+        // build WAP URL
+        StringBuffer buffer = new StringBuffer( wapUrl );
+        if ( ! wapUrl.endsWith("/") )
+        {
+            buffer.append( "/" );
+        }
+        buffer.append( username ).append( ".jar" );
+
+        // set the cellular carrier code
+        int carrierCode = getCarrierCode( carrier );
+
+        // setup HTTP client
+        HttpClient client = new HttpClient();
+        HttpMethod method = new PostMethod( smsTransportUrl );
+        NameValuePair[] params = new NameValuePair[] {
+                new NameValuePair( "Carrier", String.valueOf( carrierCode ) ),
+                new NameValuePair( "UID", smsUsername ),
+                new NameValuePair( "PWD", smsPassword ),
+                new NameValuePair( "Campaign", smsAccountName ),
+                new NameValuePair( "CellNumber", mobile ),
+                new NameValuePair( "msg", buffer.toString() )
+        };
+        method.setQueryString( params );
+        client.executeMethod( method );
+    }
+
+    private int getCarrierCode( String carrier )
+    {
+        int carrierCode = 31004;
+        if ( carrier.equalsIgnoreCase( "AT&T" ) )
+        {
+            carrierCode = 31001;
+        }
+        else if ( carrier.equalsIgnoreCase( "Cingular" ) )
+        {
+            carrierCode = 31002;
+        }
+        else if ( carrier.equalsIgnoreCase( "Verizon" ) )
+        {
+            carrierCode = 31003;
+        }
+        else if ( carrier.equalsIgnoreCase( "T-Mobile" ) )
+        {
+            carrierCode = 31004;
+        }
+        else if ( carrier.equalsIgnoreCase( "Spring" ) )
+        {
+            carrierCode = 31005;
+        }
+        else if ( carrier.equalsIgnoreCase( "Nextel" ) )
+        {
+            carrierCode = 310007;
+        }
+        return carrierCode;
+    }
+    public void setSmsTransportUrl( String smsTransportUrl )
+    {
+        this.smsTransportUrl = smsTransportUrl;
+    }
+
+    public void setSmsUsername( String smsUsername )
+    {
+        this.smsUsername = smsUsername;
+    }
+
+    public void setSmsPassword( String smsPassword )
+    {
+        this.smsPassword = smsPassword;
+    }
+
+    public void setSmsAccountName( String smsAccountName )
+    {
+        this.smsAccountName = smsAccountName;
+    }
+
+    public void setWapUrl(String wapUrl)
+    {
+        this.wapUrl = wapUrl;
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/PolicyManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/PolicyManager.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/PolicyManager.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/PolicyManager.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,38 @@
+/*
+ *  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.demo.service;
+
+import org.safehaus.triplesec.guardian.ApplicationPolicy;
+import org.safehaus.triplesec.jaas.SafehausPrincipal;
+
+import javax.security.auth.login.LoginException;
+import java.util.Properties;
+
+public interface PolicyManager
+{
+    void setUrl( String url );
+    void setLdapProperties( Properties ldapProperties );
+    void setRealm( String realm );
+    ApplicationPolicy getAppPolicy();
+    String getRealm();
+    SafehausPrincipal getPrincipal( String userId,
+                                    String password,
+                                    String passcode ) throws LoginException;
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/Registry.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/Registry.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/Registry.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/Registry.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,90 @@
+/*
+ *  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. 
+ *  
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: tbennett
+ * Date: May 9, 2006
+ * Time: 12:02:48 AM
+ * To change this template use File | Settings | File Templates.
+ */
+package org.safehaus.triplesec.demo.service;
+
+/**
+ * A common place to get business delegates.
+ */
+public class Registry
+{
+    /** Holds the single instance of the registry */
+    private static Registry ourInstance = new Registry();
+
+    /** Management object for security */
+    private PolicyManager policyManager;
+
+    /** Management object for SMS service */
+    private SmsManager smsManager;
+
+    /**
+     * Returns the singleton instance of the Registry. The
+     * Registry must be initialized using setter methods before
+     * it is of any use. This is normally done using Spring's
+     * dependency injection.
+     */
+    public static Registry getInstance()
+    {
+        return ourInstance;
+    }
+
+    /**
+     * Private constructor to enforce singleton pattern.
+     */
+    private Registry()
+    {
+    }
+
+    public static PolicyManager policyManager()
+    {
+        return ourInstance.policyManager;
+    }
+
+    public static SmsManager smsManager()
+    {
+        return ourInstance.smsManager;
+    }
+    
+    public PolicyManager getPolicyManager()
+    {
+        return policyManager;
+    }
+
+    public void setPolicyManager( PolicyManager policyManager )
+    {
+        this.policyManager = policyManager;
+    }
+
+    public SmsManager getSmsManager()
+    {
+        return smsManager;
+    }
+
+    public void setSmsManager( SmsManager smsManager )
+    {
+        this.smsManager = smsManager;
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/SmsManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/SmsManager.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/SmsManager.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/service/SmsManager.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.demo.service;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: tbennett
+ * Date: May 13, 2006
+ * Time: 3:23:02 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface SmsManager {
+    void setSmsTransportUrl( String url );
+    void setSmsAccountName( String accountName );
+    void setSmsUsername( String username );
+    void setSmsPassword( String password );
+    void sendSmsMessage( String mobile, String carrier, String username )
+            throws Exception;
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDataProvider.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDataProvider.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDataProvider.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDataProvider.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,48 @@
+/*
+ *  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.demo.view;
+
+import wicket.extensions.markup.html.repeater.util.SortableDataProvider;
+import org.safehaus.triplesec.demo.dao.AccountDao;
+import org.safehaus.triplesec.demo.dao.QueryParam;
+
+import java.util.Iterator;
+
+public abstract class AccountDataProvider extends SortableDataProvider
+{
+    protected AccountDataProvider()
+    {
+        setSort( "uid", true );
+    }
+
+    protected abstract AccountDao getAccountDao();
+
+    public final Iterator iterator( int first, int count )
+    {
+        QueryParam qp = new QueryParam( first, count,
+                getSort().getProperty(), getSort().isAscending() );
+        return getAccountDao().find( qp );
+    }
+
+    public final int size()
+    {
+        return getAccountDao().count();
+    }
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDetachableModel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDetachableModel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDetachableModel.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/AccountDetachableModel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,70 @@
+/*
+ *  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.demo.view;
+
+import wicket.model.AbstractDetachableModel;
+import wicket.model.IModel;
+import wicket.Component;
+import org.safehaus.triplesec.demo.model.Account;
+import org.safehaus.triplesec.demo.dao.AccountDao;
+
+/**
+ * Base class for contact detachable models. This class implements
+ * all necessary logic except retrieval of the dao object, this way
+ * we can isolate that logic.
+ */
+public abstract class AccountDetachableModel extends AbstractDetachableModel
+{
+    private String uid;
+    private transient Account account;
+
+    public AccountDetachableModel( Account account )
+    {
+        this.uid = account.getUid();
+        this.account = account;
+    }
+
+    public IModel getNestedModel()
+    {
+        return null;
+    }
+
+    protected final void onAttach()
+    {
+        account = getAccountDao().get( uid );
+    }
+
+    protected final void onDetach()
+    {
+        account = null;
+    }
+
+    protected Object onGetObject( Component component )
+    {
+        return account;
+    }
+
+    protected void onSetObject( Component component, Object object )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    protected abstract AccountDao getAccountDao();
+}

Added: directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/ChartResource.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/ChartResource.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/ChartResource.java (added)
+++ directory/trunks/triplesec/webapp-demo/src/main/java/org/safehaus/triplesec/demo/view/ChartResource.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,144 @@
+/*
+ *  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.demo.view;
+
+import org.jCharts.chartData.ChartDataException;
+import org.jCharts.chartData.PieChartDataSet;
+import org.jCharts.nonAxisChart.PieChart2D;
+import org.jCharts.properties.ChartProperties;
+import org.jCharts.properties.LegendProperties;
+import org.jCharts.properties.PieChart2DProperties;
+import org.safehaus.triplesec.demo.model.Account;
+import wicket.markup.html.image.resource.BufferedDynamicImageResource;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.HeadlessException;
+import java.awt.Image;
+import java.awt.Paint;
+import java.awt.Transparency;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.swing.ImageIcon;
+
+
+public class ChartResource extends BufferedDynamicImageResource
+{
+    private static final long serialVersionUID = 7331088436339160727L;
+
+    public ChartResource( final Account account )
+    {
+        this.setFormat("PNG");
+        this.setImage( createChart( account ) );
+        this.setCacheable( false );
+    }
+
+    
+    private BufferedImage createChart( final Account account )
+    {
+        double[] data= { 
+            account.getBonds(), 
+            account.getForeign(), 
+            account.getTBills(), 
+            account.getTechStocks(),
+            account.getVolatileHighYield() 
+        };
+        String[] labels= { "Bonds", "Foriegn", "T-Bills", "Tech Stocks", "Volatile" };
+        Paint[] paints= { Color.magenta, Color.green, Color.blue, Color.red, Color.yellow };
+
+        PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
+        PieChartDataSet pieChartDataSet= null;
+        
+        try
+        {
+            pieChartDataSet = new PieChartDataSet( "Investments", data, labels, paints, pieChart2DProperties );
+        }
+        catch ( ChartDataException e )
+        {
+            e.printStackTrace();
+        }
+
+        PieChart2D pieChart2D = new PieChart2D( pieChartDataSet, new LegendProperties(), new ChartProperties(), 500, 300 );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        
+        try
+        {
+            org.jCharts.encoders.PNGEncoder.encode( pieChart2D, out );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+        }
+ 
+        ImageIcon img = new ImageIcon( out.toByteArray() );
+        return toBufferedImage( img.getImage() );
+    }
+    
+    private BufferedImage toBufferedImage( Image image )
+    {
+        if ( image instanceof BufferedImage )
+        {
+            return ( BufferedImage ) image;
+        }
+
+        // This code ensures that all the pixels in the image are loaded
+        image = new ImageIcon( image ).getImage();
+
+        // Create a buffered image with a format that's compatible with the screen
+        BufferedImage bimage = null;
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        try
+        {
+            // Determine the type of transparency of the new buffered image
+            int transparency = Transparency.OPAQUE;
+
+            // Create the buffered image
+            GraphicsDevice gs = ge.getDefaultScreenDevice();
+            GraphicsConfiguration gc = gs.getDefaultConfiguration();
+            bimage = gc.createCompatibleImage( image.getWidth( null ), image.getHeight( null ), transparency );
+        }
+        catch ( HeadlessException e )
+        {
+            // The system does not have a screen
+            e.printStackTrace();
+        }
+
+        if ( bimage == null )
+        {
+            // Create a buffered image using the default color model
+            int type = BufferedImage.TYPE_INT_RGB;
+            bimage = new BufferedImage( image.getWidth( null ), image.getHeight( null ), type );
+        }
+
+        // Copy image to buffered image
+        Graphics g = bimage.createGraphics();
+
+        // Paint the image onto the buffered image
+        g.drawImage( image, 0, 0, null );
+        g.dispose();
+
+        return bimage;
+    }
+}



Mime
View raw message