Created
September 26, 2017 14:13
-
-
Save Romain-P/260a0cb78c119333a5d2e34a8418767c to your computer and use it in GitHub Desktop.
Exemple d'implémentation authentification ortec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class OrtecAuthenticationProviderImpl extends OrtecAuthenticationProvider<UserDTO> { | |
| @Autowired | |
| private UserRepository repository; | |
| @Override | |
| protected void configure(AuthenticationConfigurer<UserDTO> configurer) { | |
| configurer | |
| .loadUserByUsername(username -> repository.findByUsername(username)) | |
| .createUserEntity(ldap -> { | |
| UserDTO dto = new UserDTO(); | |
| dto.setUsername(ldap.getUsername()); | |
| Long id = repository.create(dto); | |
| dto.setId(id); | |
| return dto; | |
| }) | |
| .rescueInvalidAuthentication((username, password) -> repository.findByUsernameAndPassword(username, password)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Getter @Setter | |
| public class UserDTO implements UserIdentity { | |
| private Long id; | |
| private String username; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface UserRepository { | |
| Optional<UserDTO> findByUsername(String username); | |
| Optional<UserDTO> findByUsernameAndPassword(String username, String password); | |
| Long create(UserDTO dto); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment