use of ba.isss.models.Student in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class TokenAuthenticationService method getAuthentication.
public static Authentication getAuthentication(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
studentRepository = webApplicationContext.getBean(StudentRepository.class);
String token = request.getHeader(HEADER_STRING);
if (token != null) {
// parse the token.
String user = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token.replace(TOKEN_PREFIX, "")).getBody().getSubject();
Student student = studentRepository.findStudentByUsername(user);
Collection<GrantedAuthority> authorities = new ArrayList<>();
if (student != null) {
authorities.add(new SimpleGrantedAuthority("ROLE_STUDENT"));
}
return user != null ? new UsernamePasswordAuthenticationToken(user, null, authorities) : null;
}
return null;
}
use of ba.isss.models.Student in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class PrijavaController method prijaviIspit.
@PreAuthorize("hasAnyRole('ROLE_STUDENT')")
@PostMapping(path = "/prijavi")
public void prijaviIspit(@ModelAttribute("prijava") Prijava p, Principal principal) throws Exception {
Student s = studentService.findByUsername(principal.getName());
prijavaService.SavePrijava(p, s);
}
use of ba.isss.models.Student in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class PrijavaController method odjaviIspit.
@PreAuthorize("hasAnyRole('ROLE_STUDENT')")
@RequestMapping(path = "/odjavi", method = RequestMethod.POST)
@ResponseBody
public void odjaviIspit(@ModelAttribute("odjava") Prijava p, Principal principal) throws Exception {
Student s = studentService.findByUsername(principal.getName());
prijavaService.DeletePrijava(p, s);
}
use of ba.isss.models.Student in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class StudentController method updatePassword.
@PreAuthorize("hasAnyRole('ROLE_STUDENT')")
@RequestMapping(value = "/update_password", method = RequestMethod.POST)
@ResponseBody
public String updatePassword(Principal principal, @RequestParam("password1") String pass1, @RequestParam("password2") String pass2, @RequestParam("password") String pass) throws NoSuchAlgorithmException {
Student s = studentService.findOne(studentService.findByUsername(principal.getName()).getId());
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String oldPassHash = encoder.encodePassword(pass, null);
String newPassHash = encoder.encodePassword(pass1, null);
if (pass1.length() < 5)
return "Prekratak password";
if (!s.getPassword().equals(oldPassHash))
return "Pogresan stari password";
if (!pass1.equals(pass2))
return "Passwordi razliciti";
if (studentService.updatePassword(studentService.findByUsername(principal.getName()).getId(), newPassHash) == 0)
return "ERROR";
return "Password promijenjen";
}
Aggregations