那些被若依登录搞崩溃的人

编程入门 行业动态 更新时间:2024-10-23 04:51:13

那些被若依登录搞崩溃<a href=https://www.elefans.com/category/jswz/34/1769694.html style=的人"/>

那些被若依登录搞崩溃的人

这里呢,我就介绍两种登录若依的方法(前提是在不运行前端页面的情况下)
1.postman进行登录
2.swagger进行登录
首先我们先来看看postman如何进行登录吧
在若依的登录接口中我们可以看到,有一个入参

    /*** 登录方法** @param loginBody 登录信息* @return 结果*/@PostMapping(value = "/login", produces = "application/json")@ApiOperation(value = "登录接口", tags = {"登录账号密码四个参数"}, notes = "登录")public AjaxResult login(@RequestBody LoginBody loginBody) {AjaxResult ajax = AjaxResult.success();// 生成令牌String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),loginBody.getUuid());ajax.put(Constants.TOKEN, token);return ajax;}

入参的实体类又是这样的呢

package com.aidexmon.core.domain.model;/*** 用户登录对象* * @author ruoyi*/
public class LoginBody
{/*** 用户名*/private String username;/*** 用户密码*/private String password;/*** 验证码*/private String code;/*** 唯一标识*/private String uuid;public String getUsername(){return username;}public void setUsername(String username){this.username = username;}public String getPassword(){return password;}public void setPassword(String password){this.password = password;}public String getCode(){return code;}public void setCode(String code){this.code = code;}public String getUuid(){return uuid;}public void setUuid(String uuid){this.uuid = uuid;}
}

这样我们就可以看到,requestBody是有四个属性的,那么大家在玩儿若依进行测试接口的时间有没有发现登录不进去呢?因为一般情况下正常人的反应是不是账号,密码登录,但是在这里呢,他又多了两个参数,就是验证码,当然你也可以去掉若依的这个验证方式,如果不去掉的话,你就需要去拿到这个图片了,然后进行验证,我沉思很久,他肯定有这样的一个接口,因为从若依给的页面展示上是有的,如图若依案例:

于是我就开始去寻找这个接口啦,最终功夫不负有心人,让我找到了,如下:

package com.aidex.web.controllermon;import com.aidexmon.config.AiDexConfig;
import com.aidexmon.constant.Constants;
import com.aidexmon.core.domain.AjaxResult;
import com.aidexmon.core.redis.RedisCache;
import com.aidexmon.utils.sign.Base64;
import com.aidexmon.utils.uuid.IdUtils;
import com.aidex.framework.cache.ConfigUtils;
import com.google.code.kaptcha.Producer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;/*** 验证码操作处理* * @author ruoyi*/
@RestController
@Api(value = "CaptchaController", tags = {"显示图片信息"})
public class CaptchaController
{@Resource(name = "captchaProducer")private Producer captchaProducer;@Resource(name = "captchaProducerMath")private Producer captchaProducerMath;@Autowiredprivate RedisCache redisCache;@Autowired(required = false)private AiDexConfig aidexConfig;/*** 生成验证码*/@GetMapping("/captchaImage")@ApiOperation(value = "获取二维码图片", tags = {"传入值type的math"}, notes = "获取图片",produces = "application/json")public AjaxResult getCode(HttpServletResponse response) throws IOException{AjaxResult ajax = AjaxResult.success();boolean captchaOnOff = ConfigUtils.getConfigBooleanValueByKey("sys.captcha.onOff",true);ajax.put("captchaOnOff", captchaOnOff);if (!captchaOnOff){return ajax;}try {// 保存验证码信息String uuid = IdUtils.simpleUUID();String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;String capStr = null, code = null;BufferedImage image = null;// 生成验证码String captchaType = aidexConfig.getCaptchaType();// 生成验证码if ("math".equals(captchaType)){String capText = captchaProducerMath.createText();capStr = capText.substring(0, capText.lastIndexOf('@'));code = capText.substring(capText.lastIndexOf('@') + 1);image = captchaProducerMath.createImage(capStr);}else if ("char".equals(captchaType)){capStr = code = captchaProducer.createText();image = captchaProducer.createImage(capStr);}redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);// 转换流信息写出FastByteArrayOutputStream os = new FastByteArrayOutputStream();try{ImageIO.write(image, "jpg", os);}catch (IOException e){e.printStackTrace();return AjaxResult.error(e.getMessage());}ajax = AjaxResult.success();ajax.put("uuid", uuid);ajax.put("img", Base64.encode(os.toByteArray()));} catch (Exception e) {e.printStackTrace();}return ajax;}
}

从结果可以得知他会返回两个值:uuid和img,这个时间呢我们是可以得到uuid啦,但是我们又少了一样东西,那code去哪里找呢?

//这里的这句话就是存入了redis中啦
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);

这个时间你就直接可以去redis中去寻找它了
redis配置是在

这样你就可以获取值和uuid啦 账号密码数据库中有,可以自行查看,若依默认账号,密码为admin—>admin123
具体操作
(1)

(2).点开你的redis可视化工具里边你就可以找到值了
(3)

(4).你在进行访问其他接口的时间只需要加上他就可以啦
Authorization(这个是key),value你自己获取的

OK.说到这里第一种方式就已经结束啦
接下来我会向大家述说第二种方式
在若依的依赖池中我们可以看到swagger这个依赖,配置类中也进行了配置,所以有的可能就习惯用swagger
首先我们直接访问http://localhost:8080/swagger-ui/index.html,这个路径进入swagger页面,这个访问路径是swagger3的和2的不是一样的2的是http://localhost:8080/swagger-ui.html#/,你们可以自己去改依赖


1.第一步先获取图片的结果值,以及uuid
2.进行登录
3.如果想要进行其他的访问的接口,需要把刚刚获取的token写进去
(1)

(2)放入token值

这种情况下token就会有了,然后你想访问哪个接口都是可以的啦,OK今日分享到此结束,我们下次再见,嘻嘻

更多推荐

那些被若依登录搞崩溃的人

本文发布于:2024-02-17 13:32:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1694185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:的人   被若依

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!