You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by "Harriett Y. Xing (HYX)" <Xi...@EBRINC.COM> on 2004/02/02 20:57:05 UTC
Setting up user Group and Role upon login
Hi,
I am trying to implement the code to setup user group and role right after
the login. I created class ApplicationAccessControlList implementing
AccessControlList. The code is crashing when it try to add a group to the
access control list.
May I kindly ask for help to take a look at it to see what I am doing wrong?
Thank you very much for your help.
-----------------------------------------------------------------------
Here's the code snipet at IntakeLoginUser.java:
// todo: Identify the user group
ApplicationAccessControlList acl = new
ApplicationAccessControlList();
Criteria criteria = new Criteria();
criteria.add(TurbineUserGroupRolePeer.USER_ID, user.getId(),
Criteria.EQUAL );
List userGroups = null;
try {
userGroups = TurbineUserGroupRolePeer.doSelect(criteria);
RoleSet roleSet = null;
for (int i=0; i<userGroups.size(); i++) {
com.ebr.collabAdvizor.om.TurbineUserGroupRole userGroup
= (com.ebr.collabAdvizor.om.TurbineUserGroupRole) userGroups.get(i);
ApplicationSecurityGroup uGroup = new
ApplicationSecurityGroup();
uGroup.setId(userGroup.getUserId() );
acl.addGroup(uGroup); // It crashes here.
ApplicationRole role = new ApplicationRole();
role.setId(userGroup.getUserId() );
roleSet.add(role);
}
acl.setRoles(roleSet);
data.setACL(acl);
} catch (TorqueException e) {
e.printStackTrace(); //To change body of catch statement
use Options | File Templates.
}
And here is the implementation for ApplicationAccessControlList.java:
package com.ebr.collabAdvizor.modules.security;
import org.apache.turbine.util.security.AccessControlList;
import org.apache.turbine.util.security.RoleSet;
import org.apache.turbine.util.security.PermissionSet;
import org.apache.turbine.util.security.GroupSet;
import org.apache.turbine.om.security.Group;
import org.apache.turbine.om.security.Role;
import org.apache.turbine.om.security.Permission;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: Xing
* Date: Jan 23, 2004
* Time: 4:14:54 PM
* To change this template use Options | File Templates.
*/
public class ApplicationAccessControlList implements AccessControlList {
private static RoleSet roles;
private static PermissionSet permissionSet;
private static Group [] allGroups;
public static void setRoles(RoleSet roles) {
ApplicationAccessControlList.roles = roles;
}
public static void setPermissionSet(PermissionSet permissionSet) {
ApplicationAccessControlList.permissionSet = permissionSet;
}
public static void setAllGroups(ApplicationSecurityGroup[] allGroups) {
ApplicationAccessControlList.allGroups = allGroups;
}
/**
* Retrieves a set of Roles an user is assigned in a Group.
*
* @param group the Group
* @return the set of Roles this user has within the Group.
*/
public RoleSet getRoles(Group group) {
return null;
}
/**
* Retrieves a set of Roles an user is assigned in the global Group.
*
* @return the set of Roles this user has within the global Group.
*/
public RoleSet getRoles() {
return null;
}
/**
* Retrieves a set of Permissions an user is assigned in a Group.
*
* @param group the Group
* @return the set of Permissions this user has within the Group.
*/
public PermissionSet getPermissions(Group group) {
return null;
}
/**
* Retrieves a set of Permissions an user is assigned in the global
Group.
*
* @return the set of Permissions this user has within the global Group.
*/
public PermissionSet getPermissions() {
return null;
}
/**
* Checks if the user is assigned a specific Role in the Group.
*
* @param role the Role
* @param group the Group
* @return <code>true</code> if the user is assigned the Role in the
Group.
*/
public boolean hasRole(Role role, Group group) {
return false;
}
/**
* Checks if the user is assigned a specific Role in any of the given
* Groups
*
* @param role the Role
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Role in any of
* the given Groups.
*/
public boolean hasRole(Role role, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the Group.
*
* @param role the Role
* @param group the Group
* @return <code>true</code> if the user is assigned the Role in the
Group.
*/
public boolean hasRole(String role, String group) {
return false;
}
/**
* Checks if the user is assigned a specifie Role in any of the given
* Groups
*
* @param rolename the name of the Role
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Role in any of
* the given Groups.
*/
public boolean hasRole(String rolename, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the global Group.
*
* @param role the Role
* @return <code>true</code> if the user is assigned the Role in the
global Group.
*/
public boolean hasRole(Role role) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the global Group.
*
* @param role the Role
* @return <code>true</code> if the user is assigned the Role in the
global Group.
*/
public boolean hasRole(String role) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(Permission permission, Group group) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in any of the
given
* Groups
*
* @param permission the Permission
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Permission in
any
* of the given Groups.
*/
public boolean hasPermission(Permission permission, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(String permission, String group) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(String permission, Group group) {
return false;
}
/**
* Checks if the user is assigned a specifie Permission in any of the
given
* Groups
*
* @param permissionName the name of the Permission
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Permission in
any
* of the given Groups.
*/
public boolean hasPermission(String permissionName, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the global
Group.
*
* @param permission the Permission
* @return <code>true</code> if the user is assigned the Permission in
the global Group.
*/
public boolean hasPermission(Permission permission) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the global
Group.
*
* @param permission the Permission
* @return <code>true</code> if the user is assigned the Permission in
the global Group.
*/
public boolean hasPermission(String permission) {
return false;
}
/**
* Returns all groups definded in the system.
*
* @return An Array of all defined Groups
*
* This is useful for debugging, when you want to display all roles
* and permissions an user is assigned. This method is needed
* because you can't call static methods of TurbineSecurity class
* from within WebMacro/Velocity template
*/
public Group[] getAllGroups() {
return allGroups;
}
public void addGroup(ApplicationSecurityGroup group) {
System.out.println("ApplicationAccessControlList.addGroup");
int index = allGroups.length;
allGroups[index] = group;
System.out.println("ApplicationAccessControlList.addGroup - done");
}
}
RE: Setting up user Group and Role upon login
Posted by David Demner <tu...@demner.com>.
Hi Harriett,
The problem is this:
int index = allGroups.length;
allGroups[index] = group;
In all cases, index refers past the end of the array. You need to do either
allGroups[index - 1] (which you probably don't want since it will overwrite
a group), or resize the array when you add the group (which isn't good since
arrays aren't meant to be resized). You probably want to use a List or
Vector (or something meant to have a variable number of elements) instead of
an array.
Good luck,
David
-----Original Message-----
From: Harriett Y. Xing (HYX) [mailto:Xing@EBRINC.COM]
Sent: Monday, February 02, 2004 11:57 AM
To: turbine-user@jakarta.apache.org
Subject: Setting up user Group and Role upon login
Hi,
I am trying to implement the code to setup user group and role right after
the login. I created class ApplicationAccessControlList implementing
AccessControlList. The code is crashing when it try to add a group to the
access control list.
May I kindly ask for help to take a look at it to see what I am doing wrong?
Thank you very much for your help.
-----------------------------------------------------------------------
Here's the code snipet at IntakeLoginUser.java:
// todo: Identify the user group
ApplicationAccessControlList acl = new
ApplicationAccessControlList();
Criteria criteria = new Criteria();
criteria.add(TurbineUserGroupRolePeer.USER_ID, user.getId(),
Criteria.EQUAL );
List userGroups = null;
try {
userGroups = TurbineUserGroupRolePeer.doSelect(criteria);
RoleSet roleSet = null;
for (int i=0; i<userGroups.size(); i++) {
com.ebr.collabAdvizor.om.TurbineUserGroupRole userGroup
= (com.ebr.collabAdvizor.om.TurbineUserGroupRole) userGroups.get(i);
ApplicationSecurityGroup uGroup = new
ApplicationSecurityGroup();
uGroup.setId(userGroup.getUserId() );
acl.addGroup(uGroup); // It crashes here.
ApplicationRole role = new ApplicationRole();
role.setId(userGroup.getUserId() );
roleSet.add(role);
}
acl.setRoles(roleSet);
data.setACL(acl);
} catch (TorqueException e) {
e.printStackTrace(); //To change body of catch statement
use Options | File Templates.
}
And here is the implementation for ApplicationAccessControlList.java:
package com.ebr.collabAdvizor.modules.security;
import org.apache.turbine.util.security.AccessControlList;
import org.apache.turbine.util.security.RoleSet;
import org.apache.turbine.util.security.PermissionSet;
import org.apache.turbine.util.security.GroupSet;
import org.apache.turbine.om.security.Group;
import org.apache.turbine.om.security.Role;
import org.apache.turbine.om.security.Permission;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: Xing
* Date: Jan 23, 2004
* Time: 4:14:54 PM
* To change this template use Options | File Templates.
*/
public class ApplicationAccessControlList implements AccessControlList {
private static RoleSet roles;
private static PermissionSet permissionSet;
private static Group [] allGroups;
public static void setRoles(RoleSet roles) {
ApplicationAccessControlList.roles = roles;
}
public static void setPermissionSet(PermissionSet permissionSet) {
ApplicationAccessControlList.permissionSet = permissionSet;
}
public static void setAllGroups(ApplicationSecurityGroup[] allGroups) {
ApplicationAccessControlList.allGroups = allGroups;
}
/**
* Retrieves a set of Roles an user is assigned in a Group.
*
* @param group the Group
* @return the set of Roles this user has within the Group.
*/
public RoleSet getRoles(Group group) {
return null;
}
/**
* Retrieves a set of Roles an user is assigned in the global Group.
*
* @return the set of Roles this user has within the global Group.
*/
public RoleSet getRoles() {
return null;
}
/**
* Retrieves a set of Permissions an user is assigned in a Group.
*
* @param group the Group
* @return the set of Permissions this user has within the Group.
*/
public PermissionSet getPermissions(Group group) {
return null;
}
/**
* Retrieves a set of Permissions an user is assigned in the global
Group.
*
* @return the set of Permissions this user has within the global Group.
*/
public PermissionSet getPermissions() {
return null;
}
/**
* Checks if the user is assigned a specific Role in the Group.
*
* @param role the Role
* @param group the Group
* @return <code>true</code> if the user is assigned the Role in the
Group.
*/
public boolean hasRole(Role role, Group group) {
return false;
}
/**
* Checks if the user is assigned a specific Role in any of the given
* Groups
*
* @param role the Role
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Role in any of
* the given Groups.
*/
public boolean hasRole(Role role, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the Group.
*
* @param role the Role
* @param group the Group
* @return <code>true</code> if the user is assigned the Role in the
Group.
*/
public boolean hasRole(String role, String group) {
return false;
}
/**
* Checks if the user is assigned a specifie Role in any of the given
* Groups
*
* @param rolename the name of the Role
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Role in any of
* the given Groups.
*/
public boolean hasRole(String rolename, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the global Group.
*
* @param role the Role
* @return <code>true</code> if the user is assigned the Role in the
global Group.
*/
public boolean hasRole(Role role) {
return false;
}
/**
* Checks if the user is assigned a specific Role in the global Group.
*
* @param role the Role
* @return <code>true</code> if the user is assigned the Role in the
global Group.
*/
public boolean hasRole(String role) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(Permission permission, Group group) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in any of the
given
* Groups
*
* @param permission the Permission
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Permission in
any
* of the given Groups.
*/
public boolean hasPermission(Permission permission, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(String permission, String group) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the Group.
*
* @param permission the Permission
* @param group the Group
* @return <code>true</code> if the user is assigned the Permission in
the Group.
*/
public boolean hasPermission(String permission, Group group) {
return false;
}
/**
* Checks if the user is assigned a specifie Permission in any of the
given
* Groups
*
* @param permissionName the name of the Permission
* @param groupset a Groupset
* @return <code>true</code> if the user is assigned the Permission in
any
* of the given Groups.
*/
public boolean hasPermission(String permissionName, GroupSet groupset) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the global
Group.
*
* @param permission the Permission
* @return <code>true</code> if the user is assigned the Permission in
the global Group.
*/
public boolean hasPermission(Permission permission) {
return false;
}
/**
* Checks if the user is assigned a specific Permission in the global
Group.
*
* @param permission the Permission
* @return <code>true</code> if the user is assigned the Permission in
the global Group.
*/
public boolean hasPermission(String permission) {
return false;
}
/**
* Returns all groups definded in the system.
*
* @return An Array of all defined Groups
*
* This is useful for debugging, when you want to display all roles
* and permissions an user is assigned. This method is needed
* because you can't call static methods of TurbineSecurity class
* from within WebMacro/Velocity template
*/
public Group[] getAllGroups() {
return allGroups;
}
public void addGroup(ApplicationSecurityGroup group) {
System.out.println("ApplicationAccessControlList.addGroup");
int index = allGroups.length;
allGroups[index] = group;
System.out.println("ApplicationAccessControlList.addGroup - done");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org