Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8c792c6
begin work on security features
Spaceman1701 Oct 5, 2017
f915cc4
design inital auth interface
Spaceman1701 Oct 5, 2017
af2e375
add unit test for schema creation
Spaceman1701 Oct 5, 2017
00bd3a9
move supporting unit test classes into one file
Spaceman1701 Oct 5, 2017
6a729c7
refactor gradle build. still not quite working right.
Spaceman1701 Oct 5, 2017
fea929a
fix gitignore
Spaceman1701 Oct 5, 2017
c639b7d
Fix gradle build in theory.
Spaceman1701 Oct 5, 2017
8a7eb85
add config and tests that somehow got lost in refactor
Spaceman1701 Oct 5, 2017
378616c
test commit to ensure travis is running unit tests correctly
Spaceman1701 Oct 5, 2017
b1064f6
update readme build link and fix test (travis seems to work)
Spaceman1701 Oct 5, 2017
bfa2f58
tone down email notifications
Spaceman1701 Oct 5, 2017
7a2aa05
add secure slack notification for travis
Spaceman1701 Oct 5, 2017
0cbd4f0
fix travis slack notification settings
Spaceman1701 Oct 5, 2017
4fab345
break the build
Spaceman1701 Oct 6, 2017
e0fb4a8
Fix build. Clean up imports
Spaceman1701 Oct 6, 2017
0f45526
fix unit tests
Spaceman1701 Oct 6, 2017
e1fc6fa
play around with mongo jpa layer
Spaceman1701 Oct 7, 2017
581c8ce
add very basic integration tests
Spaceman1701 Oct 8, 2017
e7742eb
security work
Spaceman1701 Oct 10, 2017
ca54964
add GraphQLUtils for accessing request headers
Spaceman1701 Oct 16, 2017
37d185b
remove unused permission classes
Spaceman1701 Oct 16, 2017
e677913
work on Shiro Realm for MongoDB access
Spaceman1701 Oct 16, 2017
a6c6a1c
maybe fix autowired for the shiro realm
Spaceman1701 Oct 16, 2017
c327a2f
more auth work
Spaceman1701 Oct 16, 2017
1dca682
work on auth
Spaceman1701 Oct 17, 2017
2c4c444
add a lot of hacky stuff to test shiro config
Spaceman1701 Oct 17, 2017
097889a
break everything
Spaceman1701 Oct 18, 2017
d7fc8b1
break shiro config and fix bean config
Spaceman1701 Oct 18, 2017
9663243
fix shiro session management. Currently caching is broken
Spaceman1701 Oct 19, 2017
7d8c108
code cleanup
Spaceman1701 Oct 19, 2017
f9eefdf
fix auth header name to comply to standard
Spaceman1701 Oct 19, 2017
2bea31f
enable the most basic of caching for the auth db
Spaceman1701 Oct 20, 2017
ae416b5
fix AuthenticatedUser not being suitable for caching
Spaceman1701 Oct 20, 2017
6a3cd74
more code cleanup + disable Shiro-level caching
Spaceman1701 Oct 20, 2017
a45e2c5
remove unused shiro.ini
Spaceman1701 Oct 20, 2017
c6d3b89
work on adding rsa to jwt signing
Spaceman1701 Oct 21, 2017
1aa8c4f
remove test keys from repo - STILL DON'T USE THEM
Spaceman1701 Oct 21, 2017
71a5054
rename packages
Spaceman1701 Oct 21, 2017
684ea0c
clean up code and test signed tokens
Spaceman1701 Oct 21, 2017
2544b50
fix unit tests
Spaceman1701 Oct 21, 2017
d0a8af7
fix build
Spaceman1701 Oct 22, 2017
11f02ec
add delete method to Auth repo
Spaceman1701 Oct 22, 2017
998cbd1
add insert method to auth repo
Spaceman1701 Oct 22, 2017
4ae7cf6
add mongo config methods
Spaceman1701 Oct 22, 2017
47a3351
heh... fix build
Spaceman1701 Oct 22, 2017
93b2be2
move MongoDB config into config options
Spaceman1701 Oct 22, 2017
6f080aa
add standin secret for testing
Spaceman1701 Oct 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Created by .ignore support plugin (hsz.mobi)
### Gradle template
.gradle
/build/

build
# Ignore Gradle GUI config
gradle-app.setting

Expand Down Expand Up @@ -37,6 +36,6 @@ gradle-app.setting

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/out
out/
.idea
*.iml
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
language: java

