Search in sources :

Example 16 with NetworkGroupDTO

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

the class UsuariosController method saveUsuario.

@RequestMapping("/save")
public String saveUsuario(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, @Valid UsuarioForm usuarioForm, BindingResult bindingResult, WebRequest request) {
    String[] permissions = request.getParameterValues("permissions");
    if (permissions != null) {
        for (String permission : permissions) {
            System.out.println("permission: " + permission);
        }
    }
    if (usuarioForm.getSourceButton() != null && usuarioForm.getSourceButton().equals("resetPassword")) {
        userService.updateUserPassword(generatePassword(), usuarioForm.getLogin());
        NetworkGroupDTO[] groups = userService.findAllRoleGroups();
        // jogo no ArrayList para trabalhar
        List<NetworkGroupDTO> roles = new ArrayList();
        roles.addAll(Arrays.asList(groups));
        // ordenar a lista de roles
        Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

            @Override
            public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
                return o1.getDescricao().compareTo(o2.getDescricao());
            }
        });
        model.addAttribute("roles", roles);
        // buscar as roles do marcadas
        if (permissions != null) {
            List<String> rolesAssigned = new ArrayList<>();
            for (NetworkGroupDTO group : groups) {
                for (String permission : permissions) {
                    if (permission.equals(group.getNome())) {
                        rolesAssigned.add(group.getNome());
                    }
                }
            }
            model.addAttribute("rolesAssigned", rolesAssigned);
        }
        model.addAttribute("organizacoes", organizationalService.findAllOrganizacoes());
        model.addAttribute("successMessage", "Senha reinicializada com sucesso!<br/> Um email automático foi enviado para o usuário");
        return "usuarios/form";
    }
    if (bindingResult.hasErrors()) {
        model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
        NetworkGroupDTO[] groups = userService.findAllRoleGroups();
        // jogo no ArrayList para trabalhar
        List<NetworkGroupDTO> roles = new ArrayList();
        roles.addAll(Arrays.asList(groups));
        // ordenar a lista de roles
        Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

            @Override
            public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
                return o1.getDescricao().compareTo(o2.getDescricao());
            }
        });
        model.addAttribute("roles", roles);
        // buscar as roles do marcadas
        if (permissions != null) {
            List<String> rolesAssigned = new ArrayList<>();
            for (NetworkGroupDTO group : groups) {
                for (String permission : permissions) {
                    if (permission.equals(group.getNome())) {
                        rolesAssigned.add(group.getNome());
                    }
                }
            }
            model.addAttribute("rolesAssigned", rolesAssigned);
        }
        return "usuarios/form";
    }
    NetworkUserDTO dto;
    if (usuarioForm.getOp().equals("NEW")) {
        dto = new NetworkUserDTO();
        dto.setPassword(generatePassword());
    } else {
        dto = userService.findUser(usuarioForm.getLogin());
    }
    if (usuarioForm.getOrganizacaoId() > 0) {
        OrganizacaoDTO organizacao = organizationalService.findOrganizacao(usuarioForm.getOrganizacaoId());
        dto.setOrganizacao(organizacao.getSigla());
    }
    // Inserção do campo SENHA como solução do problema do PROXY
    if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
        dto.setPassword(usuarioForm.getPassword());
    }
    dto.setLogin(usuarioForm.getLogin());
    dto.setNome(usuarioForm.getNome());
    dto.setNomeGuerra(usuarioForm.getNomeGuerra());
    dto.setPosto(usuarioForm.getPosto());
    dto.setTarjeta(usuarioForm.getPosto() + " " + usuarioForm.getNomeGuerra());
    dto.setTelefone(usuarioForm.getTelefone());
    dto.setEmail(usuarioForm.getEmail());
    if (usuarioForm.getOp().equals("NEW")) {
        try {
            userService.createUser(dto, permissions);
            // Inserção do campo SENHA como solução do problema do PROXY
            if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
                model.addAttribute("successMessage", "Usuário criado com sucesso!");
                model.addAttribute("errorMessage", "Faz-se necessário contato com o usuário para informar a senha definida!");
            } else {
                model.addAttribute("successMessage", "Usuário criado com sucesso!<br/> Um email automático foi enviado para o usuário");
            }
        } catch (CoreException e) {
            model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("usuarios", userService.findAllUsers());
            return "usuarios";
        }
    } else {
        userService.updateUser(dto, permissions);
        if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
            model.addAttribute("successMessage", "Usuário atualizado com sucesso!");
            model.addAttribute("errorMessage", "Faz-se necessário contato com o usuário para informar a nova senha definida!");
        } else {
            model.addAttribute("successMessage", "Usuário atualizado com sucesso!");
        }
    }
    // buscar usuário pelo login
    dto = userService.findUser(usuarioForm.getLogin());
    // buscar as roles do usuário
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    List<String> rolesAssigned = new ArrayList<>();
    for (NetworkGroupDTO group : groups) {
        if (group.getMembers().contains(dto.getId())) {
            rolesAssigned.add(group.getNome());
        }
    }
    // jogo no ArrayList para trabalhar
    List<NetworkGroupDTO> roles = new ArrayList();
    roles.addAll(Arrays.asList(groups));
    // ordenar a lista de roles
    Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

        @Override
        public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
            return o1.getDescricao().compareTo(o2.getDescricao());
        }
    });
    model.addAttribute("roles", roles);
    model.addAttribute("rolesAssigned", rolesAssigned);
    model.addAttribute("usuario", dto);
    return "usuarios/detail";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) ArrayList(java.util.ArrayList) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with NetworkGroupDTO

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

