Search in sources :

Example 21 with NetworkGroupDTO

use of com.tomasio.projects.trainning.dto.NetworkGroupDTO in project trainning by fernandotomasio.

the class LDAPNetworkGroupDAO method removeOrganization.

@Override
public void removeOrganization(String id) throws DAOException {
    NetworkGroupDTO group = findOrganization(id);
    try {
        Name dn = buildOrganizationsGroupDn(group);
        ldapTemplate.unbind(dn);
    } catch (org.springframework.ldap.NameNotFoundException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) Name(javax.naming.Name) DistinguishedName(org.springframework.ldap.core.DistinguishedName)

Example 22 with NetworkGroupDTO

use of com.tomasio.projects.trainning.dto.NetworkGroupDTO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method findAllOrganizationsGroups.

@Override
public NetworkGroupDTO[] findAllOrganizationsGroups() {
    NetworkGroupDAO dao = factory.getNetworkGroupDAO();
    NetworkGroupDTO[] groupsArray = null;
    try {
        List<NetworkGroupDTO> groups = dao.findAllOrganizations();
        if (groups != null) {
            groupsArray = new NetworkGroupDTO[groups.size()];
            groups.toArray(groupsArray);
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
    return groupsArray;
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO)

Example 23 with NetworkGroupDTO

use of com.tomasio.projects.trainning.dto.NetworkGroupDTO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method findOrganizationGroup.

@Override
public NetworkGroupDTO findOrganizationGroup(String id) {
    NetworkGroupDAO dao = factory.getNetworkGroupDAO();
    NetworkGroupDTO group = null;
    try {
        group = dao.findOrganization(id);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
    return group;
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO)

Example 24 with NetworkGroupDTO

use of com.tomasio.projects.trainning.dto.NetworkGroupDTO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method updateUser.

@Override
@Transactional(readOnly = true)
public void updateUser(NetworkUserDTO user, String[] roles) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        NetworkUserDTO oldUser = userDAO.find(user.getLogin());
        userDAO.update(user);
        if (!oldUser.getOrganizacao().equals(user.getOrganizacao())) {
            // REMOVER DO GRUPO DA ORGANIZAÇÃO ANTIGA
            NetworkGroupDTO oldOrganizationGroup = groupDAO.findOrganization(oldUser.getOrganizacao());
            if (oldOrganizationGroup != null) {
                oldOrganizationGroup.getMembers().remove(oldUser.getId());
                if (oldOrganizationGroup.getMembers().size() > 0) {
                    groupDAO.update(oldOrganizationGroup);
                } else {
                    groupDAO.removeOrganization(oldUser.getOrganizacao());
                }
            }
            // ADICIONAR AO GRUPO DA ORGANIZAÇÃO NOVA
            Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
            NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
            if (organizationGroup == null) {
                organizationGroup = new NetworkGroupDTO();
                organizationGroup.setNome(organizacao.getSigla());
                organizationGroup.setDescricao(organizacao.getNome());
                organizationGroup.getMembers().add(user.getId());
                groupDAO.createOrganization(organizationGroup);
            } else {
                organizationGroup.getMembers().add(user.getId());
                groupDAO.update(organizationGroup);
            }
        }
        // REMOVER DE TODAS AS ROLES
        List<NetworkGroupDTO> roleGroups = groupDAO.findAllRoles();
        for (NetworkGroupDTO roleGroup : roleGroups) {
            NetworkGroupDTO r = groupDAO.findRole(roleGroup.getNome());
            r.getMembers().remove(oldUser.getId());
            groupDAO.update(r);
        }
        // ADICIONAR NOVAS ROLES
        if (roles != null) {
            for (String role : roles) {
                NetworkGroupDTO roleGroup = groupDAO.findRole(role);
                roleGroup.getMembers().add(user.getId());
                groupDAO.update(roleGroup);
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)24 DAOException (com.tomasio.projects.trainning.exception.DAOException)11 CoreException (com.tomasio.projects.trainning.exeption.CoreException)11 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)9 ArrayList (java.util.ArrayList)7 NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)5 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)4 Organizacao (com.tomasio.projects.trainning.model.Organizacao)4 DistinguishedName (org.springframework.ldap.core.DistinguishedName)4 Transactional (org.springframework.transaction.annotation.Transactional)4 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)3 UsuarioForm (com.tomasio.projects.trainning.form.UsuarioForm)2 Name (javax.naming.Name)2 AuthenticationException (org.springframework.ldap.AuthenticationException)2 InetOrgPerson (org.springframework.security.ldap.userdetails.InetOrgPerson)2 DAOFactory (com.tomasio.projects.trainning.dao.DAOFactory)1 GrupoForm (com.tomasio.projects.trainning.form.GrupoForm)1 HashMap (java.util.HashMap)1