Author: shane.bryzak(a)jboss.com
Date: 2010-07-22 04:12:29 -0400 (Thu, 22 Jul 2010)
New Revision: 13471
Added:
modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml
Modified:
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml
modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java
Log:
add infrastructure for user role management (implementation not complete yet)
Modified:
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml
===================================================================
---
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-07-22
08:01:55 UTC (rev 13470)
+++
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-07-22
08:12:29 UTC (rev 13471)
@@ -45,7 +45,7 @@
<plidm:identityClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObject</plidm:identityClass>
<plidm:credentialClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObjectCredential</plidm:credentialClass>
<plidm:relationshipClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObjectRelationship</plidm:relationshipClass>
-
<plidm:roleNameClass>org.jboss.seam.security.examples.idmconsole.model.IdentityRoleName</plidm:roleNameClass>
+
<plidm:roleTypeClass>org.jboss.seam.security.examples.idmconsole.model.IdentityRoleName</plidm:roleTypeClass>
</plidm:JpaIdentityStoreConfiguration>
</beans>
Modified:
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml 2010-07-22
08:01:55 UTC (rev 13470)
+++
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml 2010-07-22
08:12:29 UTC (rev 13471)
@@ -49,9 +49,34 @@
<to-view-id>/manageusers.xhtml</to-view-id>
<redirect/>
</navigation-case>
+
+ <navigation-case>
+ <from-action>#{userAction.addRole}</from-action>
+ <if>#{true}</if>
+ <to-view-id>/roledetail.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
</navigation-rule>
<navigation-rule>
+ <from-view-id>/roledetail.xhtml</from-view-id>
+
+ <navigation-case>
+ <from-action>#{userAction.roleSave}</from-action>
+ <from-outcome>success</from-outcome>
+ <if>#{true}</if>
+ <to-view-id>/userdetail.xhtml</to-view-id>
+ <redirect />
+ </navigation-case>
+
+ <navigation-case>
+ <from-outcome>cancel</from-outcome>
+ <to-view-id>/userdetail.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
+ </navigation-rule>
+
+ <navigation-rule>
<from-view-id>/managegroups.xhtml</from-view-id>
<navigation-case>
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml 2010-07-22
08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml 2010-07-22
08:12:29 UTC (rev 13471)
@@ -31,7 +31,10 @@
<div class="buttons">
<h:commandButton id="login" value="LOGIN"
action="#{identity.login}" styleClass="loginButton"/>
- </div>
+ </div>
+
+ Tip: you can login with a username/password of demo/demo.
+
</h:form>
<br style="clear:both"/>
Added: modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml
(rev 0)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml 2010-07-22
08:12:29 UTC (rev 13471)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html"
+ template="/WEB-INF/templates/default.xhtml">
+
+ <ui:define name="sidebar">
+ <ui:include src="menu.xhtml"/>
+ </ui:define>
+
+ <ui:define name="content">
+
+ <div id="contentMain">
+
+ <h2>Add New Role</h2>
+
+ <h:messages globalOnly="true"/>
+
+ <h:form id="role">
+
+ <div class="formRow">
+ <h:outputLabel for="roleType" value="Role type"
styleClass="formLabel"/>
+ <h:selectOneMenu value="#{userAction.roleType}">
+ <f:selectItems value="#{userAction.roleTypes}"
var="roleType" itemLabel="#{roleType.name}"/>
+ </h:selectOneMenu>
+ <div class="validationError"><h:message
for="roleType"/></div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="roleGroup" value="Role group"
styleClass="formLabel"/>
+ <h:inputText id="roleGroup"
value="#{userAction.roleGroupName}"/>
+ <div class="validationError"><h:message
for="roleGroup"/></div>
+ </div>
+
+ <div class="formButtons">
+ <h:commandButton id="add" value="Add role"
action="#{userAction.roleSave}" styleClass="formButton"/>
+ <h:button id="cancel" value="Cancel"
outcome="cancel" styleClass="formButton"/>
+ </div>
+
+ <br class="clear"/>
+
+ </h:form>
+
+ </div>
+
+ </ui:define>
+
+</ui:composition>
+
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml 2010-07-22
08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml 2010-07-22
08:12:29 UTC (rev 13471)
@@ -46,21 +46,26 @@
<div class="formRow">
<h:outputLabel for="confirm" value="Confirm password"
styleClass="formLabel"/>
<h:inputSecret id="confirm"
value="#{userAction.confirm}"/>
- </div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="enabled" value="Account enabled"
styleClass="formLabel"/>
+ <h:selectBooleanCheckbox id="enabled"
value="#{userAction.enabled}"/>
+ </div>
+ <h4>Role Memberships</h4>
+
<div class="formRow">
<h:outputLabel value="Member of"
styleClass="formLabel"/>
<ui:repeat value="#{userAction.roles}" var="role">
#{role.roleType.name}<span> in group
</span>#{role.group.name}<br/>
</ui:repeat>
-
</div>
- <div class="formRow">
- <h:outputLabel for="enabled" value="Account enabled"
styleClass="formLabel"/>
- <h:selectBooleanCheckbox id="enabled"
value="#{userAction.enabled}"/>
- </div>
-
+ <div>
+ <h:commandButton id="addRole" value="Add new role"
action="#{userAction.addRole}" styleClass="formButton"/>
+ </div>
+
<div class="formButtons">
<h:commandButton id="save" value="Save"
action="#{userAction.save}" styleClass="formButton"/>
<h:commandButton id="cancel" value="Cancel"
action="#{userAction.cancel}" styleClass="formButton"/>
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-22
08:01:55 UTC (rev 13470)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-22
08:12:29 UTC (rev 13471)
@@ -3,7 +3,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
@@ -13,12 +15,14 @@
import org.jboss.seam.persistence.transaction.Transactional;
import org.jboss.seam.security.UserImpl;
import org.picketlink.idm.api.Attribute;
+import org.picketlink.idm.api.Group;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.Role;
import org.picketlink.idm.api.RoleType;
import org.picketlink.idm.api.User;
import org.picketlink.idm.common.exception.FeatureNotSupportedException;
import org.picketlink.idm.common.exception.IdentityException;
+import org.picketlink.idm.impl.api.model.SimpleRole;
/**
* A conversation-scoped component for creating and managing user accounts
@@ -43,6 +47,13 @@
@Inject IdentitySession identitySession;
@Inject Conversation conversation;
+
+ Map<RoleType, Group> newRoles = new HashMap<RoleType, Group>();
+
+ Collection<RoleType> roleTypes;
+
+ private RoleType roleType;
+ private String roleGroupName;
public void createUser()
{
@@ -72,6 +83,21 @@
newUserFlag = false;
}
+ public void addRole() throws IdentityException, FeatureNotSupportedException
+ {
+ roleTypes = identitySession.getRoleManager().findRoleTypes();
+
+ roleType = null;
+ roleGroupName = null;
+ }
+
+ public String roleSave()
+ {
+ //Role role = new SimpleRole();
+ //roles.add(role);
+ return "success";
+ }
+
public void deleteUser(String username) throws IdentityException
{
identitySession.getPersistenceManager().removeUser(new UserImpl(username), true);
@@ -238,4 +264,34 @@
{
this.enabled = enabled;
}
+
+ public RoleType getRoleType()
+ {
+ return roleType;
+ }
+
+ public void setRoleType(RoleType roleType)
+ {
+ this.roleType = roleType;
+ }
+
+ public String getRoleGroupName()
+ {
+ return roleGroupName;
+ }
+
+ public void setRoleGroupName(String roleGroupName)
+ {
+ this.roleGroupName = roleGroupName;
+ }
+
+ public Collection<RoleType> getRoleTypes()
+ {
+ return roleTypes;
+ }
+
+ public void setRoleTypes(Collection<RoleType> roleTypes)
+ {
+ this.roleTypes = roleTypes;
+ }
}
\ No newline at end of file
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java 2010-07-22
08:01:55 UTC (rev 13470)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java 2010-07-22
08:12:29 UTC (rev 13471)
@@ -67,7 +67,7 @@
public static final String OPTION_IDENTITY_CLASS_NAME =
"identityEntityClassName";
public static final String OPTION_CREDENTIAL_CLASS_NAME =
"credentialEntityClassName";
public static final String OPTION_RELATIONSHIP_CLASS_NAME =
"relationshipEntityClassName";
- public static final String OPTION_ROLE_NAME_CLASS_NAME =
"roleNameEntityClassName";
+ public static final String OPTION_ROLE_TYPE_CLASS_NAME =
"roleTypeEntityClassName";
private static final String DEFAULT_USER_IDENTITY_TYPE = "USER";
private static final String DEFAULT_ROLE_IDENTITY_TYPE = "ROLE";
@@ -92,12 +92,11 @@
private static final String PROPERTY_RELATIONSHIP_TYPE_NAME =
"RELATIONSHIP_TYPE_NAME";
private static final String PROPERTY_RELATIONSHIP_NAME =
"RELATIONSHIP_NAME";
- // Distinct from PROPERTY_RELATIONSHIP NAME - this property refers to the name field
in the RELATIONSHIP_NAME entity
- private static final String PROPERTY_RELATIONSHIP_NAME_NAME =
"RELATIONSHIP_NAME_NAME";
+ private static final String PROPERTY_ROLE_TYPE_NAME =
"RELATIONSHIP_NAME_NAME";
+
private static final String PROPERTY_ATTRIBUTE_NAME = "ATTRIBUTE_NAME";
private static final String PROPERTY_ATTRIBUTE_VALUE = "ATTRIBUTE_VALUE";
- private static final String PROPERTY_ATTRIBUTE_IDENTITY =
"ATTRIBUTE_IDENTITY";
- private static final String PROPERTY_ROLE_TYPE_NAME = "ROLE_TYPE_NAME";
+ private static final String PROPERTY_ATTRIBUTE_IDENTITY =
"ATTRIBUTE_IDENTITY";
private class EntityToSpiConverter
{
@@ -187,7 +186,6 @@
private Class<?> relationshipClass;
private Class<?> attributeClass;
private Class<?> roleTypeClass;
- private Class<?> relationshipNameClass;
private String userIdentityType = DEFAULT_USER_IDENTITY_TYPE;
private String roleIdentityType = DEFAULT_ROLE_IDENTITY_TYPE;
@@ -286,18 +284,18 @@
boolean namedRelationshipsSupported = false;
clsName = configurationContext.getStoreConfigurationMetaData()
- .getOptionSingleValue(OPTION_ROLE_NAME_CLASS_NAME);
+ .getOptionSingleValue(OPTION_ROLE_TYPE_CLASS_NAME);
if (clsName != null)
{
try
{
- relationshipNameClass = Class.forName(clsName);
+ roleTypeClass = Class.forName(clsName);
namedRelationshipsSupported = true;
}
catch (ClassNotFoundException e)
{
- throw new IdentityException("Error bootstrapping JpaIdentityStore -
invalid relationship name entity class: " + clsName);
+ throw new IdentityException("Error bootstrapping JpaIdentityStore -
invalid role type entity class: " + clsName);
}
}
@@ -308,11 +306,10 @@
configureCredentials();
configureRelationships();
configureAttributes();
- configureRoleTypeNames();
if (namedRelationshipsSupported)
{
- configureRelationshipNames();
+ configureRoleTypeName();
}
featuresMetaData = new FeaturesMetaDataImpl(
@@ -961,27 +958,12 @@
}
}
- protected void configureRoleTypeNames()
+ protected void configureRoleTypeName()
{
- if (roleTypeClass != null)
- {
- List<Property<Object>> props =
PropertyQueries.createQuery(roleTypeClass)
- .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
- .getResultList();
-
- if (props.size() == 1)
- {
- modelProperties.put(PROPERTY_ROLE_TYPE_NAME, props.get(0));
- }
- }
- }
-
- protected void configureRelationshipNames()
- {
- Property<Object> relationshipNameProp =
findNamedProperty(relationshipNameClass, "name");
+ Property<Object> relationshipNameProp = findNamedProperty(roleTypeClass,
"name");
if (relationshipNameProp != null)
{
- modelProperties.put(PROPERTY_RELATIONSHIP_NAME_NAME, relationshipNameProp);
+ modelProperties.put(PROPERTY_ROLE_TYPE_NAME, relationshipNameProp);
}
}
@@ -1363,12 +1345,29 @@
}
public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
- IdentityObjectSearchCriteria criteria) throws IdentityException,
+ IdentityObjectSearchCriteria searchCriteria) throws IdentityException,
OperationNotSupportedException
{
- System.out.println("*** Invoked unimplemented method
getRelationshipNames()");
- // TODO Auto-generated method stub
- return null;
+ Set<String> names = new HashSet<String>();
+
+ Property<Object> roleTypeNameProp =
modelProperties.get(PROPERTY_ROLE_TYPE_NAME);
+
+ if (roleTypeClass != null)
+ {
+ EntityManager em = getEntityManager(ctx);
+
+ CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<?> criteria = builder.createQuery(roleTypeClass);
+ criteria.from(roleTypeClass);
+
+ List<?> results = em.createQuery(criteria).getResultList();
+ for (Object result : results)
+ {
+ names.add(roleTypeNameProp.getValue(result).toString());
+ }
+ }
+
+ return names;
}
public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java 2010-07-22
08:01:55 UTC (rev 13470)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java 2010-07-22
08:12:29 UTC (rev 13471)
@@ -17,7 +17,7 @@
private Class<?> identityClass;
private Class<?> credentialClass;
private Class<?> relationshipClass;
- private Class<?> roleNameClass;
+ private Class<?> roleTypeClass;
private Class<?> attributeClass;
@Override
@@ -67,14 +67,14 @@
this.relationshipClass = relationshipClass;
}
- public Class<?> getRoleNameClass()
+ public Class<?> getRoleTypeClass()
{
- return roleNameClass;
+ return roleTypeClass;
}
- public void setRoleNameClass(Class<?> roleNameClass)
+ public void setRoleTypeClass(Class<?> roleTypeClass)
{
- this.roleNameClass = roleNameClass;
+ this.roleTypeClass = roleTypeClass;
}
public Class<?> getAttributeClass()
@@ -109,10 +109,10 @@
createOptionList(relationshipClass.getName()));
}
- if (roleNameClass != null)
+ if (roleTypeClass != null)
{
- options.put(JpaIdentityStore.OPTION_ROLE_NAME_CLASS_NAME,
- createOptionList(roleNameClass.getName()));
+ options.put(JpaIdentityStore.OPTION_ROLE_TYPE_CLASS_NAME,
+ createOptionList(roleTypeClass.getName()));
}
store.setOptions(options);