Author: [email protected]
Date: Fri Aug  5 18:22:23 2011
New Revision: 1271

Log:


Added:
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/NTLMService.java
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyService.java
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStore.java
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Survey.java
   
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMServiceImpl.java
   
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyColumnFamilyProvider.java
   
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyServiceImpl.java
   
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
   sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp
   sandbox/ivol/ntlm/src/main/resources/jsp/register.jsp
   sandbox/ivol/ntlm/src/main/resources/static/
   sandbox/ivol/ntlm/src/main/resources/static/css/
   sandbox/ivol/ntlm/src/main/resources/static/css/cr.css
   sandbox/ivol/ntlm/src/main/resources/static/img/
   sandbox/ivol/ntlm/src/main/resources/static/img/amdatu.jpg   (contents, 
props changed)
Removed:
   sandbox/ivol/ntlm/src/main/resources/jsp/ntlm.jsp
Modified:
   sandbox/ivol/ntlm/pom.xml
   sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java

Modified: sandbox/ivol/ntlm/pom.xml
==============================================================================
--- sandbox/ivol/ntlm/pom.xml   (original)
+++ sandbox/ivol/ntlm/pom.xml   Fri Aug  5 18:22:23 2011
@@ -50,6 +50,55 @@
       <type>bundle</type>
     </dependency>
     <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>org.amdatu.web.jaxrs</artifactId>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.listener</artifactId>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.application</artifactId>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.persistencemanager</artifactId>
+      <type>bundle</type>
+    </dependency>
+
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.listener</artifactId>
+      <type>bundle</type>
+      <version>0.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.application</artifactId>
+      <type>bundle</type>
+      <version>0.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.persistencemanager</artifactId>
+      <type>bundle</type>
+      <version>0.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+      <version>20090211</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
       <groupId>org.samba.jcifs</groupId>
       <artifactId>jcifs</artifactId>
       <version>1.3.16</version>
@@ -70,7 +119,6 @@
           </instructions>
         </configuration>
       </plugin>
-
     </plugins>
   </build>
 </project>

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/NTLMService.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/NTLMService.java       
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,5 @@
+package org.amdatu.auth.ntlm;
+
+public interface NTLMService {
+
+}

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyService.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyService.java     
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,5 @@
+package org.amdatu.auth.ntlm;
+
+public interface SurveyService {
+
+}

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStore.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStore.java       
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,8 @@
+package org.amdatu.auth.ntlm;
+
+import org.amdatu.auth.ntlm.domain.Survey;
+import org.json.JSONException;
+
+public interface SurveyStore {
+    Survey loadSurvey(String surveyId) throws JSONException;
+}

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java     
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,33 @@
+package org.amdatu.auth.ntlm.domain;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "answer")
+@XmlAccessorType(XmlAccessType.NONE)
+public class Answer {
+    @XmlAttribute(name = "questionId")
+    private String m_questionId;
+    
+    @XmlAttribute(name = "answer")
+    private String m_answer;
+    
+    public Answer() {
+    }
+    public String getQuestionId() {
+        return m_questionId;
+    }
+    public void setQuestionId(String questionId) {
+        m_questionId = questionId;
+    }
+    public String getAnswer() {
+        return m_answer;
+    }
+    public void setAnswer(String answer) {
+        m_answer = answer;
+    }
+    
+    
+}

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java   
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,98 @@
+package org.amdatu.auth.ntlm.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import me.prettyprint.hector.api.beans.HColumn;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+@XmlRootElement(name = "question")
+@XmlAccessorType(XmlAccessType.NONE)
+public class Question {
+    @XmlAttribute(name = "id")
+    private String m_id;
+    
+    @XmlAttribute(name = "description")
+    private String m_description;
+    
+    @XmlAttribute(name = "type")
+    private String m_type;
+    
+    @XmlElement(name = "value")
+    private List<String> m_values;
+    
+    public Question() {
+    }
+
+    public String getId() {
+        return m_id;
+    }
+    public void setId(String id) {
+        m_id = id;
+    }
+    
+    public String getDescription() {
+        return m_description;
+    }
+    public void setDescription(String description) {
+        m_description = description;
+    }
+    public String getType() {
+        return m_type;
+    }
+    public void setType(String type) {
+        m_type = type;
+    }
+    public List<String> getValues() {
+        return m_values;
+    }
+    public void setValues(List<String> values) {
+        m_values = values;
+    }
+    
+    public void addValue(String value) {
+        if (m_values == null) {
+            m_values = new ArrayList<String>();
+        }
+        m_values.add(value);
+    }
+    
+    public String toJSON() throws JSONException {
+        JSONObject question = new JSONObject();
+        question.put("description", getDescription());
+        question.put("type", getType());
+        question.put("values", getValues());
+        return new JSONObject().put("question", question).toString();
+    }
+    
+    public static Question fromJSON(String json) throws JSONException {
+        JSONObject jsonObject = new JSONObject(json).getJSONObject("question");
+        Question question = new Question();
+        question.setDescription(jsonObject.getString("description"));
+        question.setType(jsonObject.getString("type"));
+        JSONArray values = jsonObject.getJSONArray("values");
+        List<String> sValues = new ArrayList<String>();
+        for (int i=0; i<values.length(); i++) {
+            sValues.add(values.getString(i));
+        }
+        question.setValues(sValues);
+        return question;
+    }
+    
+    public static Question load(HColumn<String, String> question) throws 
JSONException {
+        String id = question.getName();
+        String value = question.getValue();
+        Question q = fromJSON(value);
+        q.setId(id);
+        return q;
+    }
+}

