This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
231 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
src/main/java/org/gitorious/jcryptionspring/sample/domain/UserProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/org/gitorious/jcryptionspring/sample/web/UserProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.