Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Token-based authentication with user context #209

Draft
wants to merge 16 commits into
base: bleeding-1.X.X
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def projectVersion = project.version

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
def isRelease = true

if (project.hasProperty("preRelease")) {
apply from: './pre-release.gradle'
Expand All @@ -21,6 +22,7 @@ if (project.hasProperty("preRelease")) {
projectVersion += "-rc." + i

} else if (!project.hasProperty('release')) {
isRelease = false
projectVersion += '-SNAPSHOT'
}

Expand Down Expand Up @@ -125,7 +127,10 @@ task processSourceReplacements(type: org.gradle.api.tasks.Sync) {
}

compileJava {
source = processSourceReplacements.outputs
if (isRelease) {
source = processSourceReplacements.outputs
}

options.compilerArgs << "-Xlint:deprecation"
}

Expand Down
20 changes: 0 additions & 20 deletions src/api/java/de/fearnixx/jeak/reflect/PathParam.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/api/java/de/fearnixx/jeak/reflect/RequestBody.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/api/java/de/fearnixx/jeak/reflect/RequestMapping.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/api/java/de/fearnixx/jeak/reflect/RequestParam.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/api/java/de/fearnixx/jeak/reflect/Transactional.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/api/java/de/fearnixx/jeak/reflect/http/Authenticated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.fearnixx.jeak.reflect.http;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Designates a method annotated with {@link RequestMapping} as requiring authentication.
* To facilitate basic authorization checks, a permission can be set as required for the endpoint.
*
* @since 1.2.0 (experimental)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Authenticated {

/**
* The permissions required to access the endpoint at all.
* The requesting party must have all the given permissions in order to access the endpoint (AND).
*/
String[] permissions() default {};
}
28 changes: 28 additions & 0 deletions src/api/java/de/fearnixx/jeak/reflect/http/RequestMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.fearnixx.jeak.reflect.http;

import de.fearnixx.jeak.service.http.RequestMethod;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Designates a method as being a receiver for HTTP-requests.
*
* @since 1.2.0 (experimental)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RequestMapping {

/**
* The HTTP method associated with this endpoint.
*/
RequestMethod method() default RequestMethod.GET;

/**
* URI appendix for this endpoint.
*/
String endpoint();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.fearnixx.jeak.reflect;
package de.fearnixx.jeak.reflect.http;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -8,15 +8,18 @@
/**
* Marks a class as a REST controller. One plugin can have multiple controllers, so the controller determines
* to which plugin it belongs by using the pluginId.
*
* endpoint(): REQUIRE if you use more than one controller. Specify the endpoint of the controller.
*
* pluginId(): Specify the id of the used plugin. This is independent of the pluginId specified in {@link de.fearnixx.jeak.reflect.JeakBotPlugin}.
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RestController {

/**
* Your plugin id, since controllers are grouped by plugin ID to avoid path collisions between plugins.
*/
String pluginId();
String endpoint();

/**
* An endpoint path prefix for all request mappings within this class.
*/
String path();
}
20 changes: 20 additions & 0 deletions src/api/java/de/fearnixx/jeak/reflect/http/params/PathParam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.fearnixx.jeak.reflect.http.params;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies an endpoint method parameter to be derived from the requests path pattern.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PathParam {

/**
* If the parameter name from the path pattern differs from the method parameter name, this should be the
* name used in the path pattern.
*/
String name() default "";
}
19 changes: 19 additions & 0 deletions src/api/java/de/fearnixx/jeak/reflect/http/params/QueryParam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.fearnixx.jeak.reflect.http.params;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Designates a methods parameter to be filled by a request parameter.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface QueryParam {

/**
* If the parameter name differs from the HTTP-contract, this should be the name used in the contract.
*/
String name() default "";
}
19 changes: 19 additions & 0 deletions src/api/java/de/fearnixx/jeak/reflect/http/params/RequestBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.fearnixx.jeak.reflect.http.params;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Designates an endpoint method parameter to be filled with the request body received.
* This is only applicable to {@link de.fearnixx.jeak.service.http.RequestMethod#POST}, {@link de.fearnixx.jeak.service.http.RequestMethod#PUT}
* and {@link de.fearnixx.jeak.service.http.RequestMethod#PATCH}
*
* @implNote Currently, only two method parameter types are supported! If the type is {@link String}, the serialized content will be used.
* If the type is of a custom class, Jackson will be used to attempt JSON deserialization of the request body.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface RequestBody {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.fearnixx.jeak.reflect.http.params;

import de.fearnixx.jeak.service.http.request.IRequestContext;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Denotes a parameter to be filled from the request context.
*
* @apiNote The parameter injection will work within the bounds of class assignability compatibility.
* @implNote Some usages of this cause side-effects, please see the implementation notes on {@link IRequestContext.Attributes}
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequestContext {

/**
* Denotes the attribute name to be used for the lookup.
* If empty, the parameter injection will attempt to insert the {@link IRequestContext} instance.
*
* @see IRequestContext.Attributes for more information on available attributes.
*/
String attribute() default "";

/**
* Whether or not this parameter has to be set.
* Unset, non-required values are passed as {@code null}.
*/
boolean required() default true;
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package de.fearnixx.jeak.service.controller;
package de.fearnixx.jeak.service.http;

import java.util.Map;
import java.util.Optional;

/**
* The controller manager allows plugins to register services to a specified REST method.
*
*/
public interface IRestControllerService {
public interface IControllerService {

/**
* Registers a new REST controller to the controller manager.
*
* @param cntrlrClass The class the controller provides.
* @param restController The controller to be registered.
* @param <T> The Type of the service.
* @param cntrlrClass The class the controller provides.
* @param instance The controller to be registered.
* @param <T> The Type of the service.
*/
<T> void registerController(Class<T> cntrlrClass, T restController);
<T> void registerController(Class<T> cntrlrClass, T instance);

/**
* Optionally get a controller of the specified class.
*
* @param cntrlrClass The desired controller class.
* @param <T> The desired controller type.
* @param <T> The desired controller type.
* @return An {@link Optional<T>} representing the result.
*/
<T> Optional<T> provide(Class<T> cntrlrClass);
Expand All @@ -33,16 +32,16 @@ public interface IRestControllerService {
* This method performs no checks!
*
* @param cntrlrClass The desired service class.
* @param <T> The desired controller type.
* @param <T> The desired controller type.
* @return Either the controller instance,
* or {@core null} and a {@link ClassCastException} is thrown.
* or {@code null} and a {@link ClassCastException} is thrown.
*/
<T> T provideUnchecked(Class<T> cntrlrClass);

/**
* Provide all the registered controllers.
*
* @return A {@link Map<Class<?>, Object>} representing the controller.
* @return A {@code Map<Class<?>, Object>} representing the controller.
*/
Map<Class<?>, Object> provideAll();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.fearnixx.jeak.service.controller;
package de.fearnixx.jeak.service.http;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.fearnixx.jeak.service.controller;
package de.fearnixx.jeak.service.http;

public enum RequestMethod {
POST,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.fearnixx.jeak.service.controller;
package de.fearnixx.jeak.service.http;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.fearnixx.jeak.service.controller.exceptions;
package de.fearnixx.jeak.service.http.exceptions;

public class RegisterControllerException extends RuntimeException{
public RegisterControllerException(String message) {
Expand Down
Loading