diff --git a/build.gradle b/build.gradle index faad922..5105bcc 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessor.java b/src/main/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessor.java index 14ac775..0649af0 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessor.java @@ -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 { diff --git a/src/main/java/io/wwan13/wintersecurity/auth/AuthProcessor.java b/src/main/java/io/wwan13/wintersecurity/auth/AuthProcessor.java index b9dd1d6..93a5158 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/AuthProcessor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/AuthProcessor.java @@ -16,7 +16,7 @@ package io.wwan13.wintersecurity.auth; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; public interface AuthProcessor { diff --git a/src/main/java/io/wwan13/wintersecurity/auth/RequestStorage.java b/src/main/java/io/wwan13/wintersecurity/auth/RequestStorage.java index 36433ce..51ea150 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/RequestStorage.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/RequestStorage.java @@ -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; @@ -37,6 +38,6 @@ public void saveAll(Map values) { } public void toRequestAttribute(HttpServletRequest request) { - storage.forEach(request::setAttribute); + storage.keySet().forEach(it -> request.setAttribute(it, storage.get(it))); } } diff --git a/src/main/java/io/wwan13/wintersecurity/auth/TokenExtractor.java b/src/main/java/io/wwan13/wintersecurity/auth/TokenExtractor.java index 4d52437..0d5d293 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/TokenExtractor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/TokenExtractor.java @@ -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 { diff --git a/src/main/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessor.java b/src/main/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessor.java index 0fdd86d..072f6fc 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessor.java @@ -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 { diff --git a/src/main/java/io/wwan13/wintersecurity/auth/processor/InterceptorAuthProcessor.java b/src/main/java/io/wwan13/wintersecurity/auth/processor/InterceptorAuthProcessor.java index 1870f2f..aa2311c 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/processor/InterceptorAuthProcessor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/processor/InterceptorAuthProcessor.java @@ -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; @@ -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)) { @@ -80,7 +79,7 @@ private void actionIfTokenPresent( private void actionIfTokenAbsent(HttpServletRequest request) { accessManager.manageWithoutAuthentication( - HttpMethod.resolve(request.getMethod()), + HttpMethod.valueOf(request.getMethod()), request.getRequestURI() ); } diff --git a/src/main/java/io/wwan13/wintersecurity/auth/provider/BearerTokenExtractor.java b/src/main/java/io/wwan13/wintersecurity/auth/provider/BearerTokenExtractor.java index db5dfc5..0343b6a 100644 --- a/src/main/java/io/wwan13/wintersecurity/auth/provider/BearerTokenExtractor.java +++ b/src/main/java/io/wwan13/wintersecurity/auth/provider/BearerTokenExtractor.java @@ -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 { diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/RolesResolver.java b/src/main/java/io/wwan13/wintersecurity/resolve/RolesResolver.java index 535848e..08118ab 100644 --- a/src/main/java/io/wwan13/wintersecurity/resolve/RolesResolver.java +++ b/src/main/java/io/wwan13/wintersecurity/resolve/RolesResolver.java @@ -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 { diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/SubjectResolver.java b/src/main/java/io/wwan13/wintersecurity/resolve/SubjectResolver.java index 573c2c7..ee6cd27 100644 --- a/src/main/java/io/wwan13/wintersecurity/resolve/SubjectResolver.java +++ b/src/main/java/io/wwan13/wintersecurity/resolve/SubjectResolver.java @@ -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; diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/util/AttributeExtractor.java b/src/main/java/io/wwan13/wintersecurity/resolve/util/AttributeExtractor.java index e6c7a11..8ea7d95 100644 --- a/src/main/java/io/wwan13/wintersecurity/resolve/util/AttributeExtractor.java +++ b/src/main/java/io/wwan13/wintersecurity/resolve/util/AttributeExtractor.java @@ -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 { diff --git a/src/test/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessorTest.java b/src/test/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessorTest.java index c2c3ec3..ecb0517 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessorTest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/AbstractAuthProcessorTest.java @@ -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 { diff --git a/src/test/java/io/wwan13/wintersecurity/auth/RequestStorageTest.java b/src/test/java/io/wwan13/wintersecurity/auth/RequestStorageTest.java index ff75f30..d544b3b 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/RequestStorageTest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/RequestStorageTest.java @@ -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; diff --git a/src/test/java/io/wwan13/wintersecurity/auth/authpattern/AuthPatternsTest.java b/src/test/java/io/wwan13/wintersecurity/auth/authpattern/AuthPatternsTest.java index 4ce7898..929b1aa 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/authpattern/AuthPatternsTest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/authpattern/AuthPatternsTest.java @@ -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); @@ -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); @@ -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); diff --git a/src/test/java/io/wwan13/wintersecurity/auth/authpattern/RequestsTest.java b/src/test/java/io/wwan13/wintersecurity/auth/authpattern/RequestsTest.java index 4976690..5eea1cd 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/authpattern/RequestsTest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/authpattern/RequestsTest.java @@ -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); diff --git a/src/test/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessorTest.java b/src/test/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessorTest.java index 0caad85..f69c0a9 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessorTest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/processor/AbstractInterceptorAuthProcessorTest.java @@ -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"; diff --git a/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletRequest.java b/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletRequest.java index d938f28..ba8e6f8 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletRequest.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletRequest.java @@ -16,13 +16,32 @@ package io.wwan13.wintersecurity.auth.stub; -import javax.servlet.*; -import javax.servlet.http.*; +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConnection; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; + import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.Principal; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; public class StubHttpServletRequest implements HttpServletRequest { @@ -50,14 +69,9 @@ public StubHttpServletRequest(Map attribute) { public StubHttpServletRequest() { } - @Override - public String getHeader(String name) { - return expectedHeader; - } - @Override public String getAuthType() { - return null; + return ""; } @Override @@ -66,12 +80,17 @@ public Cookie[] getCookies() { } @Override - public long getDateHeader(String name) { + public long getDateHeader(String s) { return 0; } @Override - public Enumeration getHeaders(String name) { + public String getHeader(String s) { + return expectedHeader; + } + + @Override + public Enumeration getHeaders(String s) { return null; } @@ -81,42 +100,42 @@ public Enumeration getHeaderNames() { } @Override - public int getIntHeader(String name) { + public int getIntHeader(String s) { return 0; } @Override public String getMethod() { - return method; + return this.method; } @Override public String getPathInfo() { - return null; + return ""; } @Override public String getPathTranslated() { - return null; + return ""; } @Override public String getContextPath() { - return null; + return ""; } @Override public String getQueryString() { - return null; + return ""; } @Override public String getRemoteUser() { - return null; + return ""; } @Override - public boolean isUserInRole(String role) { + public boolean isUserInRole(String s) { return false; } @@ -127,12 +146,12 @@ public Principal getUserPrincipal() { @Override public String getRequestedSessionId() { - return null; + return ""; } @Override public String getRequestURI() { - return uri; + return this.uri; } @Override @@ -142,11 +161,11 @@ public StringBuffer getRequestURL() { @Override public String getServletPath() { - return null; + return ""; } @Override - public HttpSession getSession(boolean create) { + public HttpSession getSession(boolean b) { return null; } @@ -157,7 +176,7 @@ public HttpSession getSession() { @Override public String changeSessionId() { - return null; + return ""; } @Override @@ -176,17 +195,12 @@ public boolean isRequestedSessionIdFromURL() { } @Override - public boolean isRequestedSessionIdFromUrl() { + public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException { return false; } @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - return false; - } - - @Override - public void login(String username, String password) throws ServletException { + public void login(String s, String s1) throws ServletException { } @@ -197,22 +211,22 @@ public void logout() throws ServletException { @Override public Collection getParts() throws IOException, ServletException { - return null; + return List.of(); } @Override - public Part getPart(String name) throws IOException, ServletException { + public Part getPart(String s) throws IOException, ServletException { return null; } @Override - public T upgrade(Class httpUpgradeHandlerClass) throws IOException, ServletException { + public T upgrade(Class aClass) throws IOException, ServletException { return null; } @Override - public Object getAttribute(String name) { - return attribute.get(name); + public Object getAttribute(String s) { + return attribute.get(s); } @Override @@ -222,11 +236,11 @@ public Enumeration getAttributeNames() { @Override public String getCharacterEncoding() { - return null; + return ""; } @Override - public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException { + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { } @@ -242,7 +256,7 @@ public long getContentLengthLong() { @Override public String getContentType() { - return null; + return ""; } @Override @@ -251,8 +265,8 @@ public ServletInputStream getInputStream() throws IOException { } @Override - public String getParameter(String name) { - return null; + public String getParameter(String s) { + return ""; } @Override @@ -261,28 +275,28 @@ public Enumeration getParameterNames() { } @Override - public String[] getParameterValues(String name) { + public String[] getParameterValues(String s) { return new String[0]; } @Override public Map getParameterMap() { - return null; + return Map.of(); } @Override public String getProtocol() { - return null; + return ""; } @Override public String getScheme() { - return null; + return ""; } @Override public String getServerName() { - return null; + return ""; } @Override @@ -297,21 +311,21 @@ public BufferedReader getReader() throws IOException { @Override public String getRemoteAddr() { - return null; + return ""; } @Override public String getRemoteHost() { - return null; + return ""; } @Override - public void setAttribute(String name, Object o) { - attribute.put(name, o); + public void setAttribute(String s, Object o) { + attribute.put(s, o); } @Override - public void removeAttribute(String name) { + public void removeAttribute(String s) { } @@ -331,12 +345,7 @@ public boolean isSecure() { } @Override - public RequestDispatcher getRequestDispatcher(String path) { - return null; - } - - @Override - public String getRealPath(String path) { + public RequestDispatcher getRequestDispatcher(String s) { return null; } @@ -347,12 +356,12 @@ public int getRemotePort() { @Override public String getLocalName() { - return null; + return ""; } @Override public String getLocalAddr() { - return null; + return ""; } @Override @@ -394,4 +403,19 @@ public AsyncContext getAsyncContext() { public DispatcherType getDispatcherType() { return null; } + + @Override + public String getRequestId() { + return ""; + } + + @Override + public String getProtocolRequestId() { + return ""; + } + + @Override + public ServletConnection getServletConnection() { + return null; + } } diff --git a/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletResponse.java b/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletResponse.java index eb07766..b9000f7 100644 --- a/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletResponse.java +++ b/src/test/java/io/wwan13/wintersecurity/auth/stub/StubHttpServletResponse.java @@ -16,9 +16,10 @@ package io.wwan13.wintersecurity.auth.stub; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; import java.io.PrintWriter; import java.util.Collection; @@ -45,16 +46,6 @@ public String encodeRedirectURL(String url) { return null; } - @Override - public String encodeUrl(String url) { - return null; - } - - @Override - public String encodeRedirectUrl(String url) { - return null; - } - @Override public void sendError(int sc, String msg) throws IOException { @@ -102,12 +93,6 @@ public void addIntHeader(String name, int value) { @Override public void setStatus(int sc) { - - } - - @Override - public void setStatus(int sc, String sm) { - } @Override