Author: shane.bryzak(a)jboss.com
Date: 2010-07-17 07:49:40 -0400 (Sat, 17 Jul 2010)
New Revision: 13419
Added:
modules/security/trunk/examples/idmconsole/src/main/webapp/managegroups.xhtml
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupAction.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupDTO.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupSearch.java
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/IdentityImpl.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/IdentityStoreConfiguration.java
Log:
added infrastructure for group management (but doesn't work yet, need to speak to
Bolek)
Added: modules/security/trunk/examples/idmconsole/src/main/webapp/managegroups.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/managegroups.xhtml
(rev 0)
+++
modules/security/trunk/examples/idmconsole/src/main/webapp/managegroups.xhtml 2010-07-17
11:49:40 UTC (rev 13419)
@@ -0,0 +1,60 @@
+<?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">
+ <script type="text/javascript">
+ function confirmDelete() {
+ return confirm("Are you sure you wish to delete this group? This action
cannot be undone.");
+ }
+ </script>
+
+ <h3>Manage Users</h3>
+
+ <h:form>
+ <h:commandButton action="#{groupAction.createGroup}"
styleClass="newuser"
rendered="#{identity.hasPermission('seam.account',
'create')}"/>
+ </h:form>
+
+ <h:form>
+ <h:dataTable
+ id="threads"
+ value="#{groupSearch.groups}"
+ var="group"
+ styleClass="security"
+ cellspacing="0"
+ headerClass="header"
+ rowClasses="odd,even"
+ columnClasses=",,action">
+ <h:column width="auto">
+ <f:facet name="header">
+ User name
+ </f:facet>
+ #{user.username}
+ </h:column>
+ <h:column id="action" width="auto">
+ <f:facet name="header">
+ Action
+ </f:facet>
+
+ <ui:fragment
rendered="#{identity.hasPermission('seam.identity',
'update')}">
+ <h:commandLink id="edit" value="Edit"
action="#{groupAction.editGroup(group.name)}"/>
+ <span> | </span>
+ </ui:fragment>
+ <ui:fragment
rendered="#{identity.hasPermission('seam.identity',
'delete')}">
+ <h:commandLink id="delete" value="Delete"
action="#{groupAction.deleteGroup(group.name)}" onclick="return
confirmDelete()"/>
+ </ui:fragment>
+ </h:column>
+ </h:dataTable>
+ </h:form>
+
+ <br style="clear:both"/>
+
+ </ui:define>
+</ui:composition>
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/IdentityImpl.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/IdentityImpl.java 2010-07-17
10:32:04 UTC (rev 13418)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/IdentityImpl.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -25,9 +25,11 @@
import org.jboss.seam.security.events.PreAuthenticateEvent;
import org.jboss.seam.security.events.PreLoggedOutEvent;
import org.jboss.seam.security.events.QuietLoginEvent;
-import org.jboss.seam.security.management.IdentityManager;
import org.jboss.seam.security.permission.PermissionMapper;
+import org.picketlink.idm.api.Credential;
+import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.User;
+import org.picketlink.idm.common.exception.IdentityException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +56,7 @@
@Inject private Credentials credentials;
@Inject private PermissionMapper permissionMapper;
- @Inject private IdentityManager identityManager;
+ @Inject private IdentitySession identitySession;
@Inject Instance<RequestSecurityState> requestSecurityState;
@@ -226,7 +228,7 @@
}
}
- public void quietLogin()
+ public void quietLogin()
{
try
{
@@ -248,11 +250,12 @@
}
catch (Exception ex)
{
+ log.error("Error authenticating", ex);
credentials.invalidate();
}
}
- protected boolean authenticate()
+ protected boolean authenticate() throws IdentityException
{
try
{
@@ -290,10 +293,11 @@
else
{
// Otherwise if identity management is enabled, use it.
- if (identityManager != null)
+ if (identitySession != null)
{
- success = identityManager.authenticate(credentials.getUsername(),
- credentials.getCredential());
+ success = identitySession.getAttributesManager().validateCredentials(
+ new UserImpl(credentials.getUsername()),
+ new Credential[] {credentials.getCredential()});
if (success)
{
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupAction.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupAction.java
(rev 0)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupAction.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -0,0 +1,48 @@
+package org.jboss.seam.security.management.action;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jboss.seam.security.GroupImpl;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.common.exception.IdentityException;
+
+/**
+ * Action bean for managing groups
+ *
+ * @author Shane Bryzak
+ */
+public @Named @ConversationScoped class GroupAction implements Serializable
+{
+ private static final long serialVersionUID = -1553124158319503903L;
+
+ @Inject Conversation conversation;
+
+ @Inject IdentitySession identitySession;
+
+ private String groupName;
+ private String groupType;
+
+ public void createGroup()
+ {
+ conversation.begin();
+ }
+
+ public void deleteGroup(String name, String groupType) throws IdentityException
+ {
+ Group group = new GroupImpl(name, groupType);
+ identitySession.getPersistenceManager().removeGroup(group, true);
+ }
+
+ public String save() throws IdentityException
+ {
+ identitySession.getPersistenceManager().createGroup(groupName, groupType);
+ conversation.end();
+ return "success";
+ }
+}
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupDTO.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupDTO.java
(rev 0)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupDTO.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -0,0 +1,32 @@
+package org.jboss.seam.security.management.action;
+
+/**
+ * Data transfer object for group information
+ *
+ * @author Shane Bryzak
+ */
+public class GroupDTO
+{
+ private String name;
+ private String groupType;
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setGroupType(String groupType)
+ {
+ this.groupType = groupType;
+ }
+
+ public String getGroupType()
+ {
+ return groupType;
+ }
+}
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupSearch.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupSearch.java
(rev 0)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/GroupSearch.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -0,0 +1,51 @@
+package org.jboss.seam.security.management.action;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.api.query.GroupQueryBuilder;
+import org.picketlink.idm.api.query.QueryException;
+import org.picketlink.idm.common.exception.IdentityException;
+
+/**
+ * Identity management action bean for searching for groups
+ *
+ * @author Shane Bryzak
+ */
+public @Model class GroupSearch implements Serializable
+{
+ private static final long serialVersionUID = 8592034786339372510L;
+
+ List<GroupDTO> groups;
+
+ @Inject IdentitySession identitySession;
+
+ @Inject public void loadUsers() throws IdentityException, QueryException
+ {
+ groups = new ArrayList<GroupDTO>();
+
+ GroupQueryBuilder builder = identitySession.createGroupQueryBuilder();
+
+ Collection<Group> results = identitySession.list(builder.createQuery());
+
+ for (Group group : results)
+ {
+ GroupDTO dto = new GroupDTO();
+ dto.setName(group.getName());
+ dto.setGroupType(group.getGroupType());
+ groups.add(dto);
+ }
+ }
+
+ public List<GroupDTO> getGroups()
+ {
+ return groups;
+ }
+}
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-07-17
10:32:04 UTC (rev 13418)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -49,11 +49,6 @@
return sb.toString();
}
- //public String getSelectedUser()
- //{
- //return selectedUser;
- //}
-
public List<UserDTO> getUsers()
{
return users;
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/IdentityStoreConfiguration.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/IdentityStoreConfiguration.java 2010-07-17
10:32:04 UTC (rev 13418)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/IdentityStoreConfiguration.java 2010-07-17
11:49:40 UTC (rev 13419)
@@ -34,7 +34,7 @@
public void configure(IdentityStoreConfigurationMetaDataImpl store)
{
- store.setId(id);
+ store.setId(getId());
if (getIdentityStoreClass() != null)
{