Skip to content
Open
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
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,java}]
charset = utf-8
indent_style = space
curly_bracket_next_line = false
indent_brace_style = K&R

[*.java]
indent_size = 4
continuation_indent_size = 8

[*.js]
indent_size = 2
continuation_indent_size = 2
8 changes: 4 additions & 4 deletions app/config/AuthorizationServerAuthAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public AuthorizationServerAuthAction(JwtUtils jwtUtils) {
public CompletionStage<Result> call(Http.Context ctx) {
Http.Cookie ltat = ctx.request().cookie("ltat");
boolean valid = configuration.optional();
if(ltat != null) {
if (ltat != null) {
User user = jwtUtils.validateCookie(ltat.value());
if(user != null) {
if (user != null) {
if (user.isDisabled()) {
flash("error", "Your account was disabled.");
Http.Cookie ltatRemove = Http.Cookie.builder("ltat", "")
.withPath("/").withHttpOnly(true).withMaxAge(Duration.ZERO).build();
return CompletableFuture.completedFuture(redirect(routes.LoginController.get(null)).withCookies(ltatRemove));
}
if(!configuration.requireAdmin() || user.isAdmin()){
if (!configuration.requireAdmin() || user.isAdmin()) {
ctx = ctx.withRequest(ctx.request().addAttr(AuthorizationServerSecure.USER, user));
valid = true;
} else {
Expand All @@ -45,7 +45,7 @@ public CompletionStage<Result> call(Http.Context ctx) {
}
}
}
if(!valid) {
if (!valid) {
return CompletableFuture.completedFuture(redirect(routes.LoginController.get(ctx.request().uri())));
} else { // pass on
return delegate.call(ctx);
Expand Down
9 changes: 6 additions & 3 deletions app/config/AuthorizationServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.typesafe.config.Config;
import dtos.*;
import dtos.MeDto;
import dtos.OAuthContext;
import dtos.OAuthProvider;
import dtos.Token;
import play.Logger;
import scala.Tuple2;

Expand All @@ -22,7 +25,7 @@ public class AuthorizationServerManager {
private List<Tuple2<String, String>> providerList;

@Inject
public AuthorizationServerManager(Config config){
public AuthorizationServerManager(Config config) {
this.providerMap = new LinkedHashMap<>();
try {
List<? extends Config> providers = config.getConfigList("oauth.providers");
Expand Down Expand Up @@ -77,7 +80,7 @@ public OAuthProvider getProvider(String provider) {
return providerMap.get(provider);
}

public List<Tuple2<String, String>> getProviders(){
public List<Tuple2<String, String>> getProviders() {
return providerList;
}
}
2 changes: 2 additions & 0 deletions app/config/AuthorizationServerSecure.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface AuthorizationServerSecure {
TypedKey<User> USER = TypedKey.create("user_a");

boolean requireAdmin() default false;

boolean optional() default false;
}
2 changes: 1 addition & 1 deletion app/config/CurrentUserIdentifierOverUserInfoUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CurrentUserIdentifierOverUserInfoUrl(Function<WSResponse, MeDto> response
public CompletionStage<MeDto> apply(OAuthContext context) {
return context.getWs()
.url(context.getProvider().getUserInfoUrl())
.addHeader("Authorization", "Bearer "+ context.getToken().getAccessToken())
.addHeader("Authorization", "Bearer " + context.getToken().getAccessToken())
.get()
.thenApplyAsync(responseToUserFunction);
}
Expand Down
4 changes: 2 additions & 2 deletions app/config/FacebookTokenRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public CompletionStage<Token> apply(OAuthContext context) {
.addQueryParameter("grant_type", "authorization_code")
.get()
.handleAsync((res, e) -> {
if(e != null) {
if (e != null) {
play.Logger.error("retrieveToken: exception", e);
throw new CompletionException(e);
} else if(res.getStatus() != 200) {
} else if (res.getStatus() != 200) {
String message = String.format("retrieveToken: status=%s, body=%s", res.getStatus(), res.getBody());
play.Logger.error(message);
throw new CompletionException(new IllegalStateException(message));
Expand Down
4 changes: 2 additions & 2 deletions app/config/GoogleTokenRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public CompletionStage<Token> apply(OAuthContext context) {
URLEncoder.encode(context.getProvider().getClientId(), "utf-8"),
URLEncoder.encode(context.getProvider().getClientSecret(), "utf-8")))
.handleAsync((res, e) -> {
if(e != null) {
if (e != null) {
play.Logger.error("retrieveToken: exception", e);
throw new CompletionException(e);
} else if(res.getStatus() != 200) {
} else if (res.getStatus() != 200) {
String message = String.format("retrieveToken: status=%s, body=%s", res.getStatus(), res.getBody());
play.Logger.error(message);
throw new CompletionException(new IllegalStateException(message));
Expand Down
Loading