本文整理汇总了Java中gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup类的典型用法代码示例。如果您正苦于以下问题:Java UserGroupRoleProtectionGroup类的具体用法?Java UserGroupRoleProtectionGroup怎么用?Java UserGroupRoleProtectionGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserGroupRoleProtectionGroup类属于gov.nih.nci.security.authorization.domainobjects包,在下文中一共展示了UserGroupRoleProtectionGroup类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserGroupRoleProtectionGroups
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
/**
* @param p the protectable to get the protection group for
* @return the UserGroupRoleProtectionGroup. <b>Note: This object is NOT associated with the current hibernate
* session.</b>
*/
@SuppressWarnings("unchecked")
public static List<UserGroupRoleProtectionGroup> getUserGroupRoleProtectionGroups(Protectable p) {
// Unfortunately, CSM doesn't provide a way to find out if the UserGroupRoleProtectionGroup
// has been created (down to attribute level). So we need to query for it,
// using the known values for various ids from the csm script
final String queryString =
"SELECT ugrpg FROM " + UserGroupRoleProtectionGroup.class.getName() + " ugrpg, "
+ ProtectionElement.class.getName() + " pe "
+ "WHERE pe in elements(ugrpg.protectionGroup.protectionElements) "
+ " AND size(ugrpg.protectionGroup.protectionElements) = 1" + " AND pe.attribute = 'id' "
+ " AND pe.objectId = :objectId " + " AND pe.value = :value "
+ " AND ugrpg.role.name in (:roleNames)";
final Query q = hibernateHelper.getCurrentSession().createQuery(queryString);
q.setParameterList("roleNames", new String[] {BROWSE_ROLE, READ_ROLE, WRITE_ROLE, PERMISSIONS_ROLE,
PARTIAL_READ_ROLE, PARTIAL_WRITE_ROLE });
q.setString("objectId", getUnderlyingEntityClass(p).getName());
q.setString("value", p.getId().toString());
return q.list();
}
示例2: handleDeleted
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
@SuppressWarnings({"PMD.ExcessiveMethodLength", "unchecked" })
static void handleDeleted(Collection<Protectable> deletedInstances) {
if (deletedInstances == null) {
return;
}
try {
for (final Protectable p : deletedInstances) {
LOG.debug("Deleting records for obj of type: " + p.getClass().getName() + " for user "
+ CaArrayUsernameHolder.getUser());
final List<UserGroupRoleProtectionGroup> l = getUserGroupRoleProtectionGroups(p);
for (final UserGroupRoleProtectionGroup ugrpg : l) {
if (ugrpg.getGroup() != null) {
authMgr.removeGroupRoleFromProtectionGroup(ugrpg.getProtectionGroup().getProtectionGroupId()
.toString(), ugrpg.getGroup().getGroupId().toString(), new String[] {ugrpg.getRole()
.getId().toString() });
} else {
authMgr.removeUserRoleFromProtectionGroup(ugrpg.getProtectionGroup().getProtectionGroupId()
.toString(), ugrpg.getUser().getUserId().toString(), new String[] {ugrpg.getRole()
.getId().toString() });
}
}
final ProtectionGroup pg = getProtectionGroup(p);
LOG.debug("HAndling delete for protection group " + pg.getProtectionGroupName());
final Set<ProtectionElement> protElements = pg.getProtectionElements();
final ProtectionElement pe = protElements.iterator().next();
authMgr.removeProtectionGroup(pg.getProtectionGroupId().toString());
authMgr.removeProtectionElement(pe.getProtectionElementId().toString());
}
} catch (final CSTransactionException e) {
LOG.warn("Unable to remove CSM elements from deleted object: " + e.getMessage(), e);
}
}
示例3: testOwnerPermissions
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
@Test
public void testOwnerPermissions() throws Exception {
CaArrayUsernameHolder.setUser(STANDARD_USER);
Transaction tx = this.hibernateHelper.beginTransaction();
saveSupportingObjects();
daoObject.save(DUMMY_PROJECT_1);
tx.commit();
tx = this.hibernateHelper.beginTransaction();
Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId());
assertTrue(SecurityUtils.isOwner(p, CaArrayUsernameHolder.getCsmUser()));
assertTrue(SecurityUtils.canWrite(DUMMY_SOURCE, CaArrayUsernameHolder.getCsmUser()));
assertNotNull(p.getPublicProfile());
assertEquals(2, p.getFiles().size());
assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_1.getId()));
assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_2.getId()));
assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_DATA_FILE.getId()));
List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p);
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.READ_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.WRITE_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.PERMISSIONS_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.BROWSE_ROLE))));
assertTrue(SecurityUtils.canRead(p, CaArrayUsernameHolder.getCsmUser()));
assertTrue(SecurityUtils.canWrite(p, CaArrayUsernameHolder.getCsmUser()));
assertTrue(SecurityUtils.canFullRead(p, CaArrayUsernameHolder.getCsmUser()));
assertTrue(SecurityUtils.canFullWrite(p, CaArrayUsernameHolder.getCsmUser()));
assertTrue(SecurityUtils.canModifyPermissions(p, CaArrayUsernameHolder.getCsmUser()));
}
示例4: testInitialProjectPermissions
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
@Test
public void testInitialProjectPermissions() {
// create project
Transaction tx = this.hibernateHelper.beginTransaction();
saveSupportingObjects();
this.hibernateHelper.getCurrentSession().save(DUMMY_PROJECT_1);
this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_1);
this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_2);
tx.commit();
// check initial settings.. drafts should be not visible
tx = this.hibernateHelper.beginTransaction();
final Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId());
List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p);
assertEquals(8, list.size()); // expect the user-only ones only
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.READ_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.WRITE_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.PERMISSIONS_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.BROWSE_ROLE))));
p.getPublicProfile().setSecurityLevel(SecurityLevel.VISIBLE);
tx.commit();
// check that after changing to visible, the role is reflected.
tx = this.hibernateHelper.beginTransaction();
list = SecurityUtils.getUserGroupRoleProtectionGroups(p);
assertEquals(9, list.size()); // expect the user-only ones and the anonymous access one
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.READ_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.WRITE_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.PERMISSIONS_ROLE))));
assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(
SecurityUtils.BROWSE_ROLE))));
tx.commit();
}
示例5: updateGroupForRoleProtectionGroup
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
/**
* Change the group owner in the Group/Role/ProtectionGroup mapping for the given Protection Groups.
* @param protectionGroupIds IDs of the protection groups to modify - must not be null or empty
* @param oldOwnerGroup the current owner group
* @param newOwnerGroup the new owner group
* @param appName application context name
* @throws CSTransactionException if there is an error in performing the operation
*/
public static void updateGroupForRoleProtectionGroup(List<Long> protectionGroupIds, Group oldOwnerGroup,
Group newOwnerGroup, String appName) throws CSTransactionException {
Session s = null;
Transaction t = null;
try {
s = HibernateSessionFactoryHelper.getAuditSession(ApplicationSessionFactory.getSessionFactory(appName));
t = s.beginTransaction();
Map<String, List<? extends Serializable>> idBlocks = new HashMap<String, List<? extends Serializable>>();
String inClause = HibernateHelper.buildInClause(protectionGroupIds,
"ugrpg.protectionGroup.protectionGroupId", idBlocks);
String queryString = "update " + UserGroupRoleProtectionGroup.class.getName()
+ " ugrpg set ugrpg.group = :newOwnerGroup where ugrpg.group = :oldOwnerGroup and (" + inClause
+ ")";
Query q = s.createQuery(queryString);
q.setParameter("newOwnerGroup", newOwnerGroup);
q.setParameter("oldOwnerGroup", oldOwnerGroup);
HibernateHelper.bindInClauseParameters(q, idBlocks);
q.executeUpdate();
s.flush();
t.commit();
} catch (Exception ex) {
LOG.error(ex);
try {
t.rollback();
} catch (Exception ex3) {
if (LOG.isDebugEnabled()) {
LOG.debug("Authorization|||updateGroupForRoleProtectionGroup|Failure|"
+ "Error in Rolling Back Transaction|" + ex3.getMessage());
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Authorization|||updateGroupForRoleProtectionGroup|Failure|Error in changing the group to "
+ newOwnerGroup + " for " + protectionGroupIds.size() + " Protection Groups|");
}
throw new CSTransactionException("An error occured in changing the group owner of the Protection Groups\n"
+ ex.getMessage(), ex);
} finally {
try {
s.close();
} catch (Exception ex2) {
if (LOG.isDebugEnabled()) {
LOG.debug("Authorization|||updateGroupForRoleProtectionGroup|Failure|Error in Closing Session |"
+ ex2.getMessage());
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Authorization|||updateGroupForRoleProtectionGroup|Success|Successful in changing the group to "
+ newOwnerGroup + " for " + protectionGroupIds.size() + " Protection Groups|");
}
}
示例6: clearProtectionGroupRoles
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
/**
* Removes all roles from a Protection Group for a particular user group.
* @param group user group
* @param protectionGroups protection group from which to remove roles
* @param application the application to which the instance belongs
* @throws CSException on error
*/
// Note: not directly adapted from existing CSM code but follows the conventions of other CSM code
public static void clearProtectionGroupRoles(Group group, Collection<ProtectionGroup> protectionGroups,
Application application) throws CSException {
LOG.debug("Authorization|||clearProtectionGroupRoles|Start|Starting to clear protection group roles|");
Session s = null;
Transaction t = null;
try {
s = HibernateSessionFactoryHelper.getAuditSession(ApplicationSessionFactory.getSessionFactory(application
.getApplicationName()));
t = s.beginTransaction();
String queryString = "delete from " + UserGroupRoleProtectionGroup.class.getName()
+ " where group = :group and (";
Map<String, List<? extends Serializable>> blocks = new HashMap<String, List<? extends Serializable>>();
List<Long> protectionGroupIds = new ArrayList<Long>();
for (ProtectionGroup pg : protectionGroups) {
protectionGroupIds.add(pg.getProtectionGroupId());
}
queryString += HibernateHelper.buildInClause(protectionGroupIds, "protectionGroup.id", blocks);
queryString += ")";
Query q = s.createQuery(queryString);
q.setParameter("group", group);
HibernateHelper.bindInClauseParameters(q, blocks);
q.executeUpdate();
s.flush();
t.commit();
} catch (Exception ex) {
LOG.error(ex);
try {
t.rollback();
} catch (Exception ex3) {
LOG.debug("Authorization|||clearProtectionGroupRoles|Failure|Error in Rolling Back Transaction|"
+ ex3.getMessage());
}
LOG.debug("Authorization|||clearProtectionGroupRoles|Failure|Error in clearing protection group roles|");
throw new CSTransactionException("An error occured in clearing protection group roles\n"
+ ex.getMessage(), ex);
} finally {
try {
s.close();
} catch (Exception ex2) {
LOG.debug("Authorization|||clearProtectionGroupRoles|Failure|Error in Closing Session |"
+ ex2.getMessage());
}
}
LOG.debug("Authorization|||clearProtectionGroupRoles|Success|Successful in clearing protection group roles|");
}
示例7: evaluate
import gov.nih.nci.security.authorization.domainobjects.UserGroupRoleProtectionGroup; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean evaluate(Object o) {
final UserGroupRoleProtectionGroup ugrpg = (UserGroupRoleProtectionGroup) o;
return this.role.equals(ugrpg.getRole().getName());
}