tab to 4 space

This commit is contained in:
MaxKey
2025-11-01 11:17:01 +08:00
parent e823cb1fec
commit dc5e773726
834 changed files with 43445 additions and 43445 deletions

View File

@@ -36,24 +36,24 @@ import org.springframework.context.ConfigurableApplicationContext;
@EnableDiscoveryClient
@MapperScan("org.dromara.maxkey.persistence.mapper,")
public class MaxKeyApiApplication extends SpringBootServletInitializer {
static final Logger _logger = LoggerFactory.getLogger(MaxKeyApiApplication.class);
static final Logger _logger = LoggerFactory.getLogger(MaxKeyApiApplication.class);
public static void main(String[] args) {
_logger.info("Start MaxKey Api Application ...");
ProductEnvironment.listEnvVars();
ConfigurableApplicationContext applicationContext = SpringApplication.run(MaxKeyApiApplication.class, args);
new InitializeContext(applicationContext).init();
_logger.info("MaxKey Api at {}" , new DateTime());
_logger.info("MaxKey Api Server Port {}" , WebContext.getServerPort());
_logger.info("MaxKey Api started.");
}
public static void main(String[] args) {
_logger.info("Start MaxKey Api Application ...");
ProductEnvironment.listEnvVars();
ConfigurableApplicationContext applicationContext = SpringApplication.run(MaxKeyApiApplication.class, args);
new InitializeContext(applicationContext).init();
_logger.info("MaxKey Api at {}" , new DateTime());
_logger.info("MaxKey Api Server Port {}" , WebContext.getServerPort());
_logger.info("MaxKey Api started.");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MaxKeyApiApplication.class);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MaxKeyApiApplication.class);
}
}

View File

@@ -48,15 +48,15 @@ public class MaxKeyOpenApiConfig{
UserInfoService userInfoService,
IpLocationParser ipLocationParser,
JdbcTemplate jdbcTemplate) {
JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm(
passwordEncoder,
passwordPolicyValidatorService,
loginService,
historyLoginService,
userInfoService,
ipLocationParser,
jdbcTemplate);
passwordEncoder,
passwordPolicyValidatorService,
loginService,
historyLoginService,
userInfoService,
ipLocationParser,
jdbcTemplate);
logger.debug("JdbcAuthenticationRealm inited.");
return authenticationRealm;
@@ -64,8 +64,8 @@ public class MaxKeyOpenApiConfig{
@Bean
AbstractOtpAuthn timeBasedOtpAuthn() {
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
logger.debug("TimeBasedOtpAuthn inited.");
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
logger.debug("TimeBasedOtpAuthn inited.");
return tfaOtpAuthn;
}
}

View File

@@ -35,7 +35,7 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(MaxKeyOpenApiMvcConfig.class);
@Autowired
ApplicationConfig applicationConfig;
ApplicationConfig applicationConfig;
@Autowired
AbstractAuthenticationProvider authenticationProvider ;
@@ -96,7 +96,7 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/api/idm/**")
.addPathPatterns("/api/idm/scim/**")
;
logger.debug("add Rest Api Permission Adapter");
}

View File

@@ -34,7 +34,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@RequestMapping(value={"/api/otp"})
public class RestTimeBasedOtpController {
@Autowired
@Autowired
AbstractOtpAuthn timeBasedOtpAuthn;
@Autowired
@@ -44,15 +44,15 @@ public class RestTimeBasedOtpController {
@ResponseBody
@RequestMapping(value = "/timebased/validate", method = RequestMethod.GET)
public boolean getUser(@RequestParam String username,
@RequestParam String token) {
UserInfo validUserInfo = userInfoService.findByUsername(username);
if(validUserInfo != null) {
if(timeBasedOtpAuthn.validate(validUserInfo, token)) {
return true;
}
}
@RequestParam String token) {
UserInfo validUserInfo = userInfoService.findByUsername(username);
if(validUserInfo != null) {
if(timeBasedOtpAuthn.validate(validUserInfo, token)) {
return true;
}
}
return false;
}

View File

@@ -48,79 +48,79 @@ import jakarta.servlet.http.HttpServletResponse;
*/
@Component
public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(RestApiPermissionAdapter.class);
private static final Logger logger = LoggerFactory.getLogger(RestApiPermissionAdapter.class);
static final String PASSWORD = "password";
@Autowired
DefaultTokenServices oauth20TokenServices;
static final String PASSWORD = "password";
@Autowired
DefaultTokenServices oauth20TokenServices;
@Autowired
AppsService appsService;
/*
* 请求前处理
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
logger.trace("Rest API Permission Adapter pre handle");
AuthorizationHeader headerCredential = AuthorizationHeaderUtils.resolve(request);
//判断应用的AppId和Secret
if(headerCredential != null){
UsernamePasswordAuthenticationToken authenticationToken = null;
if(headerCredential.isBasic()) {
if(StringUtils.isNotBlank(headerCredential.getUsername())&&
StringUtils.isNotBlank(headerCredential.getCredential())
) {
String appId = headerCredential.getUsername();
String credential = headerCredential.getCredential();
Apps app = appsService.get(appId, true);
if(app != null ) {
if( PasswordReciprocal.getInstance().matches(credential, app.getSecret())) {
ArrayList<SimpleGrantedAuthority> grantedAuthoritys = new ArrayList<>();
grantedAuthoritys.add(new SimpleGrantedAuthority("ROLE_USER"));
User user = new User(appId, PASSWORD, grantedAuthoritys);
authenticationToken= new UsernamePasswordAuthenticationToken(user, PASSWORD, grantedAuthoritys);
}else {
logger.trace("app {} secret not matches . ",appId);
}
}else {
logger.trace("app {} not exists . ",appId);
}
}
}else if(StringUtils.isNotBlank(headerCredential.getCredential())){
logger.trace("Authentication bearer {}" , headerCredential.getCredential());
OAuth2Authentication oauth2Authentication =
oauth20TokenServices.loadAuthentication(headerCredential.getCredential());
if(oauth2Authentication != null) {
logger.trace("Authentication token {}" , oauth2Authentication.getPrincipal().toString());
authenticationToken= new UsernamePasswordAuthenticationToken(
new User(
oauth2Authentication.getPrincipal().toString(),
"CLIENT_SECRET",
oauth2Authentication.getAuthorities()),
"PASSWORD",
oauth2Authentication.getAuthorities()
);
}else {
logger.trace("Authentication token is null ");
}
}
if(authenticationToken !=null && authenticationToken.isAuthenticated()) {
AuthorizationUtils.setAuthentication(authenticationToken);
return true;
}
}
logger.trace("No Authentication ... forward to /login");
@Autowired
AppsService appsService;
/*
* 请求前处理
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
logger.trace("Rest API Permission Adapter pre handle");
AuthorizationHeader headerCredential = AuthorizationHeaderUtils.resolve(request);
//判断应用的AppId和Secret
if(headerCredential != null){
UsernamePasswordAuthenticationToken authenticationToken = null;
if(headerCredential.isBasic()) {
if(StringUtils.isNotBlank(headerCredential.getUsername())&&
StringUtils.isNotBlank(headerCredential.getCredential())
) {
String appId = headerCredential.getUsername();
String credential = headerCredential.getCredential();
Apps app = appsService.get(appId, true);
if(app != null ) {
if( PasswordReciprocal.getInstance().matches(credential, app.getSecret())) {
ArrayList<SimpleGrantedAuthority> grantedAuthoritys = new ArrayList<>();
grantedAuthoritys.add(new SimpleGrantedAuthority("ROLE_USER"));
User user = new User(appId, PASSWORD, grantedAuthoritys);
authenticationToken= new UsernamePasswordAuthenticationToken(user, PASSWORD, grantedAuthoritys);
}else {
logger.trace("app {} secret not matches . ",appId);
}
}else {
logger.trace("app {} not exists . ",appId);
}
}
}else if(StringUtils.isNotBlank(headerCredential.getCredential())){
logger.trace("Authentication bearer {}" , headerCredential.getCredential());
OAuth2Authentication oauth2Authentication =
oauth20TokenServices.loadAuthentication(headerCredential.getCredential());
if(oauth2Authentication != null) {
logger.trace("Authentication token {}" , oauth2Authentication.getPrincipal().toString());
authenticationToken= new UsernamePasswordAuthenticationToken(
new User(
oauth2Authentication.getPrincipal().toString(),
"CLIENT_SECRET",
oauth2Authentication.getAuthorities()),
"PASSWORD",
oauth2Authentication.getAuthorities()
);
}else {
logger.trace("Authentication token is null ");
}
}
if(authenticationToken !=null && authenticationToken.isAuthenticated()) {
AuthorizationUtils.setAuthentication(authenticationToken);
return true;
}
}
logger.trace("No Authentication ... forward to /login");
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
dispatcher.forward(request, response);
return false;
}
return false;
}
}