提交 d11c499e 编写于 作者: M MaxKey

FileUpload&UserInfo&Accounts

上级 a14aeb1b
......@@ -71,6 +71,8 @@ public class Accounts extends JpaBaseEntity implements Serializable {
@Column
private String strategyId;
@Column
private String strategyName;
@Column
private int status;
@Column
......@@ -214,7 +216,15 @@ public class Accounts extends JpaBaseEntity implements Serializable {
}
}
public String getInstId() {
public String getStrategyName() {
return strategyName;
}
public void setStrategyName(String strategyName) {
this.strategyName = strategyName;
}
public String getInstId() {
return instId;
}
......
package org.maxkey.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "MXK_FILE_UPLOAD")
public class FileUpload extends JpaBaseEntity {
private static final long serialVersionUID = -4338400992411166457L;
@Id
@Column
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
String id;
@Column
byte[] uploaded;
@JsonIgnore
MultipartFile uploadFile;
@Column
String fileName;
@Column
String contentType;
@Column
long contentSize;
@Column
String createdBy;
String createdDate;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public byte[] getUploaded() {
return uploaded;
}
public void setUploaded(byte[] uploaded) {
this.uploaded = uploaded;
}
public MultipartFile getUploadFile() {
return uploadFile;
}
public void setUploadFile(MultipartFile uploadFile) {
this.uploadFile = uploadFile;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public long getContentSize() {
return contentSize;
}
public void setContentSize(long contentSize) {
this.contentSize = contentSize;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FileUpload [id=");
builder.append(id);
builder.append(", uploadFile=");
builder.append(uploadFile);
builder.append(", createdBy=");
builder.append(this.createdBy);
builder.append("]");
return builder.toString();
}
}
......@@ -18,7 +18,6 @@
package org.maxkey.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
......@@ -31,7 +30,6 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import org.maxkey.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
/**
* .
......@@ -110,8 +108,7 @@ public class UserInfo extends JpaBaseEntity {
@Column
protected byte[] picture;
protected String pictureBase64;
@JsonIgnore
protected MultipartFile pictureFile;
protected String pictureId;
@Column
protected int idType;
@Column
......@@ -413,16 +410,6 @@ public class UserInfo extends JpaBaseEntity {
this.password = password;
}
public byte[] getPicture() {
if (pictureFile != null && !pictureFile.isEmpty()) {
try {
picture = pictureFile.getBytes();
} catch (IOException e) {
e.printStackTrace();
}
}
return picture;
}
public String getPictureBase64() {
return pictureBase64;
......@@ -439,6 +426,10 @@ public class UserInfo extends JpaBaseEntity {
}
}
public byte[] getPicture() {
return picture;
}
/**
* @return the protectedAppsMap
*/
......@@ -628,15 +619,15 @@ public class UserInfo extends JpaBaseEntity {
this.birthDate = birthDate;
}
public MultipartFile getPictureFile() {
return pictureFile;
}
public String getPictureId() {
return pictureId;
}
public void setPictureFile(MultipartFile pictureFile) {
this.pictureFile = pictureFile;
}
public void setPictureId(String pictureId) {
this.pictureId = pictureId;
}
public int getIdType() {
public int getIdType() {
return idType;
}
......
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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.maxkey.persistence.mapper;
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.maxkey.entity.FileUpload;
/**
* @author Crystal.sea
*
*/
public interface FileUploadMapper extends IJpaBaseMapper<FileUpload> {
}
/*
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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.maxkey.persistence.service;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.FileUpload;
import org.maxkey.persistence.mapper.FileUploadMapper;
import org.springframework.stereotype.Repository;
@Repository
public class FileUploadService extends JpaBaseService<FileUpload>{
public FileUploadService() {
super(FileUploadMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public FileUploadMapper getMapper() {
return (FileUploadMapper)super.getMapper();
}
}
......@@ -212,7 +212,7 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
public UserInfo passwordEncoder(UserInfo userInfo) {
//密码不为空,则需要进行加密处理
if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
if(!StringUtils.isBlank(userInfo.getPassword())) {
String password = passwordEncoder.encode(userInfo.getPassword());
userInfo.setDecipherable(PasswordReciprocal.getInstance().encode(userInfo.getPassword()));
_logger.debug("decipherable : "+userInfo.getDecipherable());
......@@ -220,6 +220,9 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
userInfo.setPasswordLastSetTime(DateUtils.getCurrentDateTimeAsString());
userInfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
}else {
userInfo.setPassword(null);
userInfo.setDecipherable(null);
}
return userInfo;
}
......
......@@ -121,6 +121,7 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/apps/**")
.addPathPatterns("/accounts/**")
.addPathPatterns("/access/**")
.addPathPatterns("/access/**/**")
......@@ -136,6 +137,8 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/institutions/**")
.addPathPatterns("/localization/**")
.addPathPatterns("/file/upload/")
;
_logger.debug("add PermissionAdapter");
......
......@@ -83,6 +83,7 @@ public class AccountsController {
@RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> get(@PathVariable("id") String id) {
Accounts account=accountsService.get(id);
account.setRelatedPassword(PasswordReciprocal.getInstance().decoder(account.getRelatedPassword()));
return new Message<Accounts>(account).buildResponse();
}
......@@ -127,10 +128,13 @@ public class AccountsController {
@ResponseBody
@RequestMapping(value = "/generate")
public String generate(@ModelAttribute Accounts account) {
public ResponseEntity<?> generate(@ModelAttribute Accounts account) {
AccountsStrategy accountsStrategy = accountsStrategyService.get(account.getStrategyId());
UserInfo userInfo = userInfoService.get(account.getUserId());
return accountsService.generateAccount(userInfo,accountsStrategy);
return new Message<Object>(
Message.SUCCESS,
(Object)accountsService.generateAccount(userInfo,accountsStrategy)
).buildResponse();
}
}
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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.maxkey.web.contorller;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.entity.FileUpload;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.service.FileUploadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class FileUploadEndpoint {
private static Logger _logger = LoggerFactory.getLogger(FileUploadEndpoint.class);
@Autowired
FileUploadService fileUploadService;
@RequestMapping(value={"/file/upload/"})
@ResponseBody
public ResponseEntity<?> upload( HttpServletRequest request,
HttpServletResponse response,
@ModelAttribute FileUpload fileUpload,
@CurrentUser UserInfo currentUser){
_logger.debug("FileUpload");
fileUpload.setId(fileUpload.generateId());
fileUpload.setContentType(fileUpload.getUploadFile().getContentType());
fileUpload.setFileName(fileUpload.getUploadFile().getOriginalFilename());
fileUpload.setContentSize(fileUpload.getUploadFile().getSize());
fileUpload.setCreatedBy(currentUser.getUsername());
/*
* upload UploadFile MultipartFile to Uploaded Bytes
*/
if(null!=fileUpload.getUploadFile()&&!fileUpload.getUploadFile().isEmpty()){
try {
fileUpload.setUploaded(fileUpload.getUploadFile().getBytes());
fileUploadService.insert(fileUpload);
_logger.trace("FileUpload SUCCESS");
} catch (IOException e) {
_logger.error("FileUpload IOException",e);
}
}
return new Message<Object>(Message.SUCCESS,(Object)fileUpload.getId()).buildResponse();
}
}
......@@ -38,6 +38,7 @@ import org.maxkey.constants.ConstsPasswordSetType;
import org.maxkey.entity.ExcelImport;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.service.FileUploadService;
import org.maxkey.persistence.service.UserInfoService;
import org.maxkey.util.DateUtils;
import org.maxkey.util.ExcelUtils;
......@@ -73,6 +74,9 @@ public class UserInfoController {
@Autowired
private UserInfoService userInfoService;
@Autowired
FileUploadService fileUploadService;
@RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE})
......@@ -101,6 +105,8 @@ public class UserInfoController {
if(userInfo.getPicture()!=null){
userInfo.transPictureBase64();
}
userInfo.setPassword("");
userInfo.setDecipherable("");
return new Message<UserInfo>(userInfo).buildResponse();
}
......@@ -110,6 +116,10 @@ public class UserInfoController {
_logger.debug("-Add :" + userInfo);
userInfo.setId(WebContext.genId());
userInfo.setInstId(currentUser.getInstId());
if(StringUtils.isNotBlank(userInfo.getPictureId())) {
userInfo.setPicture(fileUploadService.get(userInfo.getPictureId()).getUploaded());
fileUploadService.remove(userInfo.getPictureId());
}
if (userInfoService.insert(userInfo)) {
return new Message<UserInfo>(Message.SUCCESS).buildResponse();
} else {
......@@ -128,6 +138,10 @@ public class UserInfoController {
convertExtraAttribute(userInfo) ;
_logger.info(userInfo.getExtraAttribute());
userInfo.setInstId(currentUser.getInstId());
if(StringUtils.isNotBlank(userInfo.getPictureId())) {
userInfo.setPicture(fileUploadService.get(userInfo.getPictureId()).getUploaded());
fileUploadService.remove(userInfo.getPictureId());
}
if (userInfoService.update(userInfo)) {
return new Message<UserInfo>(Message.SUCCESS).buildResponse();
} else {
......@@ -148,9 +162,12 @@ public class UserInfoController {
@ResponseBody
@RequestMapping(value = "/randomPassword")
public String randomPassword() {
return userInfoService.randomPassword();
@RequestMapping(value = "/randomPassword", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> randomPassword() {
return new Message<Object>(
Message.SUCCESS,
(Object)userInfoService.randomPassword()
).buildResponse();
}
......@@ -169,7 +186,7 @@ public class UserInfoController {
@ResponseBody
@RequestMapping(value="/changePassword")
@RequestMapping(value="/changePassword", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> changePassword( @ModelAttribute("userInfo")UserInfo userInfo) {
_logger.debug(userInfo.getId());
userInfo.setPasswordSetType(ConstsPasswordSetType.PASSWORD_NORMAL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册