<commit_before>package gov.nih.nci.cananolab.ui.security;

import gov.nih.nci.cananolab.dto.common.UserBean;
import gov.nih.nci.cananolab.exception.SecurityException;
import gov.nih.nci.cananolab.service.security.AuthorizationService;
import gov.nih.nci.cananolab.util.Constants;
import gov.nih.nci.cananolab.util.StringUtils;
import gov.nih.nci.security.authorization.domainobjects.Group;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

/**
 * This class sets up information required for CSM.
 *
 * @author pansu
 *
 */
public class InitSecuritySetup {
	private static AuthorizationService authorizationService;

	private InitSecuritySetup() throws SecurityException {
		authorizationService = new AuthorizationService(Constants.CSM_APP_NAME);
	}

	public static InitSecuritySetup getInstance() throws SecurityException {
		return new InitSecuritySetup();
	}

	public static AuthorizationService getAuthorizationService() {
		return authorizationService;
	}

	public boolean userHasCreatePrivilege(UserBean user,
			String protectionElementObjectId) throws SecurityException {
		boolean status = false;
		status = authorizationService.checkCreatePermission(user,
				protectionElementObjectId);
		return status;
	}

	public boolean userHasAdminPrivilege(UserBean user)
			throws SecurityException {
		boolean status = false;
		status = authorizationService.isAdmin(user);
		return status;
	}

	public boolean userHasDeletePrivilege(UserBean user,
			String protectionElementObjectId) throws SecurityException {
		boolean status = false;
		status = authorizationService.checkDeletePermission(user,
				protectionElementObjectId);
		return status;
	}

	public List<String> getAllVisibilityGroups(HttpServletRequest request)
			throws SecurityException {
		List<String> groupNames = authorizationService.getAllVisibilityGroups();
		request.getSession().setAttribute("allVisibilityGroups", groupNames);
		return groupNames;
	}

	public List<String> getAllVisibilityGroupsWithoutOrg(
			HttpServletRequest request, String sampleOrg)
			throws SecurityException {
		List<String> groupNames = getAllVisibilityGroups(request);
		if (!StringUtils.isEmpty(sampleOrg))
			groupNames.remove(sampleOrg);
		request.getSession().setAttribute("allVisibilityGroupsNoOrg",
				groupNames);
		return groupNames;
	}

	/**
	 * Assign curator CURD role to curation and R role to Public group
	 */
	public void setupDefaultCSM() throws SecurityException {
		// assign Curator group to role CURD on curation
		authorizationService.secureObject(Constants.CSM_PG_CURATION,
				Constants.CSM_DATA_CURATOR, Constants.CSM_CURD_ROLE);

		// create a collaboration group for Public group and assign Curator R
		// role
		Group publicGroup = authorizationService
				.getGroup(Constants.CSM_PUBLIC_GROUP);
		authorizationService.secureObject(
				Constants.CSM_COLLABORATION_GROUP_PREFIX
						+ publicGroup.getGroupId(), Constants.CSM_DATA_CURATOR,
				Constants.CSM_READ_ROLE);
	}
}
<commit_msg>updated setupDefaultCSM<commit_after>package gov.nih.nci.cananolab.ui.security;

import gov.nih.nci.cananolab.dto.common.UserBean;
import gov.nih.nci.cananolab.exception.SecurityException;
import gov.nih.nci.cananolab.service.security.AuthorizationService;
import gov.nih.nci.cananolab.util.Constants;
import gov.nih.nci.cananolab.util.StringUtils;
import gov.nih.nci.security.authorization.domainobjects.Group;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

/**
 * This class sets up information required for CSM.
 *
 * @author pansu
 *
 */
public class InitSecuritySetup {
	private static AuthorizationService authorizationService;

	private InitSecuritySetup() throws SecurityException {
		authorizationService = new AuthorizationService(Constants.CSM_APP_NAME);
	}

	public static InitSecuritySetup getInstance() throws SecurityException {
		return new InitSecuritySetup();
	}

	public static AuthorizationService getAuthorizationService() {
		return authorizationService;
	}

	public boolean userHasCreatePrivilege(UserBean user,
			String protectionElementObjectId) throws SecurityException {
		boolean status = false;
		status = authorizationService.checkCreatePermission(user,
				protectionElementObjectId);
		return status;
	}

	public boolean userHasAdminPrivilege(UserBean user)
			throws SecurityException {
		boolean status = false;
		status = authorizationService.isAdmin(user);
		return status;
	}

	public boolean userHasDeletePrivilege(UserBean user,
			String protectionElementObjectId) throws SecurityException {
		boolean status = false;
		status = authorizationService.checkDeletePermission(user,
				protectionElementObjectId);
		return status;
	}

	public List<String> getAllVisibilityGroups(HttpServletRequest request)
			throws SecurityException {
		List<String> groupNames = authorizationService.getAllVisibilityGroups();
		request.getSession().setAttribute("allVisibilityGroups", groupNames);
		return groupNames;
	}

	public List<String> getAllVisibilityGroupsWithoutOrg(
			HttpServletRequest request, String sampleOrg)
			throws SecurityException {
		List<String> groupNames = getAllVisibilityGroups(request);
		if (!StringUtils.isEmpty(sampleOrg))
			groupNames.remove(sampleOrg);
		request.getSession().setAttribute("allVisibilityGroupsNoOrg",
				groupNames);
		return groupNames;
	}

	/**
	 * Assign curator CURD role to curation and R role to Public group
	 */
	public void setupDefaultCSM() throws SecurityException {
		// assign Curator group to role CURD on curation
		authorizationService.secureObject(Constants.CSM_PG_CURATION,
				Constants.CSM_DATA_CURATOR, Constants.CSM_CURD_ROLE);
	}
}

{'fraction_non_alphanumeric': 0.07809456348503631, 'fraction_numerical': 0.0, 'mean_word_length': 5.731823599523242, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7664459', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1563, 'n_words': 346}