Added: sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Survey.java
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Survey.java     
Fri Aug  5 18:22:23 2011
@@ -0,0 +1,63 @@
+package org.amdatu.auth.ntlm.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.beans.HSuperColumn;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+@XmlRootElement(name = "survey")
+@XmlAccessorType(XmlAccessType.NONE)
+public class Survey {
+    @XmlAttribute(name = "id")
+    private String m_id;
+    
+    @XmlElement(name = "question")
+    private List<Question> m_questions;
+    
+    public Survey() {
+    }
+    
+    public String getId() {
+        return m_id;
+    }
+
+    public void setId(String id) {
+        m_id = id;
+    }
+
+    public void setQuestions(List<Question> questions) {
+        m_questions = questions;
+    }
+
+    public List<Question> getQuestions() {
+        return m_questions;
+    }
+    
+    public void loadQuestions(HSuperColumn<String, String, String> questionSC) 
throws JSONException {
+        List<HColumn<String, String>> questions = questionSC.getColumns();
+        m_questions = new ArrayList<Question>();
+        for (HColumn<String, String> question : questions) {
+            m_questions.add(Question.load(question));
+        }
+    }
+    
+    public String toJSON() throws JSONException {
+        JSONObject survey = new JSONObject();
+        survey.put("id", getId());
+        JSONArray questions = new JSONArray(getQuestions());
+      
+        survey.put("questions", questions);
+        return new JSONObject().put("survey", survey).toString();
+    }
+}

Modified: 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java
==============================================================================
--- sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java    
(original)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java    
Fri Aug  5 18:22:23 2011
@@ -20,7 +20,18 @@
 
 import javax.servlet.Filter;
 
+import jcifs.http.NtlmHttpFilter;
+
+import org.amdatu.auth.ntlm.NTLMService;
+import org.amdatu.auth.ntlm.SurveyService;
+import org.amdatu.auth.ntlm.SurveyStore;
+import org.amdatu.auth.ntlm.service.NTLMServiceImpl;
+import org.amdatu.auth.ntlm.service.SurveyColumnFamilyProvider;
+import org.amdatu.auth.ntlm.service.SurveyServiceImpl;
+import org.amdatu.auth.ntlm.service.SurveyStoreImpl;
 import org.amdatu.auth.ntlm.service.WebResourceProvider;
+import org.amdatu.cassandra.listener.ColumnFamilyProvider;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
 import org.amdatu.web.dispatcher.DispatcherService;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.amdatu.web.jsp.JspSupport;
@@ -29,6 +40,7 @@
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.log.LogService;
 
 /**
@@ -57,6 +69,8 @@
      */
     public static final String CONTEXTID = "amdatu-ntlm";
     
