Skip to content

Commit

Permalink
first version - allow basic log and http jobs through REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
xhanin committed Feb 18, 2014
1 parent 5e1c284 commit 394fbff
Show file tree
Hide file tree
Showing 18 changed files with 870 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
logs
.idea
*.iml
target

16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>quartz-ui</groupId>
<artifactId>quartz-ui-parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>ui</module>
<module>srv</module>
</modules>
</project>
12 changes: 12 additions & 0 deletions srv/data/credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"//": "lines with // keys are just comments (we don't have real comments in json)",
"//": "this file stores password passed through md5+bcrypt hash",
"//": "you can use `restx hash md5+bcrypt {password}` shell command to get hashed passwords to put here",

"//": "to help startup with restx, there are comments with clear text passwords,",
"//": "which should obviously not be stored here.",
"user1": "$2a$10$iZluFUJShbjb1ue68bLrDuGCeJL9EMLHelVIf8u0SUbCseDOvKnoe",
"//": "user 1 password is 'user1-pwd'",
"user2": "$2a$10$oym3SYMFXf/9gGfDKKHO4eM1vWNqAZMsRZCL.BORCaP4yp5cdiCXu",
"//": "user 2 password is 'user2-pwd'"
}
4 changes: 4 additions & 0 deletions srv/data/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"name":"user1", "roles": []},
{"name":"user2", "roles": []}
]
36 changes: 36 additions & 0 deletions srv/md.restx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"module": "quartz-ui:quartz-ui:0.1-SNAPSHOT",
"packaging": "war",

"properties": {
"java.version": "1.7",
"restx.version": "0.31.1",
"project.war.resources.directory": "../ui/dist"
},
"fragments": {
"maven": [
"classpath:///restx/build/fragments/maven/custom-war-resources.xml"
]
},
"dependencies": {
"compile": [
"io.restx:restx-core:${restx.version}",
"io.restx:restx-security-basic:${restx.version}",
"io.restx:restx-core-annotation-processor:${restx.version}",
"io.restx:restx-factory:${restx.version}",
"io.restx:restx-factory-admin:${restx.version}",
"io.restx:restx-monitor-admin:${restx.version}",
"io.restx:restx-server-jetty:${restx.version}",
"io.restx:restx-apidocs:${restx.version}",
"io.restx:restx-specs-admin:${restx.version}",
"io.restx:restx-admin:${restx.version}",
"org.quartz-scheduler:quartz:2.2.1",
"com.github.kevinsawicki:http-request:5.5",
"ch.qos.logback:logback-classic:1.0.13"
],
"test": [
"io.restx:restx-specs-tests:${restx.version}",
"junit:junit:4.11"
]
}
}
34 changes: 34 additions & 0 deletions srv/module.ivy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="quartz-ui" module="quartz-ui" revision="0.1" status="integration">
<ea:build organisation="org.apache.easyant.buildtypes" module="build-webapp-java" revision="0.9"
compile.java.source.version="1.7"
compile.java.target.version="1.7"
project.war.resources.directory="../ui/dist"
/>
</info>
<configurations>
<conf name="default"/>
<conf name="runtime"/>
<conf name="test"/>
</configurations>
<publications>
<artifact type="war"/>
</publications>
<dependencies>
<dependency org="io.restx" name="restx-core" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-security-basic" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-core-annotation-processor" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-factory" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-factory-admin" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-monitor-admin" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-server-jetty" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-apidocs" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-specs-admin" rev="0.31.1" conf="default" />
<dependency org="io.restx" name="restx-admin" rev="0.31.1" conf="default" />
<dependency org="org.quartz-scheduler" name="quartz" rev="2.2.1" conf="default" />
<dependency org="com.github.kevinsawicki" name="http-request" rev="5.5" conf="default" />
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="default" />
<dependency org="io.restx" name="restx-specs-tests" rev="0.31.1" conf="test->default" />
<dependency org="junit" name="junit" rev="4.11" conf="test->default" />
</dependencies>
</ivy-module>
115 changes: 115 additions & 0 deletions srv/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>quartz-ui</groupId>
<artifactId>quartz-ui</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>quartz-ui</name>

<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<restx.version>0.31.1</restx.version>
<project.war.resources.directory>../ui/dist</project.war.resources.directory>
</properties>

