Search in sources :

Example 1 with OPERATION_ADD_MEMBERS

use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_ADD_MEMBERS in project studio by craftercms.

the class GroupServiceImpl method addGroupMembers.

@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public List<User> addGroupMembers(long groupId, List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException, GroupNotFoundException, AuthenticationException {
    List<User> users = groupServiceInternal.addGroupMembers(groupId, userIds, usernames);
    Group group = groupServiceInternal.getGroup(groupId);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    List<AuditLogParameter> parameters = new ArrayList<AuditLogParameter>();
    for (User user : users) {
        AuditLogParameter parameter = new AuditLogParameter();
        parameter.setTargetId(Long.toString(user.getId()));
        parameter.setTargetType(TARGET_TYPE_USER);
        parameter.setTargetValue(user.getUsername());
        parameters.add(parameter);
    }
    auditLog.setParameters(parameters);
    auditLog.setOperation(OPERATION_ADD_MEMBERS);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(Long.toString(groupId));
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(group.getGroupName());
    auditServiceInternal.insertAuditLog(auditLog);
    return users;
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) User(org.craftercms.studio.api.v2.dal.User) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 2 with OPERATION_ADD_MEMBERS

use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_ADD_MEMBERS 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;
}
Also used : UserGroup(org.craftercms.studio.api.v2.dal.UserGroup) Group(org.craftercms.studio.api.v2.dal.Group) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) AuthenticationSystemException(org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) StudioConfiguration(org.craftercms.studio.api.v2.utils.StudioConfiguration) AuditServiceInternal(org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal) UserDAO(org.craftercms.studio.api.v2.dal.UserDAO) SiteService(org.craftercms.studio.api.v1.service.site.SiteService) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) GroupDAO(org.craftercms.studio.api.v2.dal.GroupDAO)

Example 3 with OPERATION_ADD_MEMBERS

use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_ADD_MEMBERS 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;
}
Also used : UserGroup(org.craftercms.studio.api.v2.dal.UserGroup) Group(org.craftercms.studio.api.v2.dal.Group) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) AuthenticationException(org.springframework.ldap.AuthenticationException) CommunicationException(org.springframework.ldap.CommunicationException) AuthenticationSystemException(org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException) BadCredentialsException(org.craftercms.studio.api.v1.exception.security.BadCredentialsException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) StudioConfiguration(org.craftercms.studio.api.v2.utils.StudioConfiguration) AuditServiceInternal(org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal) UserDAO(org.craftercms.studio.api.v2.dal.UserDAO) SiteService(org.craftercms.studio.api.v1.service.site.SiteService) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) GroupDAO(org.craftercms.studio.api.v2.dal.GroupDAO)

Aggregations

ArrayList (java.util.ArrayList)3 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)3 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)3 Group (org.craftercms.studio.api.v2.dal.Group)3 User (org.craftercms.studio.api.v2.dal.User)3 HashMap (java.util.HashMap)2 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)2 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)2 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)2 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)2 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)2 GroupDAO (org.craftercms.studio.api.v2.dal.GroupDAO)2 UserDAO (org.craftercms.studio.api.v2.dal.UserDAO)2 UserGroup (org.craftercms.studio.api.v2.dal.UserGroup)2 AuditServiceInternal (org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal)2 StudioConfiguration (org.craftercms.studio.api.v2.utils.StudioConfiguration)2 NamingException (javax.naming.NamingException)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 BadCredentialsException (org.craftercms.studio.api.v1.exception.security.BadCredentialsException)1