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 | |
| class AuthTokenHandler { | |
| @Autowired | |
| lateinit var authTokenDao: AuthTokenDao | |
| @Transactional(readOnly = true) | |
| fun getUserFromToken(token : String?) : User { | |
| if (token == null) | |
| throw AuthenticationException() |
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
| class AuthTokenWebResolver : HandlerMethodArgumentResolver { | |
| @Autowired | |
| lateinit var authTokenHandler: AuthTokenHandler | |
| // to register Auth annotation | |
| override fun supportsParameter(methodParameter: MethodParameter): Boolean { | |
| return methodParameter.getParameterAnnotation(Auth::class.java) != null | |
| } |
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
| @Configuration | |
| class CustomConfig : WebMvcConfigurationSupport() { | |
| @Bean | |
| fun authWebArgumentResolverFactory() : HandlerMethodArgumentResolver { | |
| return AuthWebResolver() | |
| } | |
| // Addding the AuthWebResolver to the default argument resolvers | |
| override fun addArgumentResolvers(argumentResolvers: MutableList<HandlerMethodArgumentResolver>) { |
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
| @GetMapping("data/{id}") | |
| fun getData( | |
| @Auth user : User, | |
| @PathVariable(value = "id") id: Int | |
| ) : ResponseEntity<Void> { | |
| // NOTE: user can be used inside the method body | |
| // API logic | |
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
| @GetMapping("data/{id}") | |
| fun getData( | |
| @PathVariable(value = "id") id: Int | |
| ) : ResponseEntity<Void> { | |
| // API logic | |
| return ResponseEntity(HttpStatus.OK) | |
| } |
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
| @ControllerAdvice | |
| class CustomExceptionsHandler { | |
| @ExceptionHandler(AuthenticationException::class) | |
| fun authenticationExceptionHandler(e: Exception): ResponseEntity<String> { | |
| return ResponseEntity("authToken missing or not valid!", HttpStatus.UNAUTHORIZED) | |
| } | |
| } |
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
| import axios from 'axios'; | |
| // sample configurations | |
| const axiosInstance = axios.create({ | |
| withCredentials: true, | |
| baseURL: 'https://medium.org' | |
| }); | |
| export default axiosInstance; |
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
| import { Author as AuthorAPI } from './Author' | |
| import { Book as BookAPI } from './Book' | |
| export { | |
| AuthorAPI, | |
| BookAPI | |
| } |