Skip to content

Commit

Permalink
Merge pull request #40 from wwan13/feature/refactor
Browse files Browse the repository at this point in the history
Feature/refactor
  • Loading branch information
wwan13 authored Oct 24, 2024
2 parents f8d4800 + 9c34f91 commit 7c14886
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 109 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.4'
id 'maven-publish'
}

group = 'io.wwan13'
version = '0.0.9'
version = '1.0.0'

java {
sourceCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.wwan13.wintersecurity.auth;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

public abstract class AbstractAuthProcessor implements AuthProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.wwan13.wintersecurity.auth;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

public interface AuthProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package io.wwan13.wintersecurity.auth;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -37,6 +38,6 @@ public void saveAll(Map<String, Object> values) {
}

public void toRequestAttribute(HttpServletRequest request) {
storage.forEach(request::setAttribute);
storage.keySet().forEach(it -> request.setAttribute(it, storage.get(it)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package io.wwan13.wintersecurity.auth;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import java.util.Optional;

public interface TokenExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package io.wwan13.wintersecurity.auth.processor;

import io.wwan13.wintersecurity.auth.AbstractAuthProcessor;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class AbstractInterceptorAuthProcessor
extends AbstractAuthProcessor implements HandlerInterceptor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import io.wwan13.wintersecurity.exception.unauthirized.InvalidJwtTokenException;
import io.wwan13.wintersecurity.jwt.TokenClaims;
import io.wwan13.wintersecurity.jwt.TokenDecoder;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpMethod;

import javax.servlet.http.HttpServletRequest;

public class InterceptorAuthProcessor extends AbstractInterceptorAuthProcessor {

private final TokenExtractor tokenExtractor;
Expand Down Expand Up @@ -62,14 +61,14 @@ private void actionIfTokenPresent(
TokenClaims claims = tokenDecoder.decode(token);

accessManager.manageWithAuthentication(
HttpMethod.resolve(request.getMethod()),
HttpMethod.valueOf(request.getMethod()),
request.getRequestURI(),
claims.getRoles()
);

storage.save(Constants.ATTRIBUTE_CLAIMS_KEY, claims);
} catch (InvalidJwtTokenException | ExpiredJwtTokenException e) {
HttpMethod method = HttpMethod.resolve(request.getMethod());
HttpMethod method = HttpMethod.valueOf(request.getMethod());
String uri = request.getRequestURI();

if (!accessManager.isUnsecuredRequest(method, uri)) {
Expand All @@ -80,7 +79,7 @@ private void actionIfTokenPresent(

private void actionIfTokenAbsent(HttpServletRequest request) {
accessManager.manageWithoutAuthentication(
HttpMethod.resolve(request.getMethod()),
HttpMethod.valueOf(request.getMethod()),
request.getRequestURI()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.wwan13.wintersecurity.auth.provider;

import io.wwan13.wintersecurity.auth.TokenExtractor;
import jakarta.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

public class BearerTokenExtractor implements TokenExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import io.wwan13.wintersecurity.jwt.TokenClaims;
import io.wwan13.wintersecurity.resolve.util.AttributeExtractor;
import io.wwan13.wintersecurity.resolve.util.ResolveTypeConverter;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

public class RolesResolver implements HandlerMethodArgumentResolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import io.wwan13.wintersecurity.jwt.TokenClaims;
import io.wwan13.wintersecurity.resolve.util.AttributeExtractor;
import io.wwan13.wintersecurity.resolve.util.ResolveTypeConverter;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletRequest;

public class SubjectResolver implements HandlerMethodArgumentResolver {

private final TargetAnnotations targetAnnotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import io.wwan13.wintersecurity.constant.Constants;
import io.wwan13.wintersecurity.jwt.TokenClaims;
import jakarta.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

public class AttributeExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

import io.wwan13.wintersecurity.UnitTest;
import io.wwan13.wintersecurity.auth.stub.StubHttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.Test;

import javax.servlet.http.HttpServletRequest;

import static org.assertj.core.api.Assertions.assertThat;

class AbstractAuthProcessorTest extends UnitTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import io.wwan13.wintersecurity.UnitTest;
import io.wwan13.wintersecurity.auth.stub.StubHttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.Test;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void should_JudgeRequestIsAccessible(

// when
boolean result = authPatterns
.isAccessibleRequest(HttpMethod.resolve(requestMethod), requestUri, Set.of(requestRole));
.isAccessibleRequest(HttpMethod.valueOf(requestMethod), requestUri, Set.of(requestRole));

// then
assertThat(result).isEqualTo(expected);
Expand Down Expand Up @@ -109,7 +109,7 @@ void should_AcceptUnregisteredRequest_when_AnyRequestPermitAll(

// when
boolean result = authPatterns
.isAccessibleRequest(HttpMethod.resolve(requestMethod), requestUri, Set.of(requestRole));
.isAccessibleRequest(HttpMethod.valueOf(requestMethod), requestUri, Set.of(requestRole));

// then
assertThat(result).isEqualTo(expected);
Expand Down Expand Up @@ -143,7 +143,7 @@ void should_BlockUnregisteredRequest_when_AnyRequestAuthenticated(

// when
boolean result = authPatterns
.isAccessibleRequest(HttpMethod.resolve(requestMethod), requestUri, Set.of(requestRole));
.isAccessibleRequest(HttpMethod.valueOf(requestMethod), requestUri, Set.of(requestRole));

// then
assertThat(result).isEqualTo(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void should_JudgeRequestIsRegistered_when_MethodAndUriEntered(
Requests requests = new Requests(methods, uriPattern);

// when
boolean result = requests.isRegistered(HttpMethod.resolve(method), uri);
boolean result = requests.isRegistered(HttpMethod.valueOf(method), uri);

// then
assertThat(result).isEqualTo(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import io.wwan13.wintersecurity.auth.RequestStorage;
import io.wwan13.wintersecurity.auth.stub.StubHttpServletRequest;
import io.wwan13.wintersecurity.auth.stub.StubHttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.jupiter.api.Test;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static org.assertj.core.api.Assertions.assertThat;

class AbstractInterceptorAuthProcessorTest extends UnitTest {

static class StubAbstractInterceptorAuthProcessor extends AbstractInterceptorAuthProcessor {
static class StubAbstractInterceptorAuthProcessor extends AbstractInterceptorAuthProcessor {
@Override
protected void processInternal(HttpServletRequest request, RequestStorage storage) {
final String key = "key";
Expand Down
Loading

0 comments on commit 7c14886

Please sign in to comment.