+    private ServiceRegistration m_registration;
+    
     @Override
     public void init(final BundleContext context, final DependencyManager 
manager) throws Exception {
         // Register the tweet gadget
@@ -76,13 +90,35 @@
         filterProps.put(DispatcherService.CONTEXT_ID_KEY, Activator.CONTEXTID);
         filterProps.put("init.jcifs.http.domainController", "bail.gx.local");
 
-        manager.add(
+        m_registration = context.registerService(Filter.class.getName(), new 
NtlmHttpFilter(), filterProps);
+       /* manager.add(
             createComponent()
                 .setInterface(Filter.class.getName(), filterProps)
-                .setImplementation(jcifs.http.NtlmHttpFilter.class));
+                .setImplementation(jcifs.http.NtlmHttpFilter.class));*/
+        
+        manager.add(
+            createComponent()
+                .setInterface(NTLMService.class.getName(), null)
+                .setImplementation(NTLMServiceImpl.class));
+        
+        manager.add(
+            createComponent()
+                .setInterface(SurveyService.class.getName(), null)
+                .setImplementation(SurveyServiceImpl.class)
+                
.add(createServiceDependency().setService(SurveyStore.class).setRequired(true)));
        
+        
+        manager.add(createComponent()
+            .setInterface(new String[]{ColumnFamilyProvider.class.getName()}, 
null)
+            .setImplementation(SurveyColumnFamilyProvider.class));
+        
+        manager.add(createComponent()
+            .setInterface(new String[]{SurveyStore.class.getName()}, null)
+            .setImplementation(SurveyStoreImpl.class)
+            
.add(createServiceDependency().setService(CassandraPersistenceManager.class).setRequired(true)));
     }
 
     @Override
     public void destroy(final BundleContext context, final DependencyManager 
manager) throws Exception {
+        m_registration.unregister();
     }
 }

Added: 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMServiceImpl.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMServiceImpl.java
   Fri Aug  5 18:22:23 2011
@@ -0,0 +1,23 @@
+package org.amdatu.auth.ntlm.service;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+import jcifs.smb.NtlmPasswordAuthentication;
+
+import org.amdatu.auth.ntlm.NTLMService;
+
+@Path("ntlm")
+public class NTLMServiceImpl implements NTLMService {
+    @GET
+    @Path("username")
+    @Produces({MediaType.TEXT_PLAIN})
+    public String status(@Context final HttpServletRequest request) {
+        NtlmPasswordAuthentication session = (NtlmPasswordAuthentication) 
request.getSession().getAttribute("NtlmHttpAuth");
+        return session.getUsername();
+    }
+}

Added: 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyColumnFamilyProvider.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyColumnFamilyProvider.java
        Fri Aug  5 18:22:23 2011
@@ -0,0 +1,25 @@
+package org.amdatu.auth.ntlm.service;
+
+import org.amdatu.cassandra.listener.ColumnFamilyDefinition;
+import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType;
+import org.amdatu.cassandra.listener.ColumnFamilyDefinition.CompareType;
+import org.amdatu.cassandra.listener.ColumnFamilyProvider;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+
+public class SurveyColumnFamilyProvider implements ColumnFamilyProvider {
+    /**
+     * ColumnFamily that stores the survey definitions.
+     */
+    public static final String CF_SURVEY = "Survey";
+    
+    public ColumnFamilyDefinition[] getColumnFamilies() {
+        return new ColumnFamilyDefinition[] {
+            new ColumnFamilyDefinition(
+                CF_SURVEY,
+                    new String[] 
{CassandraPersistenceManager.DEFAULT_KEYSPACE},
+                    ColumnType.SUPER,
+                    CompareType.BYTESTYPE,
+                    CompareType.BYTESTYPE)};
+    }
+
+}

Added: 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyServiceImpl.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyServiceImpl.java
 Fri Aug  5 18:22:23 2011
@@ -0,0 +1,49 @@
+package org.amdatu.auth.ntlm.service;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.amdatu.auth.ntlm.SurveyService;
+import org.amdatu.auth.ntlm.SurveyStore;
+import org.amdatu.auth.ntlm.domain.Survey;
+
+@Path("survey")
+public class SurveyServiceImpl implements SurveyService {
+    private volatile SurveyStore m_surveyStore;
+
+    @GET
+    @Path("submitted")
+    @Produces({MediaType.TEXT_PLAIN})
+    public String hasSubmitted(@Context final HttpServletRequest request) {
+        Object session = request.getSession().getAttribute("NtlmHttpAuth");
+
+        return "1";
+    }
+
+    @POST
+    @Produces({MediaType.TEXT_PLAIN})
+    public void addSurvey(@Context final HttpServletRequest request) {
+        // TODO: verify that this user did not yet submit this survey
+    }
+
+    @GET
+    @Path("{id}")
+    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public Response getSurvey(@Context final HttpServletRequest request, 
@PathParam("id") final String surveyId) {
+        try {
+            Survey survey = m_surveyStore.loadSurvey(surveyId);
+            return Response.ok(survey).build();
+        }
+        catch (Exception e) {
+            throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
+        }
+    }
+}

Added: 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
   Fri Aug  5 18:22:23 2011
@@ -0,0 +1,74 @@
+package org.amdatu.auth.ntlm.service;
+
+import java.util.List;
+
+import me.prettyprint.hector.api.beans.HSuperColumn;
+
+import org.amdatu.auth.ntlm.SurveyStore;
+import org.amdatu.auth.ntlm.domain.Answer;
+import org.amdatu.auth.ntlm.domain.Question;
+import org.amdatu.auth.ntlm.domain.Survey;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+import org.json.JSONException;
+
+public class SurveyStoreImpl implements SurveyStore {
+    public final static String SC_QUESTIONS = "Questions";
+    public final static String SC_ANSWERS = "Answers";
+    
+    private volatile CassandraPersistenceManager m_pm;
+    
+    public void start() throws JSONException {
+        // Add a test survey
+        addTestSurvey();
+        
+        // Retieve the survey
+        Survey survey = loadSurvey("1");
+        
+        
+        
+        List<Question> questions = survey.getQuestions();
+        questions.get(0);
+    }
+    
+    public Survey loadSurvey(String surveyId) throws JSONException {
+        Survey survey = new Survey();
+        survey.setId(surveyId);
+        List<HSuperColumn<String, String, String>> superColumns = 
m_pm.getSuperColumns(SurveyColumnFamilyProvider.CF_SURVEY, surveyId, 
String.class);
+        for (HSuperColumn<String, String, String> superColumn : superColumns) {
+            if (superColumn.getName().equals(SurveyStoreImpl.SC_QUESTIONS)) {
+                survey.loadQuestions(superColumn);
+            }
+        }
+        return survey;
+    }
+    
+    
+    
+    private void addAnswer(Survey survey, Answer answer) {
+        
+    }
+    
+    private void addTestSurvey() throws JSONException {
+        Question q1 = new Question();
+        q1.setDescription("Wil je salarisverhoging?");
+        q1.setType("radio");
+        q1.addValue("Ja");
+        q1.addValue("Nee");
+        
+        Question q2 = new Question();
+        q2.setDescription("Wil vind je er allemaal van?");
+        q2.setType("open");
+       
+        Question q3 = new Question();
+        q3.setDescription("Wat vind je belangrijk?");
+        q3.setType("check");
+        q3.addValue("MTO");
+        q3.addValue("Arbeidsvoorwaarden");
+        q3.addValue("Lease auto");
+        
+        String surveyId = "1";
+        m_pm.setValue(SurveyColumnFamilyProvider.CF_SURVEY, surveyId, 
SC_QUESTIONS, "Q1", q1.toJSON());
+        m_pm.setValue(SurveyColumnFamilyProvider.CF_SURVEY, surveyId, 
SC_QUESTIONS, "Q2", q2.toJSON());
+        m_pm.setValue(SurveyColumnFamilyProvider.CF_SURVEY, surveyId, 
SC_QUESTIONS, "Q3", q3.toJSON());
+    }
+}

