[seam-commits] Seam SVN: r7403 - in trunk/examples/seamspace: src/org/jboss/seam/example/seamspace and 3 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sat Feb 9 00:21:59 EST 2008
Author: shane.bryzak at jboss.com
Date: 2008-02-09 00:21:59 -0500 (Sat, 09 Feb 2008)
New Revision: 7403
Added:
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleAction.java
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleSearch.java
trunk/examples/seamspace/view/images/btn_newrole.png
trunk/examples/seamspace/view/roledetail.xhtml
trunk/examples/seamspace/view/rolemanager.xhtml
Modified:
trunk/examples/seamspace/resources/WEB-INF/pages.xml
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserSearch.java
trunk/examples/seamspace/view/register2.xhtml
trunk/examples/seamspace/view/style/seamspace.css
trunk/examples/seamspace/view/userdetail.xhtml
trunk/examples/seamspace/view/usermanager.xhtml
Log:
role management, updated to work with api changes
Modified: trunk/examples/seamspace/resources/WEB-INF/pages.xml
===================================================================
--- trunk/examples/seamspace/resources/WEB-INF/pages.xml 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/resources/WEB-INF/pages.xml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
login-view-id="/home.xhtml">
- <page view-id="/home.xhtml">
+ <page view-id="/home.xhtml" action="#{identity.logout}">
<navigation from-action="#{identity.login}">
<rule if-outcome="loggedIn">
<redirect view-id="/profile.xhtml"/>
@@ -73,14 +73,34 @@
</navigation>
</page>
+ <page view-id="/rolemanager.xhtml" action="#{roleSearch.loadRoles}">
+ <restrict>#{s:hasPermission('seam.account', 'read', null)}</restrict>
+
+ <navigation from-action="#{roleAction.createRole}">
+ <redirect view-id="/roledetail.xhtml"/>
+ </navigation>
+
+ <navigation from-action="#{roleAction.editRole(roleSearch.selectedRole)}">
+ <redirect view-id="/roledetail.xhtml"/>
+ </navigation>
+ </page>
+
<page view-id="/userdetail.xhtml">
<navigation from-action="#{userAction.save}">
<rule if-outcome="success">
- <redirect view-id="/usermanager.xhtml"/>
+ <redirect view-id="/usermanager.xhtml"/>
</rule>
</navigation>
</page>
+ <page view-id="/roledetail.xhtml">
+ <navigation from-action="#{roleAction.save}">
+ <rule if-outcome="success">
+ <redirect view-id="/rolemanager.xhtml"/>
+ </rule>
+ </navigation>
+ </page>
+
<page view-id="/profile.xhtml">
<param name="name" value="#{selectedMember.memberName}"/>
@@ -111,9 +131,9 @@
</page>
<page view-id="*">
- <navigation from-action="#{identity.logout}">
+ <!--navigation from-action="#{identity.logout}">
<redirect view-id="/home.xhtml"/>
- </navigation>
+ </navigation-->
<navigation from-action="#{blog.createComment}">
<redirect view-id="/comment.xhtml"/>
@@ -124,11 +144,11 @@
</navigation>
</page>
- <exception class="org.jboss.seam.security.NotLoggedInException" log="false">
+ <!--exception class="org.jboss.seam.security.NotLoggedInException" log="false">
<redirect view-id="/register.xhtml">
<message severity="warn">You must be a member to use this feature</message>
</redirect>
- </exception>
+ </exception-->
<!--exception class="org.jboss.seam.security.AuthorizationException">
<end-conversation/>
Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java 2008-02-09 05:21:59 UTC (rev 7403)
@@ -52,6 +52,7 @@
private byte[] picture;
private String pictureContentType;
+ private String pictureFileName;
private boolean verified;
@@ -109,7 +110,7 @@
}
public void execute() {
- identityManager.createAccount(username, password);
+ identityManager.createUser(username, password);
identityManager.grantRole(username, "user");
}
}.run();
@@ -195,6 +196,16 @@
this.pictureContentType = contentType;
}
+ public String getPictureFileName()
+ {
+ return pictureFileName;
+ }
+
+ public void setPictureFileName(String filename)
+ {
+ this.pictureFileName = filename;
+ }
+
public boolean isVerified()
{
return verified;
Added: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleAction.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleAction.java (rev 0)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleAction.java 2008-02-09 05:21:59 UTC (rev 7403)
@@ -0,0 +1,106 @@
+package org.jboss.seam.example.seamspace;
+
+import static org.jboss.seam.ScopeType.CONVERSATION;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.annotations.Begin;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Conversation;
+import org.jboss.seam.security.management.IdentityManager;
+
+ at Name("roleAction")
+ at Scope(CONVERSATION)
+public class RoleAction
+{
+ private String role;
+ private List<String> memberships;
+
+ @In IdentityManager identityManager;
+
+ @Begin
+ public void createRole()
+ {
+ memberships = new ArrayList<String>();
+ }
+
+ @Begin
+ public void editRole(String role)
+ {
+ this.role = role;
+ memberships = identityManager.getGrantedRoles(role);
+ }
+
+ public String save()
+ {
+ if (identityManager.roleExists(role))
+ {
+ return saveExistingRole();
+ }
+ else
+ {
+ return saveNewRole();
+ }
+ }
+
+ private String saveNewRole()
+ {
+ boolean success = identityManager.createRole(role);
+
+ if (success)
+ {
+ for (String r : memberships)
+ {
+ identityManager.grantRole(role, r);
+ }
+
+ Conversation.instance().end();
+ }
+
+ return "success";
+ }
+
+ private String saveExistingRole()
+ {
+ List<String> grantedRoles = identityManager.getGrantedRoles(role);
+
+ if (grantedRoles != null)
+ {
+ for (String r : grantedRoles)
+ {
+ if (!memberships.contains(r)) identityManager.revokeRole(role, r);
+ }
+ }
+
+ for (String r : memberships)
+ {
+ if (grantedRoles == null || !grantedRoles.contains(r)) identityManager.grantRole(role, r);
+ }
+
+ Conversation.instance().end();
+ return "success";
+ }
+
+ public String getRole()
+ {
+ return role;
+ }
+
+ public void setRole(String role)
+ {
+ this.role = role;
+ }
+
+ public List<String> getMemberships()
+ {
+ return memberships;
+ }
+
+ public void setMemberships(List<String> memberships)
+ {
+ this.memberships = memberships;
+ }
+}
\ No newline at end of file
Added: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleSearch.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleSearch.java (rev 0)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RoleSearch.java 2008-02-09 05:21:59 UTC (rev 7403)
@@ -0,0 +1,52 @@
+package org.jboss.seam.example.seamspace;
+
+import static org.jboss.seam.ScopeType.SESSION;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.datamodel.DataModel;
+import org.jboss.seam.annotations.datamodel.DataModelSelection;
+import org.jboss.seam.security.management.IdentityManager;
+
+ at Name("roleSearch")
+ at Scope(SESSION)
+public class RoleSearch implements Serializable
+{
+ @DataModel
+ List<String> roles;
+
+ @DataModelSelection
+ String selectedRole;
+
+ @In IdentityManager identityManager;
+
+ public void loadRoles()
+ {
+ roles = identityManager.listRoles();
+ }
+
+ public String getRoleMemberships(String role)
+ {
+ List<String> roles = identityManager.getGrantedRoles(role);
+
+ if (roles == null) return "";
+
+ StringBuilder sb = new StringBuilder();
+
+ for (String r : roles)
+ {
+ sb.append((sb.length() > 0 ? ", " : "") + r);
+ }
+
+ return sb.toString();
+ }
+
+ public String getSelectedRole()
+ {
+ return selectedRole;
+ }
+}
\ No newline at end of file
Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java 2008-02-09 05:21:59 UTC (rev 7403)
@@ -36,12 +36,12 @@
{
this.username = username;
roles = identityManager.getGrantedRoles(username);
- enabled = identityManager.isEnabled(username);
+ enabled = identityManager.isUserEnabled(username);
}
public String save()
{
- if (identityManager.accountExists(username))
+ if (identityManager.userExists(username))
{
return saveExistingUser();
}
@@ -59,7 +59,7 @@
return "failure";
}
- boolean success = identityManager.createAccount(username, password);
+ boolean success = identityManager.createUser(username, password);
if (success)
{
@@ -70,7 +70,7 @@
if (!enabled)
{
- identityManager.disableAccount(username);
+ identityManager.disableUser(username);
}
Conversation.instance().end();
@@ -97,23 +97,29 @@
List<String> grantedRoles = identityManager.getGrantedRoles(username);
- for (String role : grantedRoles)
+ if (grantedRoles != null)
{
- if (!roles.contains(role)) identityManager.revokeRole(username, role);
+ for (String role : grantedRoles)
+ {
+ if (!roles.contains(role)) identityManager.revokeRole(username, role);
+ }
}
for (String role : roles)
{
- if (!grantedRoles.contains(role)) identityManager.grantRole(username, role);
+ if (grantedRoles == null || !grantedRoles.contains(role))
+ {
+ identityManager.grantRole(username, role);
+ }
}
if (enabled)
{
- identityManager.enableAccount(username);
+ identityManager.enableUser(username);
}
else
{
- identityManager.disableAccount(username);
+ identityManager.disableUser(username);
}
Conversation.instance().end();
Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserSearch.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserSearch.java 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserSearch.java 2008-02-09 05:21:59 UTC (rev 7403)
@@ -34,6 +34,9 @@
public String getUserRoles(String username)
{
List<String> roles = identityManager.getGrantedRoles(username);
+
+ if (roles == null) return "";
+
StringBuilder sb = new StringBuilder();
for (String role : roles)
Added: trunk/examples/seamspace/view/images/btn_newrole.png
===================================================================
(Binary files differ)
Property changes on: trunk/examples/seamspace/view/images/btn_newrole.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/examples/seamspace/view/register2.xhtml
===================================================================
--- trunk/examples/seamspace/view/register2.xhtml 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/view/register2.xhtml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -20,6 +20,7 @@
<div class="formRow">
<h:outputLabel for="picture">Member photo</h:outputLabel>
<s:fileUpload id="picture" data="#{register.picture}" accept="image/png"
+ fileName="#{register.pictureFileName}"
contentType="#{register.pictureContentType}" />
<div class="validationError"><h:message for="picture"/></div>
</div>
Added: trunk/examples/seamspace/view/roledetail.xhtml
===================================================================
--- trunk/examples/seamspace/view/roledetail.xhtml (rev 0)
+++ trunk/examples/seamspace/view/roledetail.xhtml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -0,0 +1,51 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<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:rich="http://richfaces.org/rich"
+ xmlns:s="http://jboss.com/products/seam/taglib">
+
+ <ui:composition template="template.xhtml">
+
+ <ui:define name="content">
+
+ <div id="contentMain">
+
+ <h2>Role Details</h2>
+
+ <h:messages globalOnly="true"/>
+
+ <h:form>
+
+ <div class="formRow">
+ <h:outputLabel for="role" value="Role" styleClass="formLabel"/>
+ <h:inputText id="role" value="#{roleAction.role}" readonly="#{identityManager.userExists(roleAction.role)}"/>
+ <div class="validationError"><h:message for="role"/></div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="roles" value="Member of" styleClass="formLabel"/>
+ <div class="selectMany">
+ <h:selectManyCheckbox id="roles" value="#{roleAction.memberships}" layout="pageDirection" styleClass="roles">
+ <s:selectItems value="#{identityManager.listRoles()}" var="role" label="#{role}"/>
+ </h:selectManyCheckbox>
+ </div>
+ <div class="validationError"><h:message for="roles"/></div>
+ </div>
+
+ <div class="formButtons">
+ <h:commandButton value="Save" action="#{roleAction.save}" styleClass="formButton"/>
+ <s:button view="/rolemanager.xhtml" value="Cancel" propagation="end" styleClass="formButton"/>
+ </div>
+
+ <br class="clear"/>
+
+ </h:form>
+
+ </div>
+
+ </ui:define>
+
+ </ui:composition>
+</html>
Added: trunk/examples/seamspace/view/rolemanager.xhtml
===================================================================
--- trunk/examples/seamspace/view/rolemanager.xhtml (rev 0)
+++ trunk/examples/seamspace/view/rolemanager.xhtml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<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:rich="http://richfaces.org/rich"
+ xmlns:s="http://jboss.com/products/seam/taglib">
+
+ <ui:composition template="template.xhtml">
+
+ <ui:define name="content">
+
+ <script type="text/javascript">
+ function confirmDelete()
+ {
+ return confirm("Are you sure you wish to delete this role? This action cannot be undone.");
+ }
+ </script>
+
+ <div id="contentMain">
+
+ <h2>Role Manager</h2>
+
+ <s:button action="#{roleAction.createRole}" styleClass="newrole" rendered="#{s:hasPermission('seam.account', 'create', null)}"/>
+ <s:link view="/usermanager.xhtml" value="--> Manage Users" propagation="none"/>
+
+ <rich:dataTable
+ id="threads"
+ value="#{roles}"
+ var="role"
+ styleClass="default"
+ columnClasses=",,enabled,action">
+ <f:facet name="header">
+ <rich:columnGroup>
+ <rich:column width="auto">
+ User name
+ </rich:column>
+ <rich:column width="auto">
+ Member Of
+ </rich:column>
+ <rich:column width="auto">
+ Action
+ </rich:column>
+ </rich:columnGroup>
+ </f:facet>
+ <rich:column width="auto">
+ #{role}
+ </rich:column>
+ <rich:column width="auto">
+ #{roleSearch.getRoleMemberships(role)}
+ </rich:column>
+ <rich:column width="auto">
+ <s:fragment rendered="#{s:hasPermission('seam.account', 'update', null)}">
+ <s:link value="Edit" action="#{roleAction.editRole(roleSearch.selectedRole)}"/><span> | </span>
+ </s:fragment>
+ <s:link value="Delete" action="#{identityManager.deleteAccount(roleSearch.selectedRole)}"
+ rendered="#{s:hasPermission('seam.account', 'delete', null)}"
+ onclick="return confirmDelete()"/>
+ </rich:column>
+ </rich:dataTable>
+ </div>
+
+ </ui:define>
+
+ </ui:composition>
+</html>
Modified: trunk/examples/seamspace/view/style/seamspace.css
===================================================================
--- trunk/examples/seamspace/view/style/seamspace.css 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/view/style/seamspace.css 2008-02-09 05:21:59 UTC (rev 7403)
@@ -509,6 +509,15 @@
cursor: pointer;
}
+input.newrole {
+ background: url(../images/btn_newrole.png) top left no-repeat;
+ height: 24px;
+ width: 80px;
+ margin: 4px 4px 4px 4px;
+ border: 0px;
+ cursor: pointer;
+}
+
/* General form styles */
div.formRow {
Modified: trunk/examples/seamspace/view/userdetail.xhtml
===================================================================
--- trunk/examples/seamspace/view/userdetail.xhtml 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/view/userdetail.xhtml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -20,7 +20,7 @@
<div class="formRow">
<h:outputLabel for="username" value="Username" styleClass="formLabel"/>
- <h:inputText id="username" value="#{userAction.username}" readonly="#{identityManager.accountExists(userAction.username)}"/>
+ <h:inputText id="username" value="#{userAction.username}" readonly="#{identityManager.userExists(userAction.username)}"/>
<div class="validationError"><h:message for="username"/></div>
</div>
Modified: trunk/examples/seamspace/view/usermanager.xhtml
===================================================================
--- trunk/examples/seamspace/view/usermanager.xhtml 2008-02-09 05:21:07 UTC (rev 7402)
+++ trunk/examples/seamspace/view/usermanager.xhtml 2008-02-09 05:21:59 UTC (rev 7403)
@@ -22,6 +22,7 @@
<h2>User Manager</h2>
<s:button action="#{userAction.createUser}" styleClass="newuser" rendered="#{s:hasPermission('seam.account', 'create', null)}"/>
+ <s:link view="/rolemanager.xhtml" value="--> Manage Roles" propagation="none"/>
<rich:dataTable
id="threads"
@@ -52,7 +53,7 @@
#{userSearch.getUserRoles(user)}
</rich:column>
<rich:column width="auto">
- <div class="#{identityManager.isEnabled(user) ? 'checkmark' : 'cross'}"/>
+ <div class="#{identityManager.isUserEnabled(user) ? 'checkmark' : 'cross'}"/>
</rich:column>
<rich:column width="auto">
<s:fragment rendered="#{s:hasPermission('seam.account', 'update', null)}">
More information about the seam-commits
mailing list