Search in sources :

Example 11 with ShaPasswordEncoder

use of org.springframework.security.authentication.encoding.ShaPasswordEncoder 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";
}
Also used : ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) Student(ba.isss.models.Student) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ShaPasswordEncoder (org.springframework.security.authentication.encoding.ShaPasswordEncoder)11 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Student (ba.isss.models.Student)1 URL (java.net.URL)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 EhCacheBasedUserCache (org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache)1 RestTemplate (org.springframework.web.client.RestTemplate)1