Added: sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp        Fri Aug  5 
18:22:23 2011
@@ -0,0 +1,139 @@
+<%--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.verning permissions and limitations
+  under the License.
+--%>
+
+<%@ page language="java" session="false" buffer="none" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
+
+<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
+<c:set var="staticPath" value="${contextPath}/oauth-consumerregistry/static"/>
+<c:set var="ntlmUrl" value="${baseUrl}/rest/ntlm"/>
+<c:set var="surveyUrl" value="${baseUrl}/rest/survey"/>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
+<html>
+  <head>
+      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+      <title>Ondernemingsraad - Online enquete</title>
+      <link rel="stylesheet" href="${staticPath}/css/cr.css">
+      <script type="text/javascript" 
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
+  </head>
+
+  <body>
+    <table>
+      <tr>
+        <td align="left"><img src="${staticPath}/img/amdatu.jpg" width="30%" 
align="left"/></td>
+        <td align="right" nowrap="nowrap"><h2>Welkom <label 
id="username"></label></h2></td>
+      </tr>
+    </table>
+    <hr/>
+
+    <div class="leftbox">
+      <h3>Waarom?</h3>
+      <p>Deze online enquete moet ons inzicht geven in wat de achterban vindt. 
Meer blablabla.</p>
+
+      <h3>Is dit anoniem?</h3>
+      <p>Ja. Om te garanderen dat werknemers maar eenmaal deze enquete in 
kunnen vullen wordt wel de gebruikersnaam opgeslagen.
+      Deze wordt echter niet gekoppeld aan de gegeven antwoorden, waardoor het 
achteraf niet mogelijk is te bepalen wie welk antwoord gegeven heeft.</p>
+
+      <h3>Wat gebeurd hiermee?</h3>
+      <p>En meer blablablal</p>
+    </div>
+
+    <div class="rightbox">
+      <p>
+      <form action="rest/enquete">
+        <ul>
+          <li><b>Vraag 1.</b><br/>
+            Vind jij dat een 13e maand onderdeel zou moeten zijn van de GX 
arbeidsvoorwaarden?<br/>
+            <input type="radio" name="vraag1" value="1"/>Ja
+            <input type="radio" name="vraag1" value="0"/>Nee
+          </li>
+
+          <li><b>Vraag 2.</b><br/>
+            Vind jij dat salarisverhogingen absoluut of relatief berekend 
moeten worden?<br/>
+            <input type="radio" name="vraag2" value="1"/>Ja
+            <input type="radio" name="vraag2" value="0"/>Nee
+          </li>
+
+          <li><b>Vraag 3.</b><br/>
+          Wat vind je van deze open vraag?<br/>
+          <textarea name="vraag3" rows="3"></textarea>
+          </li>
+        </ul>
+        <input type="submit" value="Versturen" />
+        </form>
+      </p>
+    </div>
+
+  </body>
+</html>
+
+<script type="text/javascript">
+
+  function getUsername() {
+     var url = "${ntlmUrl}/username";
+       jQuery.ajax({
+         url: url,
+         type: "GET",
+         async:true,
+         success: function(response) {
+             document.getElementById("username").innerHTML = response;
+           }
+         }
+    );
+  }
+
+  function hasSubmittedSurveyBefore() {
+    var url = "${surveyUrl}/submitted";
+         jQuery.ajax({
+           url: url,
+           type: "GET",
+           async:true,
+           success: function(response) {
+               if (response == "1") {
+                alert("Deze enquete heb je reeds ingevuld");
+               } else {
+
+               }
+             }
+           }
+    );
+  }
+
+  function loadSurvey() {
+    var url = "${surveyUrl}/1";
+       jQuery.ajax({
+         url: url,
+         type: "GET",
+         async:true,
+         success: function(data, textStatus, jqXHR) {
+            var survey = jQuery.parseJSON(jqXHR.responseText).survey;
+            var questions = survey.question;
+            for (i=0; i<questions.length;i++) {
+              alert(questions[i].id);
+            }
+          }
+        }
+      );
+    }
+
+
+  getUsername();
+  hasSubmittedSurveyBefore();
+  loadSurvey();
+
+</script>

