Search in sources :

Example 1 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project trainning by fernandotomasio.

the class TurmasEfetivasController method saveApresentacoes.

@RequestMapping("/save_apresentacoes")
public String saveApresentacoes(Model model, WebRequest request, @ModelAttribute("turma") @Valid TurmaEfetivaDTO turma, final RedirectAttributes redirectAttributes) throws ParseException {
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String[] matriculas = request.getParameterValues("matriculas");
    // String[] selecionados = request.getParameterValues("selecionados");
    // String[] datas = request.getParameterValues("data");
    String[] observacoes = request.getParameterValues("obs");
    List<ApresentacaoDTO> apresentacoes = new ArrayList<ApresentacaoDTO>();
    for (int i = 0; i < matriculas.length; i++) {
        MatriculaDTO matricula = atividadesEnsinoService.findMatricula(Long.parseLong(matriculas[i]));
        ApresentacaoDTO apresentacao = new ApresentacaoDTO();
        apresentacao.setMatricula(matricula);
        String[] selecionados = request.getParameterValues("selecionados" + matriculas[i]);
        apresentacao.setComparecimento(Boolean.parseBoolean(selecionados[0]));
        apresentacao.setDataApresentacao(new Date());
        apresentacao.setObservacao(observacoes[i]);
        // ajuste 066 do helpdesk - Ten Aguiar
        // String username = request.getParameter("username");
        String userLogin = user.getUid();
        // NetworkUserDTO usuario = userService.findUser(userLogin);
        apresentacao.setOperador(userLogin);
        apresentacoes.add(apresentacao);
    }
    ApresentacaoDTO[] arrayApresentacoes = new ApresentacaoDTO[apresentacoes.size()];
    apresentacoes.toArray(arrayApresentacoes);
    try {
        atividadesEnsinoService.createApresentacao(arrayApresentacoes);
        // model.addAttribute("successMessage", "Apresentação criada com sucesso.");
        redirectAttributes.addFlashAttribute("successMessage", "Apresentação criada com sucesso.");
    } catch (CoreException e) {
        // model.addAttribute("errorMessage", e.getMessage());
        redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
    }
    model.addAttribute("tab", "apresentacoes");
    return "redirect:detail/apresentacoes";
}
Also used : PreMatriculaDTO(com.tomasio.projects.trainning.dto.PreMatriculaDTO) NotificacaoMatriculaDTO(com.tomasio.projects.trainning.dto.NotificacaoMatriculaDTO) MatriculaDTO(com.tomasio.projects.trainning.dto.MatriculaDTO) CancelamentoMatriculaDTO(com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) ArrayList(java.util.ArrayList) ApresentacaoDTO(com.tomasio.projects.trainning.dto.ApresentacaoDTO) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project trainning by fernandotomasio.

the class SettingsController method savePassword.

@RequestMapping("/save_password")
public String savePassword(Model model, @Valid PasswordForm passwordForm, BindingResult bindingResult, WebRequest request) {
    if (bindingResult.hasErrors()) {
        return "settings/form_password";
    }
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String userLogin = user.getUid();
    NetworkUserDTO usuario = userService.findUser(userLogin);
    usuario.setPassword(passwordForm.getPassword());
    userService.updateUser(usuario);
    // 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 3 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project trainning by fernandotomasio.

the class AuthenticationSuccessHandlerMock method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) throws IOException, ServletException {
    // (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    final InetOrgPerson user = Mockito.mock(InetOrgPerson.class);
    Mockito.when(user.getUid()).thenReturn("fernandofot");
    Mockito.when(user.getO()).thenReturn("COMGAP");
    String userLogin = user.getUid();
    // OrganizacaoDTO[] organizacoesGestoras = atividadesEnsinoService.findAllOrganizacoesGestoras();
    // selecionar todas as ORGANIZAÇÕES que possuem PLANO DE ENSINO
    OrganizacaoDTO[] organizacoesGestoras = atividadesEnsinoService.findAllOrganizacoesHasPlano();
    OrganizacaoDTO organizacao = organizationalService.findOrganizacaoBySigla(user.getO());
    request.getSession().setAttribute("userOrganization", organizacao);
    request.getSession().setAttribute("organizacoesGestoras", organizacoesGestoras);
    request.getSession().setAttribute("topOrganization", organizacao.getTopOrganizacao());
    request.getSession().setAttribute("userLogin", userLogin);
    request.getSession().setAttribute("permissionsManager", businessPermissionManager);
    request.getRequestDispatcher("/").forward(request, response);
}
Also used : InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO)

Example 4 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project trainning by fernandotomasio.

the class AnotacoesController method getAnotacoes.

@RequestMapping("/ajax")
@ResponseBody
public List getAnotacoes(Model model, WebRequest request) {
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String userLogin = user.getUid();
    List<Map> result = new ArrayList<Map>();
    String objectId = request.getParameter("objectId");
    AnotacaoDTO[] anotacoes = systemService.findAllAnotacoesByObjectId(objectId);
    for (AnotacaoDTO anotacao : anotacoes) {
        Map<Object, Object> item = new HashMap<>();
        item.put("user", anotacao.getUser());
        item.put("text", anotacao.getTexto());
        item.put("time", anotacao.getDataCriacaoFormatted());
        boolean editable = false;
        DateTime hoje = new DateTime();
        DateTime dataAnotacao = new DateTime(anotacao.getDataCriacao().getTime());
        Interval interval = new Interval(dataAnotacao, hoje);
        int intervaloEmDias = interval.toPeriod().getDays();
        if (anotacao.getUser().equals(userLogin) && intervaloEmDias == 0) {
            editable = true;
        }
        item.put("editable", editable);
        item.put("id", anotacao.getId());
        result.add(item);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) HashMap(java.util.HashMap) Map(java.util.Map) Interval(org.joda.time.Interval) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project spring-security by spring-projects.

the class LdapUserServiceBeanDefinitionParserTests method inetOrgContextMapperIsSupported.

@Test
public void inetOrgContextMapperIsSupported() {
    setContext("<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='inetOrgPerson'/>");
    UserDetailsService uds = (UserDetailsService) this.appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");
    assertThat(ben instanceof InetOrgPerson).isTrue();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) Test(org.junit.jupiter.api.Test)

Aggregations

InetOrgPerson (org.springframework.security.ldap.userdetails.InetOrgPerson)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 InetOrgPersonContextMapper (org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper)4 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)2 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)2 NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)2 NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)2 NotificacaoMatriculaDTO (com.tomasio.projects.trainning.dto.NotificacaoMatriculaDTO)2 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)2 PreMatriculaDTO (com.tomasio.projects.trainning.dto.PreMatriculaDTO)2 CoreException (com.tomasio.projects.trainning.exeption.CoreException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 UserDetails (org.springframework.security.core.userdetails.UserDetails)2 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)2 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 AnotacaoDTO (com.tomasio.projects.trainning.dto.AnotacaoDTO)1