forked from DataLinkDC/dinky
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature]support-token-manager (DataLinkDC#2292)
* support-token-manager * support-token-manager * fix some bug * add i18n
- Loading branch information
Showing
48 changed files
with
1,636 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
dinky-admin/src/main/java/org/dinky/controller/TokenController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* | ||
* 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 org.dinky.controller; | ||
|
||
import org.dinky.data.annotation.Log; | ||
import org.dinky.data.enums.BusinessType; | ||
import org.dinky.data.enums.Status; | ||
import org.dinky.data.model.SysToken; | ||
import org.dinky.data.model.UDFTemplate; | ||
import org.dinky.data.result.ProTableResult; | ||
import org.dinky.data.result.Result; | ||
import org.dinky.service.TokenService; | ||
|
||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import cn.hutool.core.lang.UUID; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** TokenController */ | ||
@Slf4j | ||
@Api(tags = "Token Controller") | ||
@RestController | ||
@RequestMapping("/api/token") | ||
@RequiredArgsConstructor | ||
public class TokenController { | ||
|
||
private final TokenService tokenService; | ||
|
||
/** | ||
* get udf template list | ||
* | ||
* @param params {@link JsonNode} | ||
* @return {@link ProTableResult} <{@link UDFTemplate}> | ||
*/ | ||
@PostMapping("/list") | ||
@ApiOperation("Get Token List") | ||
public ProTableResult<SysToken> listToken(@RequestBody JsonNode params) { | ||
return tokenService.selectForProTable(params); | ||
} | ||
|
||
/** | ||
* save or update udf template | ||
* | ||
* @param sysToken {@link SysToken} | ||
* @return {@link Result} <{@link String}> | ||
*/ | ||
@PutMapping("/saveOrUpdateToken") | ||
@ApiOperation("Insert or Update Token") | ||
@Log(title = "Insert or Update Token", businessType = BusinessType.INSERT_OR_UPDATE) | ||
public Result<Void> saveOrUpdateToken(@RequestBody SysToken sysToken) { | ||
return tokenService.saveOrUpdate(sysToken) | ||
? Result.succeed(Status.SAVE_SUCCESS) | ||
: Result.failed(Status.SAVE_FAILED); | ||
} | ||
|
||
/** | ||
* delete Token by id | ||
* | ||
* @param id {@link Integer} | ||
* @return {@link Result} <{@link Void}> | ||
*/ | ||
@DeleteMapping("/delete") | ||
@Log(title = "Delete Token By Id", businessType = BusinessType.DELETE) | ||
@ApiOperation("Delete Token By Id") | ||
@Transactional(rollbackFor = Exception.class) | ||
public Result<Void> deleteToken(@RequestParam Integer id) { | ||
if (tokenService.removeTokenById(id)) { | ||
return Result.succeed(Status.DELETE_SUCCESS); | ||
} else { | ||
return Result.failed(Status.DELETE_FAILED); | ||
} | ||
} | ||
|
||
/** | ||
* delete Token by id | ||
* @return {@link Result} <{@link Void}> | ||
*/ | ||
@PostMapping("/buildToken") | ||
@Log(title = "Build Token", businessType = BusinessType.OTHER) | ||
@ApiOperation("Build Token") | ||
public Result<String> buildToken() { | ||
return Result.succeed(UUID.fastUUID().toString(true), Status.SUCCESS); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
dinky-admin/src/main/java/org/dinky/data/model/SysToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* | ||
* 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 org.dinky.data.model; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import com.baomidou.mybatisplus.annotation.FieldFill; | ||
import com.baomidou.mybatisplus.annotation.IdType; | ||
import com.baomidou.mybatisplus.annotation.TableField; | ||
import com.baomidou.mybatisplus.annotation.TableId; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@TableName("dinky_sys_token") | ||
public class SysToken implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@TableId(value = "id", type = IdType.AUTO) | ||
private Integer id; | ||
|
||
private String tokenValue; | ||
private Integer userId; | ||
private Integer roleId; | ||
private Integer tenantId; | ||
|
||
private Integer expireType; | ||
|
||
private Date expireStartTime; | ||
private Date expireEndTime; | ||
|
||
@TableField(fill = FieldFill.INSERT) | ||
@JsonDeserialize(using = LocalDateTimeDeserializer.class) | ||
@JsonSerialize(using = LocalDateTimeSerializer.class) | ||
private LocalDateTime createTime; | ||
|
||
@TableField(fill = FieldFill.INSERT_UPDATE) | ||
@JsonDeserialize(using = LocalDateTimeDeserializer.class) | ||
@JsonSerialize(using = LocalDateTimeSerializer.class) | ||
private LocalDateTime updateTime; | ||
|
||
private Integer creator; | ||
private Integer updator; | ||
|
||
@TableField(exist = false) | ||
private String userName; | ||
|
||
@TableField(exist = false) | ||
private String roleName; | ||
|
||
@TableField(exist = false) | ||
private String tenantCode; | ||
|
||
@TableField(exist = false) | ||
private List<LocalDateTime> expireTimeRange = new ArrayList<>(); | ||
} |
29 changes: 29 additions & 0 deletions
29
dinky-admin/src/main/java/org/dinky/mapper/TokenMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* | ||
* 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 org.dinky.mapper; | ||
|
||
import org.dinky.data.model.SysToken; | ||
import org.dinky.mybatis.mapper.SuperMapper; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
/** TokenMapper */ | ||
@Mapper | ||
public interface TokenMapper extends SuperMapper<SysToken> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
dinky-admin/src/main/java/org/dinky/service/TokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* | ||
* 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 org.dinky.service; | ||
|
||
import org.dinky.data.model.SysToken; | ||
import org.dinky.mybatis.service.ISuperService; | ||
|
||
public interface TokenService extends ISuperService<SysToken> { | ||
|
||
/** | ||
* remove token by id | ||
* | ||
* @param tokenId token id | ||
* @return delete result code | ||
*/ | ||
boolean removeTokenById(Integer tokenId); | ||
|
||
/** | ||
* add or update token | ||
* | ||
* @param token token | ||
* @return add or update code | ||
*/ | ||
boolean saveOrUpdateSysToken(SysToken token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.