yakworks.security.spring.token.TokenController.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boot-security Show documentation
Show all versions of boot-security Show documentation
gorm-tools security and domain models
/*
* Copyright 2020-2021 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package yakworks.security.spring.token
import javax.inject.Inject
import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.http.CacheControl
import org.springframework.http.ResponseEntity
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.security.oauth2.core.AbstractOAuth2Token
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import jakarta.annotation.Nullable
import yakworks.api.HttpStatus
import yakworks.api.problem.Problem
import yakworks.api.problem.UnexpectedProblem
import yakworks.security.spring.token.generator.JwtTokenExchanger
import yakworks.security.spring.token.generator.JwtTokenGenerator
import yakworks.security.spring.token.generator.StoreTokenGenerator
import yakworks.security.user.CurrentUser
/**
* A controller for the token resource.
*/
@RestController
@CompileStatic
@Slf4j
class TokenController {
@Inject JwtTokenGenerator jwtTokenGenerator
@Inject JwtTokenExchanger jwtTokenExchanger
//used for tokenLegacy right now
@Inject @Nullable
StoreTokenGenerator storeTokenGenerator
@Inject CurrentUser currentUser
// @Value('${grails.serverURL:""}')
// String serverURL
// for dev and testing to make it easier to dump token into variable.
// ex: `$ TOKEN=`http POST admin:123@localhost:8080/token.txt -b`
@PostMapping("/oauth/token.txt")
String tokenTxt() {
return jwtTokenGenerator.generate().tokenValue
}
/**
* Default generator for token. Follows the oauth standards.
*/
@PostMapping("/oauth/token")
ResponseEntity