Skip to content

Commit

Permalink
KNL-1375 Remove uses of AuthzGroupService cover.
Browse files Browse the repository at this point in the history
This removes all use the AuthzGroupService cover so we only have one API to maintain, for services it also makes testing easier as you can inject a test copy of the service.
  • Loading branch information
buckett committed Aug 3, 2015
1 parent d88808a commit 8d974a2
Show file tree
Hide file tree
Showing 57 changed files with 415 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class AliasesAction extends PagedResourceActionII
private AliasService aliasService;

public AliasesAction() {
super();
aliasService = ComponentManager.get(AliasService.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.sakaiproject.assignment.api.*;
import org.sakaiproject.assignment.taggable.api.AssignmentActivityProducer;
import org.sakaiproject.authz.api.*;
import org.sakaiproject.authz.cover.AuthzGroupService;
import org.sakaiproject.authz.cover.FunctionManager;
import org.sakaiproject.calendar.api.Calendar;
import org.sakaiproject.calendar.api.CalendarEvent;
Expand Down Expand Up @@ -176,6 +175,11 @@ public void setDeveloperHelperService( DeveloperHelperService developerHelperSer
this.developerHelperService = developerHelperService;
}

private AuthzGroupService authzGroupService;
public void setAuthzGroupService (AuthzGroupService authzGroupService) {
this.authzGroupService = authzGroupService;
}

String newline = "<br />\n";

/**********************************************************************************************************************************************************************************************************************************************************
Expand Down Expand Up @@ -1530,7 +1534,7 @@ public void removeAssignment(AssignmentEdit assignment) throws PermissionExcepti
// remove any realm defined for this resource
try
{
AuthzGroupService.removeAuthzGroup(assignment.getReference());
authzGroupService.removeAuthzGroup(assignment.getReference());
}
catch (AuthzPermissionException e)
{
Expand Down Expand Up @@ -1638,7 +1642,7 @@ public void removeAssignmentAndAllReferences(AssignmentEdit assignment) throws P
// 8. remove any realm defined for this resource
try
{
AuthzGroupService.removeAuthzGroup(assignment.getReference());
authzGroupService.removeAuthzGroup(assignment.getReference());
}
catch (AuthzPermissionException e)
{
Expand Down Expand Up @@ -3076,7 +3080,7 @@ public void removeSubmission(AssignmentSubmissionEdit submission) throws Permiss
// remove any realm defined for this resource
try
{
AuthzGroupService.removeAuthzGroup(AuthzGroupService.getAuthzGroup(submission.getReference()));
authzGroupService.removeAuthzGroup(authzGroupService.getAuthzGroup(submission.getReference()));
}
catch (AuthzPermissionException e)
{
Expand Down Expand Up @@ -3297,7 +3301,7 @@ public Map<Assignment, List<String>> getSubmittableAssignmentsForContext(String
return submittable;
}

Set<String> siteSubmitterIds = AuthzGroupService.getUsersIsAllowed(
Set<String> siteSubmitterIds = authzGroupService.getUsersIsAllowed(
SECURE_ADD_ASSIGNMENT_SUBMISSION, Arrays.asList(site.getReference()));
Map<String, Set<String>> groupIdUserIds = new HashMap<String, Set<String>>();
for (Group group : site.getGroups()) {
Expand Down Expand Up @@ -3938,7 +3942,7 @@ else if (userId == null)
}

// ask the authzGroup service to filter them down based on function
groupRefs = AuthzGroupService.getAuthzGroupsIsAllowed(userId,
groupRefs = authzGroupService.getAuthzGroupsIsAllowed(userId,
function, groupRefs);

// pick the Group objects from the site's groups to return, those that are in the groupRefs list
Expand Down Expand Up @@ -4100,7 +4104,7 @@ public List allowGradeAssignmentUsers(String assignmentReference)
if (a.getAccess() == Assignment.AssignmentAccess.GROUPED)
{
// for grouped assignment, need to include those users that with "all.groups" and "grade assignment" permissions on the site level
AuthzGroup group = AuthzGroupService.getAuthzGroup(SiteService.siteReference(a.getContext()));
AuthzGroup group = authzGroupService.getAuthzGroup(SiteService.siteReference(a.getContext()));
if (group != null)
{
// get the roles which are allowed for submission but not for all_site control
Expand Down Expand Up @@ -4158,7 +4162,7 @@ public List allowAddAnySubmissionUsers(String context)

try
{
AuthzGroup group = AuthzGroupService.getAuthzGroup(context);
AuthzGroup group = authzGroupService.getAuthzGroup(context);

// get the roles which are allowed for submission but not for all_site control
Set rolesAllowSubmission = group.getRolesIsAllowed(SECURE_ADD_ASSIGNMENT_SUBMISSION);
Expand Down Expand Up @@ -4937,7 +4941,7 @@ private List<User> getSelectedGroupUsers(String allOrOneGroup, String contextStr
{
try
{
AuthzGroup group = AuthzGroupService.getAuthzGroup(authzGroupRef);
AuthzGroup group = authzGroupService.getAuthzGroup(authzGroupRef);
Set grants = group.getUsers();
for (Iterator iUserIds = grants.iterator(); iUserIds.hasNext();)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<property name="assignmentPeerAssessmentService"><ref bean="org.sakaiproject.assignment.api.AssignmentPeerAssessmentService"/></property>
<property name="securityService"><ref bean="org.sakaiproject.authz.api.SecurityService"/></property>
<property name="developerHelperService"><ref bean="org.sakaiproject.entitybroker.DeveloperHelperService"/></property>
<property name="authzGroupService"><ref bean="org.sakaiproject.authz.api.AuthzGroupService"/></property>

<!--<property name="contentReviewService"><ref bean="org.sakaiproject.contentreview.service.ContentReviewService"/></property>-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.api.SecurityAdvisor;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.authz.cover.AuthzGroupService;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.calendar.api.Calendar;
import org.sakaiproject.calendar.api.CalendarEvent;
import org.sakaiproject.calendar.api.CalendarEventEdit;
Expand Down Expand Up @@ -821,6 +821,8 @@ public class AssignmentAction extends PagedResourceActionII
private NotificationService m_notificationService = null;

private SecurityService m_securityService = null;

private AuthzGroupService authzGroupService = null;

/********************** Supplement item ************************/
private AssignmentSupplementItemService m_assignmentSupplementItemService = null;
Expand Down Expand Up @@ -2270,7 +2272,7 @@ protected String build_list_assignments_context(VelocityPortlet portlet, Context
context.put("contextString", contextString);
context.put("user", state.getAttribute(STATE_USER));
context.put("service", AssignmentService.getInstance());
context.put("AuthzGroupService", AuthzGroupService.getInstance());
context.put("AuthzGroupService", authzGroupService);
context.put("TimeService", TimeService.getInstance());
context.put("LongObject", Long.valueOf(TimeService.newTime().getTime()));
context.put("currentTime", TimeService.newTime());
Expand Down Expand Up @@ -2358,7 +2360,7 @@ protected String build_list_assignments_context(VelocityPortlet portlet, Context
context.put("groups", (groups != null && groups.size()>0)?Boolean.TRUE:Boolean.FALSE);

// add active user list
AuthzGroup realm = AuthzGroupService.getAuthzGroup(SiteService.siteReference(contextString));
AuthzGroup realm = authzGroupService.getAuthzGroup(SiteService.siteReference(contextString));
if (realm != null)
{
context.put("activeUserIds", realm.getUsers());
Expand Down Expand Up @@ -2830,7 +2832,7 @@ else if (groupsAllowAddAssignment.size() > 0)
HashMap<String, List> roleUsers = new HashMap<String, List>();
try
{
AuthzGroup realm = AuthzGroupService.getAuthzGroup(SiteService.siteReference(contextString));
AuthzGroup realm = authzGroupService.getAuthzGroup(SiteService.siteReference(contextString));
Set<Role> roles = realm.getRoles();
for(Iterator iRoles = roles.iterator(); iRoles.hasNext();)
{
Expand Down Expand Up @@ -7744,7 +7746,7 @@ private void setNewAssignmentParametersSupplementItems(boolean validify,
List<String> accessList = new ArrayList<String>();
try
{
AuthzGroup realm = AuthzGroupService.getAuthzGroup(SiteService.siteReference(siteId));
AuthzGroup realm = authzGroupService.getAuthzGroup(SiteService.siteReference(siteId));
Set<Role> roles = realm.getRoles();
for(Iterator iRoles = roles.iterator(); iRoles.hasNext();)
{
Expand Down Expand Up @@ -8593,7 +8595,7 @@ else if (state.getAttribute(ALLPURPOSE_TITLE) != null)
Set<AssignmentAllPurposeItemAccess> accessSet = new HashSet<AssignmentAllPurposeItemAccess>();
try
{
AuthzGroup realm = AuthzGroupService.getAuthzGroup(SiteService.siteReference(siteId));
AuthzGroup realm = authzGroupService.getAuthzGroup(SiteService.siteReference(siteId));
Set<Role> roles = realm.getRoles();
for(Iterator iRoles = roles.iterator(); iRoles.hasNext();)
{
Expand Down Expand Up @@ -12001,6 +12003,10 @@ protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRu
if(assignmentPeerAssessmentService == null){
assignmentPeerAssessmentService = (AssignmentPeerAssessmentService) ComponentManager.get("org.sakaiproject.assignment.api.AssignmentPeerAssessmentService");
}

if (authzGroupService == null) {
authzGroupService = ComponentManager.get(AuthzGroupService.class);
}


String siteId = ToolManager.getCurrentPlacement().getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.sakaiproject.authz.api.PermissionsHelper;
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.api.RoleAlreadyDefinedException;
import org.sakaiproject.authz.cover.AuthzGroupService;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.cover.FunctionManager;
import org.sakaiproject.authz.cover.SecurityService;
import org.sakaiproject.cheftool.Context;
Expand All @@ -46,6 +46,7 @@
import org.sakaiproject.cheftool.VelocityPortlet;
import org.sakaiproject.cheftool.VelocityPortletPaneledAction;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.cover.EntityManager;
import org.sakaiproject.event.api.SessionState;
Expand Down Expand Up @@ -115,6 +116,13 @@ public class PermissionsHelperAction extends VelocityPortletPaneledAction

private static final String STATE_GROUP_AWARE = "state_group_aware";

private AuthzGroupService authzGroupService;

public PermissionsHelperAction() {
super();
authzGroupService = ComponentManager.get(AuthzGroupService.class);
}

protected void toolModeDispatch(String methodBase, String methodExt, HttpServletRequest req, HttpServletResponse res)
throws ToolException
{
Expand Down Expand Up @@ -213,7 +221,7 @@ protected void initHelper(VelocityPortlet portlet, Context context, RunData rund
*
* @return The name of the template to use. <code>null</code> can be returned.
*/
static public String buildHelperContext(VelocityPortlet portlet, Context context, RunData rundata, SessionState state)
public String buildHelperContext(VelocityPortlet portlet, Context context, RunData rundata, SessionState state)
{
// in state is the realm id
context.put("thelp", rb);
Expand All @@ -227,19 +235,19 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
AuthzGroup edit = (AuthzGroup) state.getAttribute(STATE_REALM_EDIT);
if (edit == null)
{
if (AuthzGroupService.allowUpdate(realmId))
if (authzGroupService.allowUpdate(realmId))
{
try
{
edit = AuthzGroupService.getAuthzGroup(realmId);
edit = authzGroupService.getAuthzGroup(realmId);
state.setAttribute(STATE_REALM_EDIT, edit);
}
catch (GroupNotDefinedException e)
{
try
{
// we can create the realm
edit = AuthzGroupService.addAuthzGroup(realmId);
edit = authzGroupService.addAuthzGroup(realmId);
state.setAttribute(STATE_REALM_EDIT, edit);
}
catch (GroupIdInvalidException ee)
Expand Down Expand Up @@ -294,7 +302,7 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
{
Group group = (Group) iGroups.next();
// need to either have realm update permission on the group level or better at the site level
if (!AuthzGroupService.allowUpdate(group.getReference()))
if (!authzGroupService.allowUpdate(group.getReference()))
{
iGroups.remove();
}
Expand All @@ -313,11 +321,11 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
viewEdit = (AuthzGroup) state.getAttribute(STATE_VIEW_REALM_EDIT);
if (viewEdit == null)
{
if (AuthzGroupService.allowUpdate(realmRolesId) || AuthzGroupService.allowUpdate(SiteService.siteReference(siteId)))
if (authzGroupService.allowUpdate(realmRolesId) || authzGroupService.allowUpdate(SiteService.siteReference(siteId)))
{
try
{
viewEdit = AuthzGroupService.getAuthzGroup(realmRolesId);
viewEdit = authzGroupService.getAuthzGroup(realmRolesId);
state.setAttribute(STATE_VIEW_REALM_EDIT, viewEdit);
}
catch (GroupNotDefinedException e)
Expand Down Expand Up @@ -406,7 +414,7 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
{
try
{
roleRealm = AuthzGroupService.getAuthzGroup(realmRolesId);
roleRealm = authzGroupService.getAuthzGroup(realmRolesId);
}
catch (Exception e)
{
Expand Down Expand Up @@ -434,7 +442,7 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
for (Iterator iRoles = roles.iterator(); iRoles.hasNext();)
{
Role role = (Role) iRoles.next();
Set locks = AuthzGroupService.getAllowedFunctions(role.getId(), realms);
Set locks = authzGroupService.getAllowedFunctions(role.getId(), realms);
rolesAbilities.put(role.getId(), locks);
}
}
Expand Down Expand Up @@ -464,7 +472,7 @@ static public String buildHelperContext(VelocityPortlet portlet, Context context
*
* @param configPrefix The prefix to get permissions for.
*/
private static Map<String, Set<String>> getPermissions(String configPrefix)
private Map<String, Set<String>> getPermissions(String configPrefix)
{
Map<String, Set<String>> roleMap = new HashMap<String, Set<String>>();
ServerConfigurationService scs = org.sakaiproject.component.cover.ServerConfigurationService.getInstance();
Expand All @@ -484,7 +492,7 @@ private static Map<String, Set<String>> getPermissions(String configPrefix)
return roleMap;
}

private static Set<String> createPermissionSet(String config, String roleName)
private Set<String> createPermissionSet(String config, String roleName)
{
String permissionList = org.sakaiproject.component.cover.ServerConfigurationService.getString(config +roleName,"");
Set<String> permissionSet = new HashSet<String>();
Expand All @@ -503,7 +511,7 @@ private static Set<String> createPermissionSet(String config, String roleName)
/**
* Remove the state variables used internally, on the way out.
*/
private static void cleanupState(SessionState state)
private void cleanupState(SessionState state)
{
state.removeAttribute(STATE_REALM_ID);
state.removeAttribute(STATE_REALM_ROLES_ID);
Expand Down Expand Up @@ -569,9 +577,9 @@ public void doSave(RunData data)
removeEmptyRoles(edit);

if (hasNothingSet(edit)) {
AuthzGroupService.removeAuthzGroup(edit);
authzGroupService.removeAuthzGroup(edit);
} else {
AuthzGroupService.save(edit);
authzGroupService.save(edit);
}
}
catch (GroupNotDefinedException e)
Expand Down Expand Up @@ -676,7 +684,7 @@ private void readForm(RunData data, AuthzGroup edit, SessionState state)
}
}

public static PermissionLimiter getPermissionLimiter() {
public PermissionLimiter getPermissionLimiter() {
Map allowedPermissions = getPermissions("realm.allowed."); // Whitelisted permissions for some roles
Map frozenPermissions = getPermissions("realm.frozen."); // Permissions that can't be changed
Map addOnlyPermissions = getPermissions("realm.add.only."); // Permissions that can only be added. }
Expand All @@ -686,7 +694,7 @@ public static PermissionLimiter getPermissionLimiter() {
/**
* The class is put into the velocity context to limit the permission that can be set.
*/
public static class PermissionLimiter
public class PermissionLimiter
{
private Map<String, Set<String>> allowedPermissions;
private Map<String, Set<String>> frozenPermissions;
Expand Down Expand Up @@ -732,10 +740,10 @@ public boolean isEnabled(String roleId, String permission, boolean enabled)
}
}

public static class RoleNameLookup {
public class RoleNameLookup {

public String getName(String roleId) {
return AuthzGroupService.getRoleName(roleId);
return authzGroupService.getRoleName(roleId);
}
}
}
Loading

0 comments on commit 8d974a2

Please sign in to comment.