jdk:
- oraclejdk8
- oraclejdk8
before_install:
- chmod +x gradlew
- chmod +x gradle/wrapper/gradle-wrapper.jar
- chmod +x gradlew
- chmod +x gradle/wrapper/gradle-wrapper.jar
notifications:
email:
on_success: never
on_failure: always
slack:
secure: zbrlGnn3XROnnOnu3QIKb+LHTkGbJrqW3xyUNE/egHZ2F6214IrW3nMQ1UCWcf3BgrcA/t+ATPUGT0DJBUbzRypQrJadkG82KavGllAhd6KUBSKGFEGq4+6ug8g+1OhOs/EyxbMH98dftPO9IABs0bByHARU8EQEvaRTkX+MvaF0I6Ni/3nFoYn2xf6aSEZ8/S20co59BN+1GjLTippJERTREWsj6A5LDlsyH5Dw9REbhp2UXRbR2zlw2hbQu6HxTLSf8FAarEh0NsXI5EeCkO2TJsL1R0CejFznPRIk2WLr4TebgWY6Hdk3EUlwuM/4JqEqgml0yLg8/BpG3oB/iXJaYZOhRW7ZALJ9KFCD2CKI4Kdi1CeryGtabl6FfQene9vPDxGkmolTOFtglW5MoHIpLVE/oni0GTQEaqHhdYqCBJ/gHLx+Mrc433cDgIEd9RNqCa6vNzmfS7h7+yHKH4OxzK+PCDezsTvrwca1VCMhKBtdT9YI+hOys5J76Gf42zW8EpY9BsC05H3g+Pp0pbVIe6rmu5RShgJUne16LlkrsLKr03mZes0XsYOYA7VgnMMLFMwd/urbtcKOe1YClfKiAuBcFrpdEbSS8boqkxLbG0BmfcyXyf35eFhKFghom0dZNLa+BgMQ0os7vk3IE25f46/rzmpZRmAUlsW7aco=
on_success: always
on_failure: always
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![build status image](https://travis-ci.org/Team0x2B/core-service-lib.svg?branch=master)
[![build status image](https://travis-ci.org/Team0x2B/org.x2b.study.core-service-lib.svg?branch=master)](https://travis-ci.org/Team0x2B/core-service-lib)

Right now this is just me messing around with GraphQL and Spring until I find a pattern I like. Eventually this will be
the core service library used to start writing a new backend service.
the org.x2b.study.core service library used to start writing a new backend service.


# GraphQL Conventions
Expand Down
46 changes: 22 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
group 'org.x2b.study.core'
group 'org.x2b.study'
version '0.1-SNAPSHOT'


tasks {
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
}
}

buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'http://repo.spring.io/plugins-release' }

}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE")
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6"
}
}

