Search in sources :

Example 11 with NetworkGroupDTO

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

the class LDAPNetworkGroupDAO method findOrganization.

@Override
public NetworkGroupDTO findOrganization(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", ORGANIZATIONS_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 12 with NetworkGroupDTO

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

the class TestesDAO method main.

public static void main(String[] args) throws DAOException {
    @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext("persist-context.xml");
    DAOFactory factory = (DAOFactory) context.getBean("daoFactory");
    NetworkGroupDAO dao = factory.getNetworkGroupDAO();
    SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
    HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
    Session session = transactionManager.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    NetworkGroupDTO group = dao.findRole("OperadorLocal");
    group.getMembers().add("uid=tasdfasd,ou=people");
    dao.update(group);
    tx.commit();
    session.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) HibernateTransactionManager(org.springframework.orm.hibernate4.HibernateTransactionManager) Transaction(org.hibernate.Transaction) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DAOFactory(com.tomasio.projects.trainning.dao.DAOFactory) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Session(org.hibernate.Session)

Example 13 with NetworkGroupDTO

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

the class SettingsController method showIndex.

@RequestMapping({ "/", "/index", "" })
public String showIndex(Model model, WebRequest request) {
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String userLogin = user.getUid();
    // buscar o usuário pelo ID
    NetworkUserDTO usuario = userService.findUser(userLogin);
    // buscar as roles do usuário
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    List<String> rolesAssigned = new ArrayList<>();
    for (NetworkGroupDTO group : groups) {
        if (group.getMembers().contains(usuario.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", usuario);
    return "settings";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with NetworkGroupDTO

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

the class UsuariosController method editUsuario.

@RequestMapping("/edit")
public String editUsuario(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, WebRequest request) {
    String usuarioId = request.getParameter("usuarioId");
    // buscar usuário pelo ID
    NetworkUserDTO dto = userService.findUser(usuarioId);
    // 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());
        }
    });
    UsuarioForm usuarioForm = new UsuarioForm();
    usuarioForm.setOp("EDIT");
    usuarioForm.setEmail(dto.getEmail());
    usuarioForm.setLogin(dto.getLogin());
    usuarioForm.setNome(dto.getNome());
    usuarioForm.setNomeGuerra(dto.getNomeGuerra());
    OrganizacaoDTO organizacao = organizationalService.findOrganizacaoBySigla(dto.getOrganizacao());
    usuarioForm.setOrganizacaoId(organizacao.getId());
    usuarioForm.setPosto(dto.getPosto());
    usuarioForm.setTelefone(dto.getTelefone());
    model.addAttribute(usuarioForm);
    model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
    model.addAttribute("roles", roles);
    model.addAttribute("rolesAssigned", rolesAssigned);
    return "usuarios/form";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) UsuarioForm(com.tomasio.projects.trainning.form.UsuarioForm) ArrayList(java.util.ArrayList) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with NetworkGroupDTO

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

the class UsuariosController method showDetails.

@RequestMapping("/detail")
public String showDetails(Model model, WebRequest request) {
    String usuarioId = request.getParameter("usuarioId");
    // buscar o usuário pelo ID
    NetworkUserDTO usuario = userService.findUser(usuarioId);
    // buscar as roles do usuário
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    List<String> rolesAssigned = new ArrayList<>();
    for (NetworkGroupDTO group : groups) {
        if (group.getMembers().contains(usuario.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", usuario);
    return "usuarios/detail";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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