use of org.craftercms.studio.api.v2.dal.QueryParameterNames.GROUP_ID in project studio by craftercms.
the class GroupServiceInternalImpl method getGroup.
@Override
public Group getGroup(long groupId) throws GroupNotFoundException, ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(GROUP_ID, groupId);
Group group;
try {
group = groupDao.getGroup(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
if (group != null) {
return group;
} else {
throw new GroupNotFoundException("No group found for id '" + groupId + "'");
}
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.GROUP_ID in project studio by craftercms.
the class GroupServiceInternalImpl method groupExists.
@Override
public boolean groupExists(long groupId, String groupName) throws ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(GROUP_ID, groupId);
params.put(GROUP_NAME, groupName);
try {
Integer result = groupDao.groupExists(params);
return (result > 0);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.GROUP_ID in project studio by craftercms.
the class HeadersAuthenticationProvider method upsertUserGroup.
protected boolean upsertUserGroup(String groupName, String username, AuthenticationChain authenticationChain) throws SiteNotFoundException {
GroupDAO groupDao = authenticationChain.getGroupDao();
UserDAO userDao = authenticationChain.getUserDao();
AuditServiceInternal auditServiceInternal = authenticationChain.getAuditServiceInternal();
SiteService siteService = authenticationChain.getSiteService();
StudioConfiguration studioConfiguration = authenticationChain.getStudioConfiguration();
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
try {
Map<String, Object> params = new HashMap<>();
params.put(ORG_ID, DEFAULT_ORGANIZATION_ID);
params.put(GROUP_NAME, groupName);
params.put(GROUP_DESCRIPTION, "Externally managed group - " + groupName);
groupDao.createGroup(params);
} catch (Exception e) {
logger.debug("Error creating group", e);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(GROUP_NAME, groupName);
Group group = groupDao.getGroupByName(params);
if (group != null) {
List<String> usernames = new ArrayList<String>();
params = new HashMap<>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
User user = userDao.getUserByIdOrUsername(params);
List<Long> users = new ArrayList<Long>();
users.add(user.getId());
params = new HashMap<>();
params.put(USER_IDS, users);
params.put(GROUP_ID, group.getId());
try {
groupDao.addGroupMembers(params);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_ADD_MEMBERS);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(username);
auditLog.setPrimaryTargetId(group.getGroupName() + ":" + user.getUsername());
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(user.getUsername());
auditServiceInternal.insertAuditLog(auditLog);
} catch (Exception e) {
logger.debug("Unknown database error", e);
}
}
return true;
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.GROUP_ID in project studio by craftercms.
the class LdapAuthenticationProvider method upsertUserGroup.
protected boolean upsertUserGroup(String groupName, String username, AuthenticationChain authenticationChain) {
UserDAO userDao = authenticationChain.getUserDao();
GroupDAO groupDao = authenticationChain.getGroupDao();
AuditServiceInternal auditServiceInternal = authenticationChain.getAuditServiceInternal();
SiteService siteService = authenticationChain.getSiteService();
StudioConfiguration studioConfiguration = authenticationChain.getStudioConfiguration();
try {
Map<String, Object> params = new HashMap<>();
params.put(ORG_ID, DEFAULT_ORGANIZATION_ID);
params.put(GROUP_NAME, groupName);
params.put(GROUP_DESCRIPTION, "Externally managed group - " + groupName);
groupDao.createGroup(params);
} catch (Exception e) {
logger.warn("Error creating group", e);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(GROUP_NAME, groupName);
Group group = groupDao.getGroupByName(params);
if (group != null) {
params = new HashMap<>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
User user = userDao.getUserByIdOrUsername(params);
List<Long> users = new ArrayList<Long>();
users.add(user.getId());
params = new HashMap<>();
params.put(USER_IDS, users);
params.put(GROUP_ID, group.getId());
try {
groupDao.addGroupMembers(params);
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_ADD_MEMBERS);
auditLog.setActorId(user.getUsername());
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(group.getGroupName() + ":" + user.getUsername());
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(user.getUsername());
auditServiceInternal.insertAuditLog(auditLog);
} catch (Exception e) {
logger.debug("Unknown database error", e);
}
}
return true;
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.GROUP_ID in project studio by craftercms.
the class GroupServiceInternalImpl method getGroupMembers.
@Override
public List<User> getGroupMembers(long groupId, int offset, int limit, String sort) throws GroupNotFoundException, ServiceLayerException {
if (!groupExists(groupId, StringUtils.EMPTY)) {
throw new GroupNotFoundException("No group found for id '" + groupId + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(GROUP_ID, groupId);
params.put(OFFSET, offset);
params.put(LIMIT, limit);
params.put(SORT, sort);
try {
return groupDao.getGroupMembers(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
Aggregations