<dependencies>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-core</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-security-basic</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-core-annotation-processor</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-factory</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-factory-admin</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-monitor-admin</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-server-jetty</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-apidocs</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-specs-admin</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-admin</artifactId>
<version>${restx.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
<version>5.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-specs-tests</artifactId>
<version>${restx.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>${project.war.resources.directory}</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
70 changes: 70 additions & 0 deletions srv/src/main/java/qzui/AppModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package qzui;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableSet;
import restx.security.*;
import restx.factory.Module;
import restx.factory.Provides;
import javax.inject.Named;

import java.nio.file.Paths;

@Module
public class AppModule {
@Provides
public SignatureKey signatureKey() {
return new SignatureKey("5621d6b0-c047-4420-a59d-412a252de015 quartz-ui 5399913187595030480 quartz-ui".getBytes(Charsets.UTF_8));
}

@Provides
@Named("restx.admin.password")
public String restxAdminPassword() {
return "juma";
}

@Provides
@Named("app.name")
public String appName(){
return "quartz-ui";
}

@Provides
public CredentialsStrategy credentialsStrategy() {
return new BCryptCredentialsStrategy();
}

@Provides
public BasicPrincipalAuthenticator basicPrincipalAuthenticator(
SecuritySettings securitySettings, CredentialsStrategy credentialsStrategy,
@Named("restx.admin.passwordHash") String defaultAdminPasswordHash, ObjectMapper mapper) {
return new StdBasicPrincipalAuthenticator(new StdUserService<>(
// use file based users repository.
// Developer's note: prefer another storage mechanism for your users if you need real user management
// and better perf
new FileBasedUserRepository<>(
StdUser.class, // this is the class for the User objects, that you can get in your app code
// with RestxSession.current().getPrincipal().get()
// it can be a custom user class, it just need to be json deserializable
mapper,

// this is the default restx admin, useful to access the restx admin console.
// if one user with restx-admin role is defined in the repository, this default user won't be
// available anymore
new StdUser("admin", ImmutableSet.<String>of("*")),

// the path where users are stored
Paths.get("data/users.json"),

// the path where credentials are stored. isolating both is a good practice in terms of security
// it is strongly recommended to follow this approach even if you use your own repository
Paths.get("data/credentials.json"),

// tells that we want to reload the files dynamically if they are touched.
// this has a performance impact, if you know your users / credentials never change without a
// restart you can disable this to get better perfs
true),
credentialsStrategy, defaultAdminPasswordHash),
securitySettings);
}
}
32 changes: 32 additions & 0 deletions srv/src/main/java/qzui/AppServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package qzui;

import com.google.common.base.Optional;
import restx.server.WebServer;
import restx.server.JettyWebServer;

/**
* This class can be used to run the app.
*
* Alternatively, you can deploy the app as a war in a regular container like tomcat or jetty.
*
* Reading the port from system env PORT makes it compatible with heroku.
*/
public class AppServer {
public static final String WEB_INF_LOCATION = "src/main/webapp/WEB-INF/web.xml";
public static final String WEB_APP_LOCATION = "src/main/webapp";

public static void main(String[] args) throws Exception {
int port = Integer.valueOf(Optional.fromNullable(System.getenv("PORT")).or("8080"));
WebServer server = new JettyWebServer(WEB_INF_LOCATION, WEB_APP_LOCATION, port, "0.0.0.0");

/*
* load mode from system property if defined, or default to dev
* be careful with that setting, if you use this class to launch your server in production, make sure to launch
* it with -Drestx.mode=prod or change the default here
*/
System.setProperty("restx.mode", System.getProperty("restx.mode", "dev"));
System.setProperty("restx.app.package", "qzui");

server.startAndAwait();
}
}
20 changes: 20 additions & 0 deletions srv/src/main/java/qzui/DefaultJobDescriptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package qzui;

import org.quartz.JobDetail;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* Date: 18/2/14
* Time: 21:35
*/
public class DefaultJobDescriptor extends JobDescriptor {
private String jobClassName;


@Override
public JobDetail buildJobDetail() {
return null;
}
}
Loading

0 comments on commit 394fbff

Please sign in to comment.