Skip to content

Instantly share code, notes, and snippets.

@ggonchar
ggonchar / swagger_oauth2_client_grant.yaml
Created September 30, 2016 09:01
Swagger 2.0 yaml spec for OAuth 2.0 implementation with client grant
swagger: '2.0'
info:
title: Authentication API
description: |
Implementation of [OAuth 2.0](https://tools.ietf.org/html/rfc6749 "Docs") with Client Credentials Grant type
version: "1.0.0"
host: localhost:3000
schemes:
- http
- https
FROM openjdk:8-jre-alpine
RUN apk update \
&& apk add bash tar curl wget sudo
RUN curl -sSL https://raw.githubusercontent.com/conjurinc/summon/master/install.sh | bash \
&& mkdir /usr/local/lib/summon \
&& curl -sSL https://github.com/conjurinc/summon-conjur/releases/download/v0.2.0/summon-conjur_v0.2.0_linux-amd64.tar.gz | tar xvz -C /usr/local/lib/summon
@ggonchar
ggonchar / package.scala
Last active November 25, 2016 22:11
Example of reusable JSON handling in Play Framework
/**
* Action handling JSON serialization
*/
object JsAction {
def apply[R](block: R => Result)(implicit reads: Reads[R]) = Action(parse.json) { request =>
request.body.validate[R](reads).fold(
valid = block,
invalid = e => {
BadRequest(s"Failed validation of JSON request ${request.uri} with errors: ${e.mkString}")
import javax.net.ssl._
import play.core.ApplicationProvider
import play.server.api._
class SSLEngineProviderWithClientAuth(appProvider: ApplicationProvider) extends SSLEngineProvider {
override def createSSLEngine(): SSLEngine = {
val sslEngine = SSLContext.getDefault.createSSLEngine
sslEngine.setNeedClientAuth(true)
sslEngine
}
import org.springframework.data.repository.CrudRepository;
public interface AddressRepository extends CrudRepository<Address, Long> {}
@Service
public class AddressService {
private final AddressRepository repository;
private final Scheduler scheduler;
public AddressRouter(AddressRepository repository, @Qualifier("jdbcScheduler") Scheduler scheduler) {
this.repository = repository;
this.scheduler = scheduler;
@Configuration
public class SchedulerConfiguration {
private final Integer connectionPoolSize;
public SchedulerConfiguration(@Value("${spring.datasource.maximum-pool-size}") Integer connectionPoolSize) {
this.connectionPoolSize = connectionPoolSize;
}
@Bean
public Scheduler jdbcScheduler() {
public Person addPerson(Person person) {
IpAddressDetails ipDetails = ipService.getDetails(person.getIpAddress());
person.setIpAddressDetails(ipDetails);
return repository.save(person);
}
private Mono<Person> addPerson(Mono<Person> mono) {
return mono
.flatMap(this::addIpAddressDetails)
.flatMap(repository::save);
}
public final class Person {
private final String id;
private final String firstname;
private final String lastname;
private final IpAddress ipAddress; // immutable inside
public Person(String id, String firstname, String lastname, IpAddress ipAddress) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;