shaun框架的配置(如果你没有上面特殊的需要,按照我这样配就行了)

此处是基于spring boot的配置
Pom.xml
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>shaun-spring-boot-starter</artifactId>
    <version>1.1</version>
</dependency>



application.properties
#开启shaun
shaun.annotations.enabled=true
#32位字符串,不配置则每次启动不一样导致重启前登录的用户token失效,此处就好比令牌
shaun.salt=3mUyKhbICUow3ArhR2QAdPXJdDuiuygf
#默认时true,表示前后端分离
shaun.stateless=true
#默认是false,表示不用session
shaun.session-on=false
#默认header,token的存取位置,此处是header或者cookie或者paramter
shaun.token-location=header_or_cookie_or_parameter
shaun.header.name=token
shaun.cookie.name=token
shaun.parameter.name=token
#8760个小时
shaun.expire-time=8760h
#排除以此路径开头一定要排除登录,否则会报错
shaun.exclude-path=/erp/InventoryUser/userNameAndPassword
shaun.exclude-branch=/doc.html,/v2/api-docs,/webjars,/swagger-resources,/swagger-ui.html
#shaun.exclude-branch=/swagger-ui.html

controller层

 @Autowired
    private SecurityManager securityManager;
    
GetMappin("/login")
    public String login(String username, String password, HttpServletRequest request, HttpServletResponse response) {
        System.out.println(username + "数据" + password);
        final TokenProfile profile = new TokenProfile();
        if (username != null && password != null) {
            PasswordHelper passwordHelper = new PasswordHelper();
            TUser tUser = itUserService.selectUser(username, passwordHelper.encryptPassword(password));
            if (tUser != null) {
                if (!tUser.getDprtId().equals("")) {
                    try {
                        String dprtIds = itDepartmentService.getDprtChildList(Integer.toString(tUser.getDprtId()));
                        if(StringUtils.isEmpty(dprtIds)) {
                            dprtIds = "-1";
                        }
                        request.getSession().setAttribute("sysuserdeptids",dprtIds);
                    }catch (Exception e) {
                      /*  logger.error("error msg :",e);*/
                    }
//                    response.addHeader("token",tUser.getDprtId().toString());
                    profile.setId(tUser.getUserId().toString());
                    response.addHeader("token",securityManager.login(profile));
                    return "请求成功";
                }
            } else {
                return "请求失败";
            }
        }

        return "请求失败";
    }


    @GetMapping("/loginOut")
    public CommonResult loginOut() {
        TokenProfile profile = ProfileHolder.getProfile();
        securityManager.logout(profile);
       return CommonResult.sucess("成功");
    }


    @GetMapping("checkLogin")
    public CommonResult CheckLogin(){
        return CommonResult.sucess("成功");
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值