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