Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Supporting multi valued parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lrkwz committed Sep 26, 2011
1 parent 2e5b5a5 commit 2d294d1
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 72 deletions.
9 changes: 9 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is an usage example for jCriptionSpring.

It is supposed to be used against a local compiled SNAPSHOT version.
Change to the desider released version in pom.xml

Simply run mvn tomcat:run and point your rowser to http://localhost:8080/sample to start experimenting jCriptionSpring.

You may wish to take a look of the crypted data been transferred when submitting the UserProfile form: enable Firebug for localhost and take a look at what happnes in Net panel (click the Persist button to see the first ajax call which retrives the publick key).

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
<dependency>
<groupId>org.gitorious.jcryptionspring</groupId>
<artifactId>jcryption-spring</artifactId>
<version>0.1.1-SNAPSHOT</version>
<version>0.1.2-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
package org.gitorious.jcryptionspring.sample.domain;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Enumerated;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.CollectionOfElements;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooEntity
public class UserProfile {

private String email;
private String email;

private String name;

private String surname;

private String name;
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Calendar birthday;

private String surname;
private Boolean enabled;

@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Calendar birthday;
@Enumerated
private Colors preferredColor;

private Boolean enabled;
@CollectionOfElements
private List<Colors> colors = new LinkedList<Colors>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package org.gitorious.jcryptionspring.sample.domain;
import java.lang.Boolean;
import java.lang.String;
import java.util.Calendar;
import java.util.List;
import org.gitorious.jcryptionspring.sample.domain.Colors;

privileged aspect UserProfile_Roo_JavaBean {

Expand Down Expand Up @@ -49,4 +51,20 @@ privileged aspect UserProfile_Roo_JavaBean {
this.enabled = enabled;
}

public Colors UserProfile.getPreferredColor() {
return this.preferredColor;
}

public void UserProfile.setPreferredColor(Colors preferredColor) {
this.preferredColor = preferredColor;
}

public List<Colors> UserProfile.getColors() {
return this.colors;
}

public void UserProfile.setColors(List<Colors> colors) {
this.colors = colors;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ privileged aspect UserProfile_Roo_ToString {
public String UserProfile.toString() {
StringBuilder sb = new StringBuilder();
sb.append("Birthday: ").append(getBirthday() == null ? "null" : getBirthday().getTime()).append(", ");
sb.append("Colors: ").append(getColors() == null ? "null" : getColors().size()).append(", ");
sb.append("Email: ").append(getEmail()).append(", ");
sb.append("Enabled: ").append(getEnabled()).append(", ");
sb.append("Id: ").append(getId()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("PreferredColor: ").append(getPreferredColor()).append(", ");
sb.append("Surname: ").append(getSurname()).append(", ");
sb.append("Version: ").append(getVersion());
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,100 @@
package org.gitorious.jcryptionspring.sample.web;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.gitorious.jcryptionspring.sample.domain.Colors;
import org.gitorious.jcryptionspring.sample.domain.UserProfile;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.convert.converter.Converter;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.WebUtils;

@RooWebScaffold(path = "userprofiles", formBackingObject = UserProfile.class)
@RequestMapping("/userprofiles")
@Controller
public class UserProfileController {
private static final Logger logger = LoggerFactory
.getLogger(UserProfileController.class);

@ModelAttribute("colorses")
public Collection<Colors> populateColorses() {
Colors[] colors = Colors.class.getEnumConstants();
return Arrays.asList(colors);
}

/*
Converter<Colors, String> getColorsConverter() {
logger.debug("Called getColorsConverter");
Converter<Colors, String> converter = new Converter<Colors, String>() {
public String convert(Colors instance) {
logger.debug("Converter called with {}", instance);
return "" + instance.ordinal();
}
};
return converter;
}
*/

/*
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid UserProfile userProfile,
BindingResult bindingResult, Model uiModel,
HttpServletRequest httpServletRequest ) {
List<ObjectError> err = bindingResult.getAllErrors();
for (ObjectError objectError : err) {
logger.debug("Errors {} ", objectError.toString());
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("userProfile", userProfile);
addDateTimeFormatPatterns(uiModel);
return "userprofiles/create";
}
uiModel.asMap().clear();
logger.debug("User profile is {}", userProfile );
userProfile.persist();
return "redirect:/userprofiles/"
+ encodeUrlPathSegment(userProfile.getId().toString(),
httpServletRequest);
}
String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
String enc = httpServletRequest.getCharacterEncoding();
if (enc == null) {
enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
}
try {
pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
}
catch (UnsupportedEncodingException uee) {}
return pathSegment;
}
void addDateTimeFormatPatterns(Model uiModel) {
uiModel.addAttribute("userProfile_birthday_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import java.io.UnsupportedEncodingException;
import java.lang.Integer;
import java.lang.Long;
import java.lang.String;
import java.util.Arrays;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.gitorious.jcryptionspring.sample.domain.Colors;
import org.gitorious.jcryptionspring.sample.domain.UserProfile;
import org.joda.time.format.DateTimeFormat;
import org.springframework.context.i18n.LocaleContextHolder;
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Updated at Wed Sep 14 15:00:23 CEST 2011
#Wed Sep 14 15:00:23 CEST 2011
#Updated at Wed Sep 21 15:38:25 CEST 2011
#Wed Sep 21 15:38:25 CEST 2011
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.rootLogger=DEBUG, stdout
log4j.rootLogger=WARN, stdout
log4j.appender.R.File=application.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
Expand All @@ -10,3 +10,5 @@ log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.logger.org.gitorious.jcryptionspring=DEBUG
log4j.logger.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
7 changes: 5 additions & 2 deletions src/main/webapp/WEB-INF/i18n/application.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#Updated at Wed Sep 14 15:00:25 CEST 2011
#Wed Sep 14 15:00:25 CEST 2011
#Updated at Wed Sep 21 15:56:36 CEST 2011
#Wed Sep 21 15:56:36 CEST 2011
application_name=Sample
label_org_gitorious_jcryptionspring_sample_domain_userprofile=User Profile
label_org_gitorious_jcryptionspring_sample_domain_userprofile_birthday=Birthday
label_org_gitorious_jcryptionspring_sample_domain_userprofile_colors=Colors
label_org_gitorious_jcryptionspring_sample_domain_userprofile_email=Email
label_org_gitorious_jcryptionspring_sample_domain_userprofile_enabled=Enabled
label_org_gitorious_jcryptionspring_sample_domain_userprofile_id=Id
label_org_gitorious_jcryptionspring_sample_domain_userprofile_likes=Likes
label_org_gitorious_jcryptionspring_sample_domain_userprofile_name=Name
label_org_gitorious_jcryptionspring_sample_domain_userprofile_plural=User Profiles
label_org_gitorious_jcryptionspring_sample_domain_userprofile_preferredcolor=Preferred Color
label_org_gitorious_jcryptionspring_sample_domain_userprofile_surname=Surname
label_org_gitorious_jcryptionspring_sample_domain_userprofile_version=Version
menu_category_userprofile_label=User Profile
Expand Down
15 changes: 6 additions & 9 deletions src/main/webapp/WEB-INF/views/userprofiles/create.jspx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>

<spring:url value="/EncryptionServlet?generateKeypair=true" var="getKeysURL"/>
<script>
<spring:url value="/EncryptionServlet?generateKeypair=true" var="getKeysURL"/>
<script>
/*<![CDATA[ */
$(function() {
$("#userProfile").jCryption({getKeysURL:"${getKeysURL}"});
$("#userProfile").jCryption({getKeysURL:"${getKeysURL}"});
});
/*]]>*/
</script>

</script>
<form:create id="fc_org_gitorious_jcryptionspring_sample_domain_UserProfile" modelAttribute="userProfile" path="/userprofiles" render="${empty dependencies}" z="UjjJnNsd72qmCD/z7pNRmFs3S7U=">
<field:input field="email" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_email" validationMessageCode="field_invalid_email" z="g/pHIsPdXrkuGl89tswySDaxAMk="/>
<field:input field="name" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_name" z="9GKjR4Uuw0GRhqouZj6lRNLICmM="/>
<field:input field="surname" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_surname" z="qNuTmj7w7sl3W11eCb05lM62dls="/>
<field:datetime dateTimePattern="${userProfile_birthday_date_format}" field="birthday" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_birthday" z="bCZgN5NDcI1LqP03lTNhFBoRr3k="/>
<field:checkbox field="enabled" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_enabled" z="4h8Kl4k0Q0olaPZ8OmYX5htEToE="/>
<field:select field="preferredColor" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_preferredColor" items="${colorses}" path="colorses" z="DRwBnAFnEFJiMeQ/UjozIdZBnAY="/>
<field:select field="colors" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_colors" items="${colorses}" multiple="true" path="colorses" z="user-managed"/>
</form:create>
<form:dependency dependencies="${dependencies}" id="d_org_gitorious_jcryptionspring_sample_domain_UserProfile" render="${not empty dependencies}" z="vt2Y9pHIqB7CDsRoL+lccZade9o="/>
</div>
1 change: 1 addition & 0 deletions src/main/webapp/WEB-INF/views/userprofiles/list.jspx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<table:column id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_surname" property="surname" z="yTGZrbO+jMYMzxTBevhPKBTZkHY="/>
<table:column calendar="true" dateTimePattern="${userProfile_birthday_date_format}" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_birthday" property="birthday" z="dOOXBphtEgA4ahVViO9vkO7xPKc="/>
<table:column id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_enabled" property="enabled" z="Av/SB6HpHxt5FyY3T7RMCGmcTVg="/>
<table:column id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_preferredColor" property="preferredColor" z="YzeMjZSbvqwjZEZqi1g+KdGbfvc="/>
</table:table>
</page:list>
</div>
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/views/userprofiles/show.jspx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<field:display field="surname" id="s_org_gitorious_jcryptionspring_sample_domain_UserProfile_surname" object="${userprofile}" z="+iJJvTOQSoY8Ry6eDjlm1Gtpq38="/>
<field:display calendar="true" dateTimePattern="${userProfile_birthday_date_format}" field="birthday" id="s_org_gitorious_jcryptionspring_sample_domain_UserProfile_birthday" object="${userprofile}" z="3zJIeeX+VM4O6m3wIyeNoqvtHKQ="/>
<field:display field="enabled" id="s_org_gitorious_jcryptionspring_sample_domain_UserProfile_enabled" object="${userprofile}" z="dzNuSwR1lQC7qcYC0iKA31AgDsQ="/>
<field:display field="preferredColor" id="s_org_gitorious_jcryptionspring_sample_domain_UserProfile_preferredColor" object="${userprofile}" z="0xfbzO0WPa2SeM9nGnNZNTYaIgk="/>
<field:display field="colors" id="s_org_gitorious_jcryptionspring_sample_domain_UserProfile_colors" object="${userprofile}" z="Lz5cFNKmIs+JFYg+0iw+UmoY3cU="/>
</page:show>
</div>
8 changes: 4 additions & 4 deletions src/main/webapp/WEB-INF/views/userprofiles/update.jspx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<div xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>

<spring:url value="/EncryptionServlet?generateKeypair=true" var="getKeysURL"/>
<script>
<spring:url value="/EncryptionServlet?generateKeypair=true" var="getKeysURL"/>
<script>
/*<![CDATA[ */
$(function() {
Expand All @@ -14,12 +13,13 @@ $("#userProfile").jCryption({getKeysURL:"${getKeysURL}"});
});
/*]]>*/
</script>

<form:update id="fu_org_gitorious_jcryptionspring_sample_domain_UserProfile" modelAttribute="userProfile" path="/userprofiles" versionField="Version" z="TLmc3Nl+vH2+Iaue/WIPhc3/a74=">
<field:input field="email" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_email" validationMessageCode="field_invalid_email" z="g/pHIsPdXrkuGl89tswySDaxAMk="/>
<field:input field="name" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_name" z="9GKjR4Uuw0GRhqouZj6lRNLICmM="/>
<field:input field="surname" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_surname" z="qNuTmj7w7sl3W11eCb05lM62dls="/>
<field:datetime dateTimePattern="${userProfile_birthday_date_format}" field="birthday" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_birthday" z="bCZgN5NDcI1LqP03lTNhFBoRr3k="/>
<field:checkbox field="enabled" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_enabled" z="4h8Kl4k0Q0olaPZ8OmYX5htEToE="/>
<field:select field="preferredColor" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_preferredColor" items="${colorses}" path="colorses" z="DRwBnAFnEFJiMeQ/UjozIdZBnAY="/>
<field:select multiple="true" field="colors" id="c_org_gitorious_jcryptionspring_sample_domain_UserProfile_colors" items="${colorses}" path="colorses" z="BOqMhOneKmMfSzXjTOqsU6c0N/Q="/>
</form:update>
</div>
Loading

0 comments on commit 2d294d1

Please sign in to comment.