Created
March 28, 2020 07:06
-
-
Save nuboat/78a7326f4d8342bb6076d7fa28e9575c to your computer and use it in GitHub Desktop.
This file contains 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
package link.colon.authorize; | |
import lombok.Data; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
import java.io.Serializable; | |
@Data | |
@Entity | |
@Table(name = "accesses") | |
public class Access implements Serializable { | |
private static final long serialVersionUID = 1L; | |
@Id | |
@Column(name="token") | |
public String token; | |
@Column(name="access_name") | |
public String accessName; | |
} |
This file contains 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
package link.colon.authorize; | |
import org.springframework.data.repository.CrudRepository; | |
import org.springframework.stereotype.Repository; | |
import java.util.Optional; | |
@Repository | |
public interface AccessCRUD extends CrudRepository<Access, Long> { | |
Optional<Access> findByToken(final String token); | |
} |
This file contains 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
package link.colon.controller; | |
import link.colon.authorize.AccessCRUD; | |
import lombok.RequiredArgsConstructor; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RestController; | |
import java.util.Optional; | |
@Slf4j | |
@RestController | |
@RequiredArgsConstructor | |
class AM { | |
private final AccessCRUD crud; | |
@GetMapping(value = "/verify/{token}") | |
private String verify(@PathVariable("token") final String token) { | |
log.info("Authoen by {}", token); | |
return crud.findByToken(token).map(a -> a.accessName) | |
.orElse(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment