diff --git a/canal-admin/canal-admin-server/pom.xml b/canal-admin/canal-admin-server/pom.xml
index 3e031738..92b5d038 100644
--- a/canal-admin/canal-admin-server/pom.xml
+++ b/canal-admin/canal-admin-server/pom.xml
@@ -29,10 +29,6 @@
mysql
mysql-connector-java
-
- commons-dbutils
- commons-dbutils
-
com.github.ben-manes.caffeine
caffeine
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ConfigurationException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ConfigurationException.java
deleted file mode 100644
index 617bffc8..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ConfigurationException.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.otter.canal.admin.common.exception;
-
-public class ConfigurationException extends RuntimeException{
-
- public ConfigurationException(String message) {
- super(message);
- }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ParamValidationException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ParamValidationException.java
deleted file mode 100644
index 96d2edab..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ParamValidationException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.alibaba.otter.canal.admin.common.exception;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Parameter validation failure exception
- */
-@ResponseStatus(value = HttpStatus.BAD_REQUEST)
-public class ParamValidationException extends SystemException {
-
- public ParamValidationException(String message) {
- super(message);
- }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/PermissionDeniedException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/PermissionDeniedException.java
deleted file mode 100644
index d7d1148f..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/PermissionDeniedException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.alibaba.otter.canal.admin.common.exception;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Permission denied exception
- */
-@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
-public class PermissionDeniedException extends RuntimeException {
-
- public PermissionDeniedException(String message) {
- super(message);
- }
-
- public PermissionDeniedException(String message, Throwable cause) {
- super(message, cause);
- }
-
- protected PermissionDeniedException() {
- super();
- }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ResourceNotFoundException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ResourceNotFoundException.java
deleted file mode 100644
index 4423966e..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/ResourceNotFoundException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.alibaba.otter.canal.admin.common.exception;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Resource not found exception
- */
-@ResponseStatus(value = HttpStatus.NOT_FOUND)
-public class ResourceNotFoundException extends SystemException {
-
- public ResourceNotFoundException() {
- }
-
- public ResourceNotFoundException(String message) {
- super(message);
- }
-
- public ResourceNotFoundException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ResourceNotFoundException(Throwable cause) {
- super(cause);
- }
-
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/SystemException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/SystemException.java
deleted file mode 100644
index 4507dbfa..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/SystemException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.alibaba.otter.canal.admin.common.exception;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * System Exception
- */
-@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-public class SystemException extends RuntimeException {
-
- public SystemException() {
- super();
- }
-
- public SystemException(String message) {
- super(message);
- }
-
- public SystemException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public SystemException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/VersionValidationException.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/VersionValidationException.java
deleted file mode 100644
index f02c8cbc..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/common/exception/VersionValidationException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.otter.canal.admin.common.exception;
-
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-@ResponseStatus(value = HttpStatus.BAD_REQUEST)
-public class VersionValidationException extends SystemException{
-
- public VersionValidationException(String message) {
- super(message);
- }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/Config.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/Config.java
deleted file mode 100644
index 1a25bc13..00000000
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/Config.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.alibaba.otter.canal.admin.config;
-
-import javax.sql.DataSource;
-
-import io.ebean.EbeanServer;
-import org.apache.commons.dbutils.QueryRunner;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class Config {
-
- @Bean
- public QueryRunner queryRunner(DataSource dataSource) {
- return new QueryRunner(dataSource);
- }
-
-// @Bean("ebeanServer")
-// public FactoryBean ebeanServer(DataSource dataSource) {
-// return new EbeanServerFactory(dataSource);
-// }
-}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/WebConfig.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/WebConfig.java
index 25fe2e9b..68f906e8 100644
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/WebConfig.java
+++ b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/config/WebConfig.java
@@ -43,37 +43,43 @@ public class WebConfig implements WebMvcConfigurer {
}
}).addPathPatterns("/api/**");
-// registry.addInterceptor(new HandlerInterceptor() {
-//
-// @Override
-// public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
-// Object o) throws Exception {
-// String token = httpServletRequest.getHeader("X-Token");
-// boolean valid = false;
-// if (token != null) {
-// User user = UserController.loginUsers.getIfPresent(token);
-// if (user != null) {
-// valid = true;
-// }
-// }
-// if (!valid) {
-// BaseModel baseModel = BaseModel.getInstance(null);
-// baseModel.setCode(50014);
-// baseModel.setMessage("Expired token");
-// ObjectMapper mapper = new ObjectMapper();
-// String json = mapper.writeValueAsString(baseModel);
-// try {
-// httpServletResponse.setContentType("application/json;charset=UTF-8");
-// PrintWriter out = httpServletResponse.getWriter();
-// out.print(json);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// return false;
-// }
-//
-// return true;
-// }
-// }).addPathPatterns("/api/**").excludePathPatterns("/api/**/user/**");
+ registry.addInterceptor(new HandlerInterceptor() {
+
+ @Override
+ public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
+ Object o) throws Exception {
+ String token = httpServletRequest.getHeader("X-Token");
+ boolean valid = false;
+ if (token != null) {
+ User user = UserController.loginUsers.getIfPresent(token);
+ if (user != null) {
+ valid = true;
+ httpServletRequest.setAttribute("user", user);
+ httpServletRequest.setAttribute("token", token);
+ }
+ }
+ if (!valid) {
+ BaseModel baseModel = BaseModel.getInstance(null);
+ baseModel.setCode(50014);
+ baseModel.setMessage("Expired token");
+ ObjectMapper mapper = new ObjectMapper();
+ String json = mapper.writeValueAsString(baseModel);
+ try {
+ httpServletResponse.setContentType("application/json;charset=UTF-8");
+ PrintWriter out = httpServletResponse.getWriter();
+ out.print(json);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ return true;
+ }
+ })
+ .addPathPatterns("/api/**")
+ .excludePathPatterns("/api/**/user/login")
+ .excludePathPatterns("/api/**/user/logout")
+ .excludePathPatterns("/api/**/user/info");
}
}
diff --git a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/controller/UserController.java b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/controller/UserController.java
index c01161a9..8ca61668 100644
--- a/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/controller/UserController.java
+++ b/canal-admin/canal-admin-server/src/main/java/com/alibaba/otter/canal/admin/controller/UserController.java
@@ -1,12 +1,15 @@
package com.alibaba.otter.canal.admin.controller;
+import com.alibaba.otter.canal.admin.service.UserService;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.alibaba.otter.canal.admin.model.BaseModel;
import com.alibaba.otter.canal.admin.model.User;
+import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -21,12 +24,16 @@ public class UserController {
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(key -> null);
+ @Autowired
+ UserService userService;
+
@PostMapping(value = "/login")
public BaseModel