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);
}
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);
}
}
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";
}
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();
}
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";
}
Aggregations