Author: shane.bryzak(a)jboss.com
Date: 2009-05-18 20:35:56 -0400 (Mon, 18 May 2009)
New Revision: 10931
Added:
examples/trunk/seamspace/ejb-jar/src/main/java/org/jboss/seam/example/seamspace/HashGenerator.java
Modified:
examples/trunk/seamspace/war/src/main/webapp/hashgen.xhtml
examples/trunk/seamspace/war/src/main/webapp/home.xhtml
examples/trunk/seamspace/war/src/main/webapp/profile.xhtml
examples/trunk/seamspace/war/src/main/webapp/template.xhtml
Log:
fix hash generator page
Added:
examples/trunk/seamspace/ejb-jar/src/main/java/org/jboss/seam/example/seamspace/HashGenerator.java
===================================================================
---
examples/trunk/seamspace/ejb-jar/src/main/java/org/jboss/seam/example/seamspace/HashGenerator.java
(rev 0)
+++
examples/trunk/seamspace/ejb-jar/src/main/java/org/jboss/seam/example/seamspace/HashGenerator.java 2009-05-19
00:35:56 UTC (rev 10931)
@@ -0,0 +1,79 @@
+package org.jboss.seam.example.seamspace;
+
+import javax.annotation.Named;
+import javax.context.RequestScoped;
+import javax.inject.Current;
+
+import org.jboss.seam.security.crypto.BinTools;
+import org.jboss.seam.security.management.JpaIdentityStore;
+import org.jboss.seam.security.management.PasswordHash;
+
+@Named
+@RequestScoped
+public class HashGenerator
+{
+ @Current JpaIdentityStore identityStore;
+ @Current PasswordHash passwordHash;
+
+ private String password;
+ private String hash;
+ private String passwordSalt;
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public String getHash()
+ {
+ return hash;
+ }
+
+ public void setHash(String hash)
+ {
+ this.hash = hash;
+ }
+
+ public String getPasswordSalt()
+ {
+ return passwordSalt;
+ }
+
+ public void setPasswordSalt(String passwordSalt)
+ {
+ this.passwordSalt = passwordSalt;
+ }
+
+ public void generate()
+ {
+ byte[] salt;
+
+ if (passwordSalt == null || "".equals(passwordSalt.trim()))
+ {
+ salt = passwordHash.generateRandomSalt();
+ passwordSalt = BinTools.bin2hex(salt);
+ }
+ else
+ {
+ salt = BinTools.hex2bin(passwordSalt);
+ }
+
+ hash = identityStore.generatePasswordHash(password, salt);
+ }
+
+ public String getSql()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("INSERT INTO USER_ACCOUNT (username, password_hash, password_salt)
values ('johnsmith', '");
+ sb.append(hash);
+ sb.append("', '");
+ sb.append(passwordSalt);
+ sb.append("');");
+ return sb.toString();
+ }
+}
Modified: examples/trunk/seamspace/war/src/main/webapp/hashgen.xhtml
===================================================================
--- examples/trunk/seamspace/war/src/main/webapp/hashgen.xhtml 2009-05-18 18:14:36 UTC
(rev 10930)
+++ examples/trunk/seamspace/war/src/main/webapp/hashgen.xhtml 2009-05-19 00:35:56 UTC
(rev 10931)
@@ -22,26 +22,26 @@
<div class="formRow">
<h:outputLabel for="password">Enter a
password</h:outputLabel>
- <h:inputText id="password"
value="#{hashgenerator.password}" required="true"
styleClass="wide"/>
+ <h:inputText id="password"
value="#{hashGenerator.password}" required="true"
styleClass="wide"/>
<div class="validationError"><h:message
for="password"/></div>
</div>
<div class="formRow">
<h:outputLabel for="salt">Password salt</h:outputLabel>
- <h:inputText id="salt"
value="#{hashgenerator.passwordSalt}" required="false"
styleClass="wide"/>
+ <h:inputText id="salt"
value="#{hashGenerator.passwordSalt}" required="false"
styleClass="wide"/>
<span>(Leave blank to generate a random salt)</span>
<div class="validationError"><h:message
for="salt"/></div>
</div>
- <h:commandButton action="#{hashgenerator.generate}"
value="Generate hash"/>
+ <h:commandButton action="#{hashGenerator.generate}"
value="Generate hash"/>
</h:form>
<h2>Results</h2>
- <div>Generated hash (hex encoded):
<pre>#{hashgenerator.passwordHash}</pre></div>
+ <div>Generated hash (hex encoded):
<pre>#{hashGenerator.hash}</pre></div>
- <div>Example SQL:<br/><textarea
style="width:640px;height:50px">#{hashgenerator.sql}</textarea></div>
+ <div>Example SQL:<br/><textarea
style="width:640px;height:50px">#{hashGenerator.sql}</textarea></div>
</ui:define>
Modified: examples/trunk/seamspace/war/src/main/webapp/home.xhtml
===================================================================
--- examples/trunk/seamspace/war/src/main/webapp/home.xhtml 2009-05-18 18:14:36 UTC (rev
10930)
+++ examples/trunk/seamspace/war/src/main/webapp/home.xhtml 2009-05-19 00:35:56 UTC (rev
10931)
@@ -14,7 +14,7 @@
been put together to demonstrate the various features of the Seam Security
API.
</p>
- <p><b>New!</b> You can now use the <h:link
view="/hashgen.xhtml" value="Password Hash Generator"/>
+ <p><b>New!</b> You can now use the <h:link
outcome="/hashgen.xhtml" value="Password Hash Generator"/>
page to generate password hashes for your own application.
</p>
Modified: examples/trunk/seamspace/war/src/main/webapp/profile.xhtml
===================================================================
--- examples/trunk/seamspace/war/src/main/webapp/profile.xhtml 2009-05-18 18:14:36 UTC
(rev 10930)
+++ examples/trunk/seamspace/war/src/main/webapp/profile.xhtml 2009-05-19 00:35:56 UTC
(rev 10931)
@@ -2,115 +2,119 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:s="http://jboss.com/products/seam/taglib">
+
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="template.xhtml">
<ui:define name="content">
<div class="errors"><h:messages
globalOnly="true"/></div>
- <s:div rendered="#{selectedMember == null}">
- Sorry, but this member does not exist.
- </s:div>
+ <ui:fragment rendered="#{selectedMember == null}">
+ <div>Sorry, but this member does not exist.</div>
+ </ui:fragment>
- <s:div rendered="#{selectedMember != null}">
-
- <s:div id="memberCard">
- <h1>#{selectedMember.memberName}'s profile</h1>
-
- <s:div id="memberCardPicture"
rendered="#{selectedMember.picture ne null}">
- <h:graphicImage
value="/content/images?id=#{selectedMember.picture.imageId}&width=170"/>
- </s:div>
+ <ui:fragment rendered="#{selectedMember != null}">
+ <div>
+ <div id="memberCard">
+ <h1>#{selectedMember.memberName}'s profile</h1>
+
+ <ui:fragment rendered="#{selectedMember.picture ne null}">
+ <div id="memberCardPicture">
+ <h:graphicImage
value="/content/images?id=#{selectedMember.picture.imageId}&width=170"/>
+ </div>
+ </ui:fragment>
- <div id="memberCardText">
- <span
class="tagline">"#{selectedMember.tagline}"</span><br/><br/>
- #{selectedMember.gender.descr}<br/>
- #{selectedMember.age}<br/>
- #{selectedMember.location}<br/>
- </div>
+ <div id="memberCardText">
+ <span
class="tagline">"#{selectedMember.tagline}"</span><br/><br/>
+ #{selectedMember.gender.descr}<br/>
+ #{selectedMember.age}<br/>
+ #{selectedMember.location}<br/>
+ </div>
- <br style="clear:both"/>
+ <br style="clear:both"/>
- View My:
- <s:link view="/pictures.xhtml" value="Pics">
- <f:param name="name"
value="#{selectedMember.memberName}"/>
- </s:link>
-
- </s:div>
+ View My:
+ <h:link outcome="/pictures.xhtml" value="Pics">
+ <f:param name="name"
value="#{selectedMember.memberName}"/>
+ </h:link>
+ </div>
- <s:div id="memberBlog">
- <div class="sectionHeader">#{selectedMember.memberName}'s
latest blog entries</div>
+ <div id="memberBlog">
+ <div class="sectionHeader">#{selectedMember.memberName}'s
latest blog entries</div>
- <ui:repeat value="#{profile.latestBlogs}"
var="latestBlog">
- <div class="blogSummary">#{latestBlog.title}
- (<s:link view="/blogentry.seam" value="view
more">
- <f:param name="name"
value="#{selectedMember.memberName}"/>
- <f:param name="blogId"
value="#{latestBlog.blogId}"/>
- </s:link>)
- </div>
- </ui:repeat>
+ <ui:repeat value="#{profile.latestBlogs}"
var="latestBlog">
+ <div class="blogSummary">#{latestBlog.title}
+ (<h:link outcome="/blogentry.seam" value="view
more">
+ <f:param name="name"
value="#{selectedMember.memberName}"/>
+ <f:param name="blogId"
value="#{latestBlog.blogId}"/>
+ </h:link>)
+ </div>
+ </ui:repeat>
- [<s:link id="viewBlog" view="/blog.seam"
value="View all blog entries" propagation="none">
- <f:param name="name"
value="#{selectedMember.memberName}"/>
- </s:link>]
+ [<h:link id="viewBlog" outcome="/blog.seam"
value="View all blog entries" propagation="none">
+ <f:param name="name"
value="#{selectedMember.memberName}"/>
+ </h:link>]
- <s:span rendered="#{s:hasPermission(selectedMember,
'createBlog')}">
- [<s:link id="createBlog" action="#{blog.createEntry}"
value="Create new blog entry" propagation="none"/>]
- </s:span>
- </s:div>
+ <ui:fragment rendered="#{identity.hasPermission(selectedMember,
'createBlog')}">
+ <span>
+ [<h:link id="createBlog"
action="#{blog.createEntry}" value="Create new blog entry"
propagation="none"/>]
+ </span>
+ </ui:fragment>
+ </div>
- <s:div id="memberFriends">
- <div class="sectionHeader">#{selectedMember.memberName}'s
friends</div>
+ <div id="memberFriends">
+ <div class="sectionHeader">#{selectedMember.memberName}'s
friends</div>
+
+ <ui:repeat value="#{profile.friends}" var="f">
+ <div class="friend">
+ <h:link outcome="/profile.seam"
propagation="none">
+ <f:param name="name"
value="#{f.memberName}"/>
+ #{f.memberName}<br/>
+ <h:graphicImage
value="/content/images?id=#{f.picture.imageId}&width=90"/>
+ </h:link>
+ </div>
+ </ui:repeat>
+
+ <br class="clear"/>
- <ui:repeat value="#{profile.friends}" var="f">
- <div class="friend">
-
- <s:link view="/profile.seam" propagation="none">
- <f:param name="name" value="#{f.memberName}"/>
- #{f.memberName}<br/>
- <h:graphicImage
value="/content/images?id=#{f.picture.imageId}&width=90"/>
- </s:link>
-
- </div>
- </ui:repeat>
-
- <br class="clear"/>
+ <ui:fragment rendered="#{selectedMember.memberId !=
authenticatedMember.memberId and identity.hasPermission(selectedMember,
'createFriendRequest')}">
+ <span>
+ [<h:link outcome="/friendrequest.seam" value="Send a
friend request" propagation="none"/>]
+ </span>
+ </ui:fragment>
+ </div>
- <s:span rendered="#{selectedMember.memberId !=
authenticatedMember.memberId and s:hasPermission(selectedMember,
'createFriendRequest')}">
- [<s:link view="/friendrequest.seam" value="Send a friend
request" propagation="none"/>]
- </s:span>
+ <div id="friendComments">
+ <div class="sectionHeader">#{selectedMember.memberName}'s
friend's comments</div>
+
+ <ui:repeat value="#{profile.friendComments}"
var="c">
+ <table class="friendComments">
+ <tr>
+ <td class="friendCommentor">
+ <h:link outcome="/profile.seam">
+ <f:param name="name"
value="#{c.friend.memberName}"/>
+ #{c.friend.memberName}<br/>
+ <h:graphicImage
value="/content/images?id=#{c.friend.picture.imageId}&width=90"/>
+ </h:link>
+ </td>
+
+ <td style="text-align: left">
+ <b>#{c.formattedCommentDate}</b><br/>
+ <p><h:outputText
value="#{c.comment}"/></p>
+ </td>
+ </tr>
+ </table>
+ </ui:repeat>
+
+ <ui:fragment rendered="#{identity.hasPermission(selectedMember,
'createFriendComment')}">
+ <span>
+ [<h:link outcome="/friendcomment.seam" value="Add
Comment"/>]
+ </span>
+ </ui:fragment>
+ </div>
+ </div>
+ </ui:fragment>
- </s:div>
-
- <s:div id="friendComments">
- <div class="sectionHeader">#{selectedMember.memberName}'s
friend's comments</div>
-
- <ui:repeat value="#{profile.friendComments}" var="c">
- <table class="friendComments">
- <tr>
- <td class="friendCommentor">
- <s:link view="/profile.seam">
- <f:param name="name"
value="#{c.friend.memberName}"/>
- #{c.friend.memberName}<br/>
- <h:graphicImage
value="/content/images?id=#{c.friend.picture.imageId}&width=90"/>
- </s:link>
- </td>
-
- <td style="text-align: left">
- <b>#{c.formattedCommentDate}</b><br/>
- <p><s:formattedText
value="#{c.comment}"/></p>
- </td>
- </tr>
- </table>
- </ui:repeat>
-
- <s:span rendered="#{s:hasPermission(selectedMember,
'createFriendComment')}">
- [<s:link view="/friendcomment.seam" value="Add
Comment"/>]
- </s:span>
- </s:div>
- </s:div>
-
</ui:define>
</ui:composition>
Modified: examples/trunk/seamspace/war/src/main/webapp/template.xhtml
===================================================================
--- examples/trunk/seamspace/war/src/main/webapp/template.xhtml 2009-05-18 18:14:36 UTC
(rev 10930)
+++ examples/trunk/seamspace/war/src/main/webapp/template.xhtml 2009-05-19 00:35:56 UTC
(rev 10931)
@@ -19,14 +19,14 @@
<div class="headerMenu">
<ui:fragment rendered="#{identity.loggedIn}">
- <h:link id="profile" view="/profile.xhtml"
value="My Profile" propagation="none">
+ <h:link id="profile" outcome="/profile.xhtml"
value="My Profile" propagation="none">
<f:param name="name"
value="#{authenticatedMember.memberName}"/>
</h:link>
<h:outputText styleClass="divider" value=" | "/>
</ui:fragment>
<ui:fragment rendered="#{identity.hasRole('admin')}">
- <h:link id="security" view="/security.xhtml"
value="Security" propagation="none"/>
+ <h:link id="security" outcome="/security.xhtml"
value="Security" propagation="none"/>
<h:outputText styleClass="divider" value=" | "/>
</ui:fragment>
@@ -50,7 +50,7 @@
</div>
<div id="menubar">
- <h:link view="/home.xhtml" value="Home"
propagation="none"/><h:outputText styleClass="divider"
value=" | "/>
+ <h:link outcome="/home.xhtml" value="Home"
propagation="none"/><h:outputText styleClass="divider"
value=" | "/>
<h:link value="Browse" onclick="javascript:alert('This feature
coming soon!');return false"/><h:outputText styleClass="divider"
value=" | "/>
<h:link value="Blog" onclick="javascript:alert('This feature
coming soon!');return false"/><h:outputText styleClass="divider"
value=" | "/>
<h:link value="Music" onclick="javascript:alert('This feature
coming soon!');return false"/>