Skip to content

Commit bfa41ac

Browse files
author
tiansh
committed
add:新增webdav相关功能,修复安全隐患
1 parent ca0da1d commit bfa41ac

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

src/main/java/cn/hellohao/auth/shiro/ShiroConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public ShiroFilterFactoryBean shiroFilterFactoryBean(@Qualifier("defaultWebSecur
3333
filterMap.put("/verifyCodeForRetrieve","anon");
3434
filterMap.put("/verifyCodeFortowSendEmail","anon");
3535
filterMap.put("/api/**","anon");
36+
filterMap.put("/w/**","anon");
3637
filterMap.put("/user/**","anon");
3738
filterMap.put("/ota/**","anon");
3839
filterMap.put("/admin/root/**","roles[admin]");

src/main/java/cn/hellohao/controller/IndexController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class IndexController {
4747
@Autowired private IRedisService iRedisService;
4848
@Autowired private AppClientService appClientService;
4949
@Autowired private WebDAVImageupload webDAVImageupload;
50-
public static String version = "20240111";
50+
public static String version = "20240124";
5151
@RequestMapping(value = "/")
5252
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
5353
model.addAttribute("name", "服务端程序(开源版)");

src/main/java/cn/hellohao/utils/verifyCode/SimpleCharVerifyCodeGenImpl.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ public class SimpleCharVerifyCodeGenImpl implements IVerifyCodeGen {
3030
* @param height
3131
*/
3232
private static void fillBackground(Graphics graphics, int width, int height) {
33-
// 填充背景
34-
graphics.setColor(Color.WHITE);
35-
//设置矩形坐标x y 为0
36-
graphics.fillRect(0, 0, width, height);
33+
// 填充背景
34+
graphics.setColor(Color.WHITE);
35+
//设置矩形坐标x y 为0
36+
graphics.fillRect(0, 0, width, height);
3737

38-
// 加入干扰线条
39-
for (int i = 0; i < 8; i++) {
40-
//设置随机颜色算法参数
41-
graphics.setColor(RandomUtils.randomColor(40, 150));
42-
Random random = new Random();
43-
int x = random.nextInt(width);
44-
int y = random.nextInt(height);
45-
int x1 = random.nextInt(width);
46-
int y1 = random.nextInt(height);
47-
graphics.drawLine(x, y, x1, y1);
48-
}
38+
// 加入干扰线条
39+
for (int i = 0; i < 8; i++) {
40+
//设置随机颜色算法参数
41+
graphics.setColor(RandomUtils.randomColor(40, 150));
42+
Random random = new Random();
43+
int x = random.nextInt(width);
44+
int y = random.nextInt(height);
45+
int x1 = random.nextInt(width);
46+
int y1 = random.nextInt(height);
47+
graphics.drawLine(x, y, x1, y1);
48+
}
4949
}
5050

5151
/**
@@ -59,15 +59,15 @@ private static void fillBackground(Graphics graphics, int width, int height) {
5959
*/
6060
@Override
6161
public String generate(int width, int height, OutputStream os) throws IOException {
62-
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
63-
Graphics graphics = image.getGraphics();
64-
fillBackground(graphics, width, height);
65-
String randomStr = RandomUtils.randomString(VALICATE_CODE_LENGTH);
66-
createCharacter(graphics, randomStr);
67-
graphics.dispose();
68-
//设置JPEG格式
69-
ImageIO.write(image, "JPEG", os);
70-
return randomStr;
62+
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
63+
Graphics graphics = image.getGraphics();
64+
fillBackground(graphics, width, height);
65+
String randomStr = RandomUtils.randomString(VALICATE_CODE_LENGTH);
66+
createCharacter(graphics, randomStr);
67+
graphics.dispose();
68+
//设置JPEG格式
69+
ImageIO.write(image, "JPEG", os);
70+
return randomStr;
7171
}
7272

7373
/**
@@ -79,20 +79,20 @@ public String generate(int width, int height, OutputStream os) throws IOExceptio
7979
*/
8080
@Override
8181
public VerifyCode generate(int width, int height) {
82-
VerifyCode verifyCode = null;
83-
try (
84-
//将流的初始化放到这里就不需要手动关闭流
85-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
86-
) {
87-
String code = generate(width, height, baos);
88-
verifyCode = new VerifyCode();
89-
verifyCode.setCode(code);
90-
verifyCode.setImgBytes(baos.toByteArray());
91-
} catch (IOException e) {
92-
logger.error(e.getMessage(), e);
93-
verifyCode = null;
94-
}
95-
return verifyCode;
82+
VerifyCode verifyCode = null;
83+
try (
84+
//将流的初始化放到这里就不需要手动关闭流
85+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
86+
) {
87+
String code = generate(width, height, baos);
88+
verifyCode = new VerifyCode();
89+
verifyCode.setCode(code);
90+
verifyCode.setImgBytes(baos.toByteArray());
91+
} catch (IOException e) {
92+
logger.error(e.getMessage(), e);
93+
verifyCode = null;
94+
}
95+
return verifyCode;
9696
}
9797

9898
/**
@@ -102,15 +102,15 @@ public VerifyCode generate(int width, int height) {
102102
* @param randomStr
103103
*/
104104
private void createCharacter(Graphics g, String randomStr) {
105-
char[] charArray = randomStr.toCharArray();
106-
for (int i = 0; i < charArray.length; i++) {
107-
//设置RGB颜色算法参数
108-
g.setColor(new Color(50 + RandomUtils.nextInt(100),
109-
50 + RandomUtils.nextInt(100), 50 + RandomUtils.nextInt(100)));
110-
//设置字体大小,类型
111-
g.setFont(new Font(FONT_TYPES[RandomUtils.nextInt(FONT_TYPES.length)], Font.BOLD, 26));
112-
//设置x y 坐标
113-
g.drawString(String.valueOf(charArray[i]), 15 * i + 5, 19 + RandomUtils.nextInt(8));
114-
}
115-
}
105+
char[] charArray = randomStr.toCharArray();
106+
for (int i = 0; i < charArray.length; i++) {
107+
//设置RGB颜色算法参数
108+
g.setColor(new Color(50 + RandomUtils.nextInt(100),
109+
50 + RandomUtils.nextInt(100), 50 + RandomUtils.nextInt(100)));
110+
//设置字体大小,类型
111+
g.setFont(new Font(FONT_TYPES[RandomUtils.nextInt(FONT_TYPES.length)], Font.BOLD, 26));
112+
//设置x y 坐标
113+
g.drawString(String.valueOf(charArray[i]), 15 * i + 5, 19 + RandomUtils.nextInt(8));
114+
}
115+
}
116116
}

0 commit comments

Comments
 (0)