Added: sandbox/ivol/ntlm/src/main/resources/jsp/register.jsp
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/resources/jsp/register.jsp       Fri Aug  5 
18:22:23 2011
@@ -0,0 +1,385 @@
+<%--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.verning permissions and limitations
+  under the License.
+--%>
+
+<%@ page language="java" session="false" buffer="none" %>
+<%@ page pageEncoding="UTF-8"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
+
+<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
+<c:set var="staticPath" value="${contextPath}/oauth-consumerregistry/static"/>
+<c:set var="baseUrl" 
value="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${contextPath}"/>
+<c:set var="statusUrl" value="${baseUrl}/rest/authorization/status"/>
+<c:set var="loginUrl" value="${baseUrl}/rest/authorization/login"/>
+<c:set var="appUrl" value="${baseUrl}/rest/oauth/consumers/"/>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
+<html>
+  <head>
+      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+      <title>Amdatu OAuth Server - Manage Applications</title>
+      <link rel="stylesheet" href="${staticPath}/css/cr.css">
+      <script type="text/javascript" 
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
+  </head>
+
+  <body>
+    <table>
+      <tr>
+        <td align="left"><img src="${staticPath}/img/amdatu.jpg" width="30%" 
align="left"/></td>
+        <td align="right" nowrap="nowrap"><h2>Manage your 
applications</h2></td>
+      </tr>
+    </table>
+    <hr/>
+
+    <div class="leftbox">
+      <h3>Register a new application</h3>
+      <p>
+        Click <a href="#" onclick="javascript:showDiv('newApp');">here</a> to 
register a new Application in the consumer registry of the OAuth server.
+        Registered applications will receive a consumer key and secret which 
can be used to
+        communicate using the OAuth protocol.
+      </p>
+
+      <h3>Your registered applications</h3>
+      <p>
+        The list below shows an overview of Applications you have currently 
registered.
+
+        <div id="myapps">
+        </div>
+      </p>
+    </div>
+
+    <div class="rightbox">
+      <p>
+        <div id="login" name="hidablediv" 
style="display:none;visibility:hidden">
+          To register a new Application you must log in with an existing 
Amdatu account.
+          <table width="95%">
+            <tr>
+              <td>Username</td><td><input type="edit" id="editusername" 
value="" onKeyPress="return submitenter(this, event)"/></td>
+            </tr>
+            <tr>
+              <td>Password</td><td><input type="password" id="editpassword" 
value="" onKeyPress="return submitenter(this, event)"/></td>
+            </tr>
+            <tr>
+              <td><input type="submit" value="Login" 
onclick="javascript:login()" /></td><td/>
+            </tr>
+            <tr><td colspan="2"><font color="red"><div 
id="result"></div></font></td></tr>
+          </table>
+        </div>
+
+        <div id="account" name="hidablediv" 
style="display:none;visibility:hidden">
+          <p>
+            You are currently logged in as '<label id="username"></label>'. 
Click on one of the links on the
+            left to register a new application or to edit an existing 
application.
+          </p>
+        </div>
+
+        <div id="newApp" name="hidablediv" 
style="display:none;visibility:hidden">
+          <table>
+            <tr>
+              <td>Application name</td>
+              <td><input id="name" type="text" style="width: 200px;"></td>
+            </tr>
+            <tr>
+              <td>Callback URL</td>
+              <td><input id="callbackurl" type="text" style="width: 
500px;"></td>
+            </tr>
+            <tr>
+              <td><input type="button" value="Register" 
onclick="javascript:newApplication();"></td>
+              <td></td>
+            </tr>
+          </table>
+        </div>
+
+        <div id="editApp" name="hidablediv" 
style="display:none;visibility:hidden">
+          <table>
+            <tr>
+              <td>Application name</td>
+              <td><input id="editname" type="text" disabled="disabled" 
style="width: 200px;"></td>
+            </tr>
+            <tr>
+              <td>Consumer key</td>
+              <td><input id="editconsumerkey" type="text" disabled="disabled" 
style="width: 500px;"></td>
+            </tr>
+            <tr>
+              <td>Consumer secret</td>
+              <td><input id="editconsumersecret" type="text" 
disabled="disabled" style="width: 500px;"></td>
+            </tr>
+            <tr>
+              <td>Callback URL</td>
+              <td><input id="editcallbackurl" type="text" style="width: 
500px;"></td>
+            </tr>
+          </table>
+
+          <table>
+            <tr>
+              <td><input type="button" value="Update application" 
onclick="javascript:updateApplication();"></td>
+              <td><input type="button" value="Delete application" 
onclick="javascript:deleteApplication();"></td>
+            </tr>
+          </table>
+        </div>
+
+        <div id="info" class="info" 
style="display:none;visibility:hidden"></div>
+
+        <div id="error" class="error" 
style="display:none;visibility:hidden"></div>
+      </p>
+  </div>
+
+  </body>
+</html>
+
+<script type="text/javascript">
+  detectLoginStatus();
+  loadApplications();
+
+  function detectLoginStatus() {
+    var url = "${statusUrl}";
+    jQuery.ajax({
+      url: url,
+      type: "GET",
+      dataType: "json",
+      async:true,
+      success: function(response) {
+          if (response.username != null) {
+            showDiv("account");
+            document.getElementById("username").innerHTML = response.username;
+            loadApplications();
+          } else {
+            showDiv("login");
+          }
+        }
+      }
+    );
+  }
+
+  function login() {
+    var postdata = {
+      username : document.getElementById('editusername').value,
+      password : document.getElementById('editpassword').value
+    };
+
+    var url = "${loginUrl}";
+    jQuery.ajax({
+      url: url,
+      type: "POST",
+      data: postdata,
+      dataType: "json",
+      async:true,
+      success: function(response) {
+          if (response.result != null && response.result == 'ok') {
+            showRegister(response.username);
+          } else {
+            var errorMsg = "An unexpected error occurred";
+            if (response.msg) {
+              errorMsg = response.msg;
+            }
+            var resultDiv = document.getElementById("result");
+            resultDiv.innerHTML = errorMsg;
+          }
+        }
+      }
+    );
+  }
+
+  function loadApplications() {
+    var url = "${appUrl}";
+    jQuery.ajax({
+      url: url,
+      type: "GET",
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        var consumers = 
jQuery.parseJSON(jqXHR.responseText).consumers.consumer;
+        if (typeof consumers != 'undefined') {
+          var html = "<ul>";
+          if (typeof consumers.length == 'undefined') {
+            html += "<li><a href=\"#\" onclick=\"javascript:editApplication('" 
+ getEditLink(consumers) + "');\">" + consumers.name + "</a></li>";
+          }
+          else {
+            for (i=0; i<consumers.length; i++) {
+              html += "<li><a href=\"#\" 
onclick=\"javascript:editApplication('" + getEditLink(consumers[i]) + "');\">" 
+ consumers[i].name + "</a></li>";
+            }
+          };
+          html += "</ul>";
+          var myAppsDiv = document.getElementById("myapps");
+          myAppsDiv.innerHTML = html;
+        }
+        else {
+          var myAppsDiv = document.getElementById("myapps");
+          myAppsDiv.innerHTML = "<p><i>You do not have any registered 
applications</i></p>";
+        }
+      }
+    });
+  }
+
+  function getEditLink(consumer) {
+    var links = consumer.links.link;
+    for (j=0; j<links.length; j++) {
+      if (links[j].rel == "edit") {
+        return links[j].href;
+      }
+    }
+    return "";
+  }
+
+  function editApplication(url) {
+    showDiv("editApp");
+    jQuery.ajax({
+        url: url,
+        type: "GET",
+        dataType: "json",
+        async:true,
+        success: function(data, textStatus, jqXHR) {
+          var consumer = jQuery.parseJSON(jqXHR.responseText).consumer;
+          document.getElementById("editname").value = consumer.name;
+          document.getElementById("editconsumerkey").value = 
consumer.consumerKey;
+          document.getElementById("editconsumersecret").value = 
consumer.consumerSecret;
+          document.getElementById("editcallbackurl").value = 
consumer.callbackUrl;
+        }
+    });
+  }
+
+  function updateApplication(app) {
+    var postdata = {
+      callbackurl : document.getElementById('editcallbackurl').value,
+    };
+
+    var url = "${appUrl}" + document.getElementById('editconsumerkey').value;
+    jQuery.ajax({
+      url: url,
+      type: "PUT",
+      data: postdata,
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        showInfo("Application updated successfully");
+        loadApplications();
+      },
+      error: function(jqXHR, textStatus, errorThrown) {
+        var obj = jQuery.parseJSON(jqXHR.responseText);
+        showError(obj.result.message);
+      }
+    });
+  }
+
+  function deleteApplication(app) {
+    var url = "${appUrl}" + document.getElementById('editconsumerkey').value;
+    jQuery.ajax({
+      url: url,
+      type: "DELETE",
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        showInfo("Application deleted successfully");
+        hide("editApp");
+        loadApplications();
+      },
+      error: function(jqXHR, textStatus, errorThrown) {
+        var obj = jQuery.parseJSON(jqXHR.responseText);
+        showError(obj.result.message);
+      }
+    });
+  }
+
+  function showDiv(id) {
+    hide("info");
+    hide("error");
+    var divs = document.getElementsByName("hidablediv");
+    for (i=0; i<divs.length; i++) {
+      divs[i].style.visibility = "hidden";
+      divs[i].style.display = "none";
+    }
+    document.getElementById(id).style.visibility = "";
+    document.getElementById(id).style.display = "";
+  }
+
+  function show(id) {
+    document.getElementById(id).style.visibility = "";
+    document.getElementById(id).style.display = "";
+  }
+
+  function hide(id) {
+    document.getElementById(id).style.visibility = "hidden";
+    document.getElementById(id).style.display = "none";
+  }
+
+  function submitenter(field, e) {
+    var keycode;
+    if (window.event) {
+      keycode = window.event.keyCode;
+    } else if (e) {
+      keycode = e.which;
+    } else {
+      return true;
+    }
+
+    if (keycode == 13) {
+      login();
+      return false;
+    } else {
+      return true;
+    }
+  }
+
+  function newApplication() {
+    var postdata = {
+      name : document.getElementById('name').value,
+      callbackurl : document.getElementById('callbackurl').value,
+    };
+
+    var url = "${appUrl}";
+    jQuery.ajax({
+      url: url,
+      type: "POST",
+      data: postdata,
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        var consumer = jQuery.parseJSON(jqXHR.responseText).consumer;
+        var resultDiv = document.getElementById("info");
+        var html = "The following Application has been registered:";
+        html += "<table>";
+        html += "<tr><td>Application name:</td><td>" + consumer.name + 
"</td></tr>";
+        html += "<tr><td>Consumer key:</td><td>" + consumer.consumerKey + 
"</td></tr>";
+        html += "<tr><td>Consumer secret:</td><td>" + consumer.consumerSecret 
+ "</td></tr>";
+        html += "<tr><td>Callback URL:</td><td>" + consumer.callbackUrl + 
"</td></tr>";
+        html += "</tr></table>";
+        hide("error");
+        show("info");
+        resultDiv.innerHTML = html;
+        loadApplications();
+      },
+      error: function(jqXHR, textStatus, errorThrown) {
+        var obj = jQuery.parseJSON(jqXHR.responseText);
+        showError(obj.result.message);
+      }
+    });
+  }
+
+  function showInfo(msg) {
+    hide("error");
+    var infoDiv = document.getElementById("info");
+    infoDiv.innerHTML = msg;
+    show("info");
+  }
+
+  function showError(msg) {
+    hide("info");
+    var errorDiv = document.getElementById("error");
+    errorDiv.innerHTML = msg;
+    show("error");
+  }
+
+</script>