tasks {
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
}
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
allprojects {
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

repositories {
mavenCentral()
subprojects {
repositories {
mavenCentral()
maven {url 'http://repo.spring.io/libs-release'}
}
}
bootRepackage.enabled = false

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'

compile 'org.springframework.boot:spring-boot-starter-web'

compile 'com.graphql-java:graphql-spring-boot-starter:3.9.2'

compile 'com.graphql-java:graphiql-spring-boot-starter:3.9.2'

compile 'com.graphql-java:graphql-java-tools:4.1.2'
compile project(":core-service-lib")
compile project(":core-service-lib-integration")
}
18 changes: 18 additions & 0 deletions core-service-lib-integration/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
group 'org.x2b.study.org.x2b.study.core'
version '0.1-SNAPSHOT'

apply plugin: 'java'

apply plugin: 'org.springframework.boot'

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'

testCompile("org.springframework.boot:spring-boot-starter-test")

compile project(':core-service-lib')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.x2b.studi.core;

import graphql.schema.idl.RuntimeWiring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
import org.x2b.studi.core.graphql.fetchers.mutation.createuser.CreateUserFetcher;
import org.x2b.studi.core.graphql.fetchers.mutation.getsecure.SecureTestFetcher;
import org.x2b.studi.core.graphql.fetchers.query.getuser.GetUserFetcher;
import org.x2b.studi.core.security.data.mongodb.AuthorizationRepository;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Base64;

@SpringBootApplication
@ComponentScan(basePackages = "org.x2b.study.core.*")
@EnableCaching
public class IntegrationTestService extends GraphQLServiceConfigure {


public static void main(String[] args) throws IOException {
ConfigurableApplicationContext ctx = SpringApplication.run(IntegrationTestService.class, args);
}

@Autowired
private AuthorizationRepository authRepo;

@Override
protected RuntimeWiring createRuntimeWiring() {
return RuntimeWiring.newRuntimeWiring()
.type("MutationRoot", w -> w
.dataFetcher("createUser", new CreateUserFetcher(authRepo))
)
.type("QueryRoot", w -> w
.dataFetcher("getUserPermissions", new GetUserFetcher(authRepo))
.dataFetcher("secureGet", new SecureTestFetcher())
)
.build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.x2b.studi.core.graphql.fetchers.mutation.createuser;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.x2b.studi.core.security.data.mongodb.AuthenticatedUser;
import org.x2b.studi.core.security.data.mongodb.AuthorizationRepository;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;

public class CreateUserFetcher implements DataFetcher<String> {


private AuthorizationRepository authRepo;

public CreateUserFetcher(AuthorizationRepository authRepo) {
this.authRepo = authRepo;
}

@Override
public String get(DataFetchingEnvironment environment) {
HashMap<String, Object> input = environment.getArgument("input");
List<String> permissions = (List<String>) input.get("permissions");
AuthenticatedUser user = new AuthenticatedUser(UUID.randomUUID(), new HashSet<>(permissions));
authRepo.save(user);
return user.getUUID().toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.x2b.studi.core.graphql.fetchers.mutation.getsecure;

import graphql.schema.DataFetchingEnvironment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;
import org.x2b.studi.core.graphql.fetchers.SecureRootFetcher;

public class SecureTestFetcher extends SecureRootFetcher {
private static final Log log = LogFactory.getLog(SecureTestFetcher.class);

@Override
public void handleAuthenticationFailure(AuthenticationException e, DataFetchingEnvironment environment) {
log.debug("auth failure!");
}

@Override
public Object secureGet(DataFetchingEnvironment environment) {
Subject s = SecurityUtils.getSubject();

return s.isPermitted("foo:bar:read");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.x2b.studi.core.graphql.fetchers.query.getuser;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.x2b.studi.core.security.data.mongodb.AuthenticatedUser;
import org.x2b.studi.core.security.data.mongodb.AuthorizationRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class GetUserFetcher implements DataFetcher<List<String>> {

private AuthorizationRepository authRepo;

public GetUserFetcher(AuthorizationRepository authRepo) {
this.authRepo = authRepo;
}

@Override
public List<String> get(DataFetchingEnvironment environment) {
String idString = environment.getArgument("id");
UUID uuid = UUID.fromString(idString);
AuthenticatedUser user = authRepo.findOne(uuid);
return new ArrayList<>(user.getPermissions());
}
}
17 changes: 17 additions & 0 deletions core-service-lib-integration/src/main/resources/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type MutationRoot {
createUser(input: PermissionsInput!): ID!
}

input PermissionsInput {
permissions: [String!]!
}

type QueryRoot {
getUserPermissions(id: ID!): [String]!
secureGet: String!
}

schema {
mutation: MutationRoot
query: QueryRoot
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.x2b.studi.core;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = IntegrationTestService.class)
@TestPropertySource(properties = {
"studi.security.auth.secret=abcdefg123"
})
public class TestIntegrationService {

@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;




@Before
public void setup() {
DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac);
this.mockMvc = builder.build();
}


@Test
public void contextLoads() throws Exception {

}

public ResultMatcher okMatcher() {
return MockMvcResultMatchers.status().isOk();
}

@Test
public void testGraphQlResponds() throws Exception {
ResultMatcher ok = okMatcher();
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/graphiql");
mockMvc.perform(builder)
.andExpect(ok);
}


}
16 changes: 16 additions & 0 deletions core-service-lib-integration/src/test/resources/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type MutationRoot {
createUser(input: PermissionsInput!): ID!
}

input PermissionsInput {
permissions: [String!]!
}

type QueryRoot {
getUserPermissions(id: ID!): [String]!
}

schema {
mutation: MutationRoot
query: QueryRoot
}
26 changes: 26 additions & 0 deletions core-service-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
group 'org.x2b.study.org.x2b.study.core'
version '0.1-SNAPSHOT'


apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

bootRepackage.enabled = false

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'

compile 'org.springframework.boot:spring-boot-starter-web:1.5.7.RELEASE'

compile 'com.graphql-java:graphql-spring-boot-starter:3.9.2'

compile 'com.graphql-java:graphiql-spring-boot-starter:3.9.2'

compile 'org.springframework.data:spring-data-mongodb:2.0.0.RELEASE'

compile 'org.apache.shiro:shiro-all:1.2.3'

compile 'com.auth0:java-jwt:3.2.0'
}
6 changes: 6 additions & 0 deletions core-service-lib/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Oct 05 15:56:37 MDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-bin.zip
Loading