Search in sources :

Example 6 with InetOrgPerson

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

the class InetOrgPersonMixinTests method serializeWhenEraseCredentialInvokedThenUserPasswordIsNull.

@Test
public void serializeWhenEraseCredentialInvokedThenUserPasswordIsNull() throws JsonProcessingException, JSONException {
    InetOrgPersonContextMapper mapper = new InetOrgPersonContextMapper();
    InetOrgPerson p = (InetOrgPerson) mapper.mapUserFromContext(createUserContext(), "ghengis", AuthorityUtils.NO_AUTHORITIES);
    p.eraseCredentials();
    String actualJson = this.mapper.writeValueAsString(p);
    JSONAssert.assertEquals(INET_ORG_PERSON_JSON.replaceAll("\"" + USER_PASSWORD + "\"", "null"), actualJson, true);
}
Also used : InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) InetOrgPersonContextMapper(org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper) Test(org.junit.jupiter.api.Test)

Example 7 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson in project hub-alert by blackducksoftware.

the class AuthenticationEventManager method sendAuthenticationEvent.

public void sendAuthenticationEvent(Authentication authentication, AuthenticationType authenticationType) {
    String username;
    String emailAddress = null;
    try {
        Object authPrincipal = authentication.getPrincipal();
        if (authentication instanceof SAMLAuthenticationToken) {
            SAMLAuthenticationToken samlAuthenticationToken = (SAMLAuthenticationToken) authentication;
            SAMLMessageContext credentials = samlAuthenticationToken.getCredentials();
            NameIDImpl subjectNameIdentifier = (NameIDImpl) credentials.getSubjectNameIdentifier();
            username = subjectNameIdentifier.getValue();
            emailAddress = username;
        } else if (authPrincipal instanceof InetOrgPerson) {
            username = authentication.getName();
            emailAddress = ((InetOrgPerson) authPrincipal).getMail();
        } else {
            username = authentication.getName();
        }
        sendAuthenticationEvent(username, emailAddress, authenticationType, authentication.getAuthorities());
    } catch (Exception e) {
        logger.warn("Unable to send authentication event");
        logger.debug("Authentication event failure", e);
    }
}
Also used : NameIDImpl(org.opensaml.saml2.core.impl.NameIDImpl) SAMLMessageContext(org.springframework.security.saml.context.SAMLMessageContext) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) SAMLAuthenticationToken(org.springframework.security.saml.SAMLAuthenticationToken) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 8 with InetOrgPerson

use of org.springframework.security.ldap.userdetails.InetOrgPerson 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 9 with InetOrgPerson

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

the class TurmasEfetivasController method saveCancelamento.

@RequestMapping("/save_cancelamento")
public String saveCancelamento(@Valid @ModelAttribute("cancelamentoForm") CancelamentoForm form, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return "turmas_efetivas/form_cancelamento";
    }
    TurmaEfetivaDTO turma = atividadesEnsinoService.findTurmaEfetiva(form.getTurmaId());
    turma.setCancelado(true);
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String userLogin = user.getUid();
    turma.setUsuarioCancelamento(userLogin);
    turma.setJustificativaCancelamento(form.getJustificativa());
    atividadesEnsinoService.updateTurmaEfetiva(turma);
    return "redirect:detail?turmaId=" + form.getTurmaId();
}
Also used : TurmaEfetivaDTO(com.tomasio.projects.trainning.dto.TurmaEfetivaDTO) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with InetOrgPerson

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

the class TurmasEfetivasController method saveConclusoes.

@RequestMapping("/save_conclusoes")
public String saveConclusoes(Model model, WebRequest request, @ModelAttribute("turma") TurmaEfetivaDTO turma, final RedirectAttributes redirectAttributes) {
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String[] matriculas = request.getParameterValues("matriculasIds");
    String[] aproveitamentos = request.getParameterValues("aproveitamentos-mirror");
    String[] observacoes = request.getParameterValues("observacoes");
    String[] parecer = request.getParameterValues("parecer");
    // for (int i = 0; i < matriculas.length; i++) {
    // System.out.println(matriculas[i] + aproveitamentos[i] + observacoes[i]);
    // }
    List<ConclusaoDTO> conclusoes = new ArrayList<ConclusaoDTO>();
    for (int i = 0; i < matriculas.length; i++) {
        MatriculaDTO matricula = atividadesEnsinoService.findMatricula(Long.parseLong(matriculas[i]));
        ConclusaoDTO conclusao = new ConclusaoDTO();
        CapacitacaoDTO capacitacao = trainningService.findCurso(turma.getCurso().getId());
        PeriodoDTO periodo = new PeriodoDTO();
        periodo.setDataInicio(turma.getDataInicio());
        periodo.setDataTermino(turma.getDataTermino());
        conclusao.setComAproveitamento(Boolean.parseBoolean(aproveitamentos[i]));
        conclusao.setObservacao(observacoes[i]);
        // ajuste para COMGAP 14/12/2015 - Ten Aguiar
        conclusao.setParecer(parecer[i]);
        int ano = 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyy");
        if (turma.getExercicio() != null) {
            Integer.parseInt(df.format(turma.getExercicio()));
        }
        conclusao.setAno(ano);
        conclusao.setCapacitacao(capacitacao);
        conclusao.setLocal(turma.getLocal());
        conclusao.setMatricula(matricula);
        conclusao.setPeriodo(periodo);
        conclusao.setPessoa(matricula.getPessoa());
        // ajuste 048 do helpdesk - Ten Aguiar
        // String username = request.getParameter("username");
        String userLogin = user.getUid();
        conclusao.setOperador(userLogin);
        conclusao.setDataOperacao(new Date());
        conclusoes.add(conclusao);
    }
    ConclusaoDTO[] arrayConclusoes = new ConclusaoDTO[conclusoes.size()];
    conclusoes.toArray(arrayConclusoes);
    try {
        atividadesEnsinoService.createConclusao(arrayConclusoes);
        // model.addAttribute("successMessage", "Conclusão criada com sucesso.");
        redirectAttributes.addFlashAttribute("successMessage", "Conclusão criada com sucesso.");
    } catch (CoreException e) {
        // model.addAttribute("errorMessage", e.getMessage());
        redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
    }
    model.addAttribute("tab", "concluidos");
    return "redirect:detail/conclusoes";
}
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) CertificadoConclusaoDTO(com.tomasio.projects.trainning.dto.CertificadoConclusaoDTO) ConclusaoDTO(com.tomasio.projects.trainning.dto.ConclusaoDTO) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) ArrayList(java.util.ArrayList) Date(java.util.Date) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PeriodoDTO(com.tomasio.projects.trainning.dto.PeriodoDTO) CapacitacaoDTO(com.tomasio.projects.trainning.dto.CapacitacaoDTO) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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