Added: sandbox/ivol/ntlm/src/main/resources/static/css/cr.css
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/resources/static/css/cr.css      Fri Aug  5 
18:22:23 2011
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+ body {
+  margin: 0px;
+  padding: 0;
+  background: #000000;
+  font-family: bookman old style;
+  font-size: 14px;
+  color: #999999;
+}
+
+table {
+  padding: 10px;
+}
+
+a {
+  color: #FFFFFF;
+}
+
+label {
+  color: #CCCCCC;
+}
+
+div.leftbox {
+  width:22%;
+  height:600px;
+  float:left;
+  margin-left:10px;
+  background: #282828;
+
+  border: #555555 1px;
+  -moz-border-radius: 15px;
+  border-radius: 15px;
+  border-style: solid;
+
+  box-shadow: 7px 7px 8px #555555;
+  -webkit-box-shadow: 7px 7px 8px #555555;
+  -moz-box-shadow: 7px 7px 8px #555555;
+  filter: progid:DXImageTransform.Microsoft.dropShadow(color=#555555, offX=7, 
offY=7, positive=true);
+}
+
+p {
+margin-left:5px;
+}
+
+h3 {
+  margin-left:5px;
+}
+
+div.leftbox p {
+ margin-top:20px;
+ margin-left:10px;
+ margin-right:5px;
+ border: 1px;
+ border-color: #123456;
+}
+
+div.rightbox {
+  width: 75%;
+  height:600px;
+  float:left;
+  margin-left:15px;
+  background: #282828;
+
+  border: #555555 1px;
+  -moz-border-radius: 15px;
+  border-radius: 15px;
+  border-style: solid;
+
+  box-shadow: 7px 7px 8px #555555;
+  -webkit-box-shadow: 7px 7px 8px #555555;
+  -moz-box-shadow: 7px 7px 8px #555555;
+  filter: progid:DXImageTransform.Microsoft.dropShadow(color=#555555, offX=7, 
offY=7, positive=true);
+}
+
+div.error {
+  margin-left:15px;
+  color: #EB3125;
+  background: #282828;
+}
+
+div.info {
+  margin-left:15px;
+  color: #DDDDDD;
+  background: #282828;
+}
\ No newline at end of file

Added: sandbox/ivol/ntlm/src/main/resources/static/img/amdatu.jpg
==============================================================================
Binary file. No diff available.
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to