the class UsuariosController method newUsuário.

@RequestMapping("/new")
public String newUsuário(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, WebRequest request) {
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    // jogo no ArrayList para trabalhar
    List<NetworkGroupDTO> roles = new ArrayList();
    roles.addAll(Arrays.asList(groups));
    // ordenar a lista de roles
    Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

        @Override
        public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
            return o1.getDescricao().compareTo(o2.getDescricao());
        }
    });
    model.addAttribute("roles", roles);
    UsuarioForm usuarioForm = new UsuarioForm();
    usuarioForm.setOp("NEW");
    model.addAttribute(usuarioForm);
    model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
    return "usuarios/form";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) UsuarioForm(com.tomasio.projects.trainning.form.UsuarioForm) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with NetworkGroupDTO

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

the class GruposController method editGrupo.

@RequestMapping("/edit")
public String editGrupo(Model model, WebRequest request) {
    String grupoId = request.getParameter("grupoId");
    NetworkGroupDTO dto = userService.findRoleGroup(grupoId);
    GrupoForm grupoForm = new GrupoForm();
    grupoForm.setNome(dto.getNome());
    grupoForm.setDescricao(dto.getDescricao());
    grupoForm.setId(dto.getId());
    model.addAttribute(grupoForm);
    return "grupos/form";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) GrupoForm(com.tomasio.projects.trainning.form.GrupoForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with NetworkGroupDTO

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

the class LDAPNetworkGroupDAO method findRole.

@Override
public NetworkGroupDTO findRole(String uid) throws DAOException {
    NetworkGroupDTO group = null;
    try {
        DistinguishedName dn = new DistinguishedName();
        dn.add("ou", "groups");
        dn.add("ou", APPLICATION_GROUP_BRANCH);
        dn.add("ou", ROLES_GROUP_BRANCH);
        dn.add("cn", uid);
        group = (NetworkGroupDTO) ldapTemplate.lookup(dn, getGroupContextMapper());
    } catch (AuthenticationException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
        throw new DAOException(MessageHelper.getMessage("systemUsers.find.error"));
    } catch (org.springframework.ldap.NameNotFoundException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
    }
    return group;
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) DistinguishedName(org.springframework.ldap.core.DistinguishedName) AuthenticationException(org.springframework.ldap.AuthenticationException)

Example 20 with NetworkGroupDTO

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

the class LDAPNetworkGroupDAO method removeRole.

@Override
public void removeRole(String id) throws DAOException {
    NetworkGroupDTO group = findRole(id);
    try {
        Name dn = buildRolesGroupDn(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)

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