Skip to content

3.x #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024
Merged

3.x #47

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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
4 changes: 2 additions & 2 deletions springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.2.2</version>
<version>3.2.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -61,4 +61,4 @@

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.codingapi.springboot.fast;

import com.codingapi.springboot.fast.manager.EntityManagerInitializer;
import com.codingapi.springboot.fast.mapping.MvcMappingRegister;
import com.codingapi.springboot.fast.script.ScriptMappingRegister;
import com.codingapi.springboot.fast.mapping.FastMvcMappingRegister;
import com.codingapi.springboot.fast.script.FastScriptMappingRegister;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
Expand All @@ -18,8 +19,8 @@ public class DataFastConfiguration {

@Bean
@ConditionalOnMissingBean
public MvcMappingRegister mvcMappingRegister(RequestMappingHandlerMapping handlerMapping) {
return new MvcMappingRegister(handlerMapping);
public FastMvcMappingRegister fastMvcMappingRegister(@Qualifier("requestMappingHandlerMapping") RequestMappingHandlerMapping requestMappingHandlerMapping) {
return new FastMvcMappingRegister(requestMappingHandlerMapping);
}


Expand All @@ -31,8 +32,8 @@ public EntityManagerInitializer entityManagerInitializer(EntityManager entityMan


@Bean
public ScriptMappingRegister scriptMappingRegister(MvcMappingRegister mvcMappingRegister) {
return new ScriptMappingRegister(mvcMappingRegister);
public FastScriptMappingRegister fastScriptMappingRegister(FastMvcMappingRegister fastMvcMappingRegister) {
return new FastScriptMappingRegister(fastMvcMappingRegister);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.codingapi.springboot.fast.mapping;

import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
Expand All @@ -9,11 +11,14 @@

import java.lang.reflect.Method;

@AllArgsConstructor
public class MvcMappingRegister {
public class FastMvcMappingRegister {

private final RequestMappingHandlerMapping handlerMapping;

public FastMvcMappingRegister(
RequestMappingHandlerMapping handlerMapping) {
this.handlerMapping = handlerMapping;
}

/**
* add mvc mapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.codingapi.springboot.fast.script;

import com.codingapi.springboot.fast.mapping.MvcMappingRegister;
import com.codingapi.springboot.fast.mapping.FastMvcMappingRegister;
import com.codingapi.springboot.framework.dto.response.Response;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class ScriptMappingRegister {
public class FastScriptMappingRegister {

private final MvcMappingRegister mappingRegister;
private final FastMvcMappingRegister fastMvcMappingRegister;

/**
* test dynamic mapping
*
* @param scriptMapping dynamic mapping
**/
public void addMapping(ScriptMapping scriptMapping) {
mappingRegister.addMapping(scriptMapping.getMapping(), scriptMapping.getScriptMethod().toRequestMethod(),
fastMvcMappingRegister.addMapping(scriptMapping.getMapping(), scriptMapping.getScriptMethod().toRequestMethod(),
scriptMapping, scriptMapping.getExecuteMethod());
}

Expand All @@ -38,7 +38,7 @@ public Response test(ScriptMapping scriptMapping) {
* @param requestMethod request method
*/
public void removeMapping(String url, ScriptMethod scriptMethod){
mappingRegister.removeMapping(url, scriptMethod.toRequestMethod());
fastMvcMappingRegister.removeMapping(url, scriptMethod.toRequestMethod());
}


Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.2.2</version>
<version>3.2.3</version>
</parent>

<artifactId>springboot-starter-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.codingapi.springboot.security.configurer.HttpSecurityConfigurer;
import com.codingapi.springboot.security.controller.VersionController;
import com.codingapi.springboot.security.dto.request.LoginRequest;
import com.codingapi.springboot.security.dto.response.LoginResponse;
import com.codingapi.springboot.security.filter.*;
import com.codingapi.springboot.security.gateway.Token;
import com.codingapi.springboot.security.gateway.TokenGateway;
Expand Down Expand Up @@ -65,21 +66,25 @@ public PasswordEncoder passwordEncoder() {
public SecurityLoginHandler securityLoginHandler() {
return new SecurityLoginHandler() {
@Override
public void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler) throws Exception {
public void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest) throws Exception {

}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler, Token token) {

public LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token) {
LoginResponse loginResponse = new LoginResponse();
loginResponse.setToken(token.getToken());
loginResponse.setUsername(token.getUsername());
loginResponse.setAuthorities(token.getAuthorities());
return loginResponse;
}
};
}

@Bean
@ConditionalOnMissingBean
public AuthenticationTokenFilter authenticationTokenFilter() {
return (request, response, chain) -> {
return (request, response) -> {

};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
@Setter
@Getter
public class LoginResponse {

private String username;
private String token;
private List<String> authorities;

private Object data;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.codingapi.springboot.security.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public interface AuthenticationTokenFilter {

void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain);
void doFilter(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}

SecurityContextHolder.getContext().setAuthentication(token.getAuthenticationToken());
authenticationTokenFilter.doFilter(request, response, chain);
authenticationTokenFilter.doFilter(request, response);
}
}
chain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,10 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()),
TokenContext.getExtra());

LoginResponse login = new LoginResponse();
login.setUsername(user.getUsername());
login.setToken(token.getToken());
login.setAuthorities(token.getAuthorities());

String content = JSONObject.toJSONString(SingleResponse.of(login));
LoginResponse loginResponse = loginHandler.postHandle(request,response,loginRequest,token);
String content = JSONObject.toJSONString(SingleResponse.of(loginResponse));
IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8);

loginHandler.postHandle(request,response,loginRequest,token);
LoginRequestContext.getInstance().clean();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.codingapi.springboot.security.filter;

import com.codingapi.springboot.security.dto.request.LoginRequest;
import com.codingapi.springboot.security.dto.response.LoginResponse;
import com.codingapi.springboot.security.gateway.Token;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public interface SecurityLoginHandler {

void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler) throws Exception;
void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest) throws Exception;

void postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler, Token token);
LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token);

}
2 changes: 1 addition & 1 deletion springboot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
</parent>
<artifactId>springboot-starter</artifactId>

Expand Down