当前位置: 首页 > news >正文

买了winhost网站空间在哪里登陆seo科技网

买了winhost网站空间在哪里登陆,seo科技网,php网站修改代码,做瞹免费视频网站在项目中,前后端分离的若依项目,需要通过统一认证,或者是第三方协带认证信息跳转到本系统的指定页面。需要前后端都做相应的改造,由于第一次实现时已过了很久,再次重写时,发现还是搞了很长时间,…

在项目中,前后端分离的若依项目,需要通过统一认证,或者是第三方协带认证信息跳转到本系统的指定页面。需要前后端都做相应的改造,由于第一次实现时已过了很久,再次重写时,发现还是搞了很长时间,所以花点时间整理出事,也方便给大家参考。

首先明确需要处理几个部分:

一、后端的处理

       1、 在控制器层,SysLoginController  中,原有的login方法之后,写一个登录的方法,注意其中的 loginService.logingcy(userId); 这个是下一步要实现的。通过第三方协议解析出用户的信息,可能 是工号,或者是微信的openid这都无所谓,反正通过他你能找到本系统的用户就可以了。

 @GetMapping("/logingcy")public AjaxResult logingcy(String ssouser){AjaxResult ajax = AjaxResult.success();try {//通过中间的协议解析出用户的基本信息String[] userInfo = JasmineSsoUtil.getUserInfo(ssouser, Constants.SSODOMAIN, Constants.SSOKEY);String userId = userInfo[0];//以下为获取此员工的待办工单数量,并按要求返回值System.out.println("useris "+userId);String token =   loginService.logingcy(userId);ajax.put(Constants.TOKEN, token);return ajax;} catch (Exception e) {e.printStackTrace();}return AjaxResult.error();// 生成令牌}

2、在登录服务中增加一个和原来登录对应的方法 SysLoginService   loginService.logingcy(userId);

/*通过工程翼用户登录*/public String logingcy(String username){// 用户验证Authentication authentication = null;SysUser sysUser = userService.selectUserByUserName(username);System.out.println("admin  staffcode is "+ username +" and password is "+sysUser.getPassword());try{//已经确认解析出用户信息,所以这里使用一个内部的特定密码和模拟密码进行检验userDetailsService.loadUserByUsername(username);UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, Constants.CPASSWORD);//AuthenticationContextHolder.setContext(token);// 该方法会去调用UserDetailsServiceImpl.loadUserByUsernameauthentication = authenticationManager.authenticate(token);}catch (Exception e){if (e instanceof BadCredentialsException){AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));throw new UserPasswordNotMatchException();}else{AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));throw new ServiceException(e.getMessage());}}finally{//  AuthenticationContextHolder.clearContext();}AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));LoginUser loginUser = (LoginUser) authentication.getPrincipal();// 生成tokenreturn tokenService.createToken(loginUser);}

3、增加一个 SecurityProvider 用于密码和校检

具体的代码如下:

package com.ruoyi.framework.security.provider;import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import org.apache.poi.hssf.record.DVALRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;/*** 自定义认证服务* */
@Service("securityProvider")
public class SecurityProvider implements AuthenticationProvider {@Autowiredprivate BCryptPasswordEncoder bCryptPasswordEncoder;@Autowiredprivate UserDetailsService userDetailsService;@Autowiredprivate ISysUserService userService;public SecurityProvider(UserDetailsService userDetailsService) {this.userDetailsService = userDetailsService;}@Overridepublic Authentication authenticate(Authentication authentication) throws AuthenticationException {/*   UsernamePasswordAuthenticationToken token= (UsernamePasswordAuthenticationToken) authentication;*/String name = authentication.getName();String password = (String) authentication.getCredentials();System.out.println("name:"+name+"password:"+password);//这里直接判断异常UserDetails user = userDetailsService.loadUserByUsername(name);String encoderPassword = bCryptPasswordEncoder.encode(password);SysUser user1 = userService.selectUserByUserName("admin");user1.setPassword(SecurityUtils.encryptPassword("admin123"));userService.updateUser(user1);System.out.println("1password is "+    SecurityUtils.encryptPassword(password));System.out.println("2password is"+encoderPassword);System.out.println("user passwordis "+user.getPassword());// 数据库账号密码的校验能通过就通过if (SecurityUtils.matchesPassword(password, user.getPassword())){//  if (bCryptPasswordEncoder.matches(password, user.getPassword())) {// log.info("使用账户密码登录");return new UsernamePasswordAuthenticationToken(user, encoderPassword);}//这里是第三方登录的使用方式,用一个内部的密码代替了password的位置// log.info(""+checkValid);if(Constants.CPASSWORD.equalsIgnoreCase(password)){return new UsernamePasswordAuthenticationToken(user, password);} else {// 如果都登录不了,就返回异常输出throw new UserPasswordNotMatchException();}}@Overridepublic boolean supports(Class<?> authentication) {//返回true后才会执行上面的authenticate方法,这步能确保authentication能正确转换类型return  true;}}

4、修改配置文件  SecurityConfig 有两处需要修改,一个是最下面,使用上一步定义的SecurityProvider

一个是上面,允许前端的新登录页面可以直接访问

到此,后端部分的改造就完成了。

二、前端页面

1、首先要做一个登录过度页面,内容可以为空白,只需要接收地址栏中的参数,并且调用上面第一步中定义的方法

2、在路由中配置路径对应访问的这个页面

3、设置白名单,可以直接访问页面

4、在原来的login.js中写入后台对应的地址,这里注意需要先logou一下,防止重复登录报错

export function logingcy(ssouser) {logout();return request({url: '/logingcy?ssouser=' + ssouser,method: 'get',})
}

5、在user.js中增加一个action,这里需要写入token是关键,不然后台一直报未登录

http://www.hkea.cn/news/948994/

相关文章:

  • 怎么用文本做网站百度排行榜风云榜
  • 未来网站开发需求多搜索网站有哪几个
  • 网站建设 成都郑州高端网站制作
  • 快站怎么做淘客网站深圳关键词
  • 做网站时如何去掉网站横条小红书软文案例
  • 图虫南宁百度快速排名优化
  • 上城网站建设app推广文案
  • 网站建设特点宁波seo搜索引擎优化公司
  • 地产商网站建设网球新闻最新消息
  • 做爰全过程网站免费的视频谷歌seo搜索引擎
  • 怎么架设网站seo推广培训
  • 自己网站做问卷调查网页设计学生作业模板
  • 清远企业网站排名深圳网站建设系统
  • 互助平台网站建设费用卡点视频免费制作软件
  • 上海做b2b国际网站公司排名优化公司电话
  • 裙晖wordpress重庆seo整站优化
  • 乌克兰网站后缀谷歌浏览器下载电脑版
  • 建设部网站撤销注册资质的都是公职人员吗正规网络公司关键词排名优化
  • 杂志网站建设推广方案铜川网络推广
  • 网站建设后怎么搜索引擎优化解释
  • 网站建设维护 天博网络成都营销型网站制作
  • 秦皇岛北京网站建设百度广告投放电话
  • 团购做的比较好的网站营销推广ppt
  • 网站怎么做网站地图重庆网站制作公司哪家好
  • wordpress改地址后打不开seo品牌优化整站优化
  • 网页设计师证书含金量高吗百度网络优化
  • 咸阳网站开发长沙seo优化公司
  • 网站通cms国内十大搜索引擎排名
  • centos7安装 wordpress网站如何进行seo
  • 设计师灵感网站美国今天刚刚发生的新闻