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

重庆信息门户网站字体设计转换器

重庆信息门户网站,字体设计转换器,云南省,wordpress 图文插件前后端分离 一般来说#xff0c;我们用SpringSecurity默认的话是前后端整在一起的#xff0c;比如thymeleaf或者Freemarker#xff0c;SpringSecurity还自带login登录页,还让你配置登出页,错误页。 但是现在前后端分离才是正道#xff0c;前后端分离的话#xff0c;那就…前后端分离 一般来说我们用SpringSecurity默认的话是前后端整在一起的比如thymeleaf或者FreemarkerSpringSecurity还自带login登录页,还让你配置登出页,错误页。 但是现在前后端分离才是正道前后端分离的话那就需要将返回的页面换成Json格式交给前端处理了 SpringSecurity默认的是采用Session来判断请求的用户是否登录的但是不方便分布式的扩展虽然SpringSecurity也支持采用SpringSession来管理分布式下的用户状态不过现在分布式的还是无状态的Jwt比较主流。 所以怎么让SpringSecurity变成前后端分离可以采用Jwt来做认证 什么是jwt Json web token (JWT)是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC7519).该token被设计为紧凑且安全的特别适用于分布式站点的单点登录(SSO)场景。JWT的声明一般被用来在身份提供者和服务提供者间传递被认证的用户身份信息以便于从资源服务器获取资源也可以增加一些额外的其它业务逻辑所必须的声明信息该token也可直接被用于认证也可被加密。 官网: JSON Web Token Introduction - jwt.io jwt的结构 以 . 分割   三部分  Header Header 部分是一个JSON对象描述JWT的元数据通常是下面的样子。 {alg: HS256,typ: JWT} 上面代码中alg属性表示签名的算法(algorithm)默认是 HMAC SHA256 (写成 HS256) ;typ属性表示这个令牌(token)的类型(type), JWT令牌统一写为JWT。 最后将上面的JSON对象使用Base64URL算法转成字符串。 Payload载荷 Payload 部分也是一个JSON对象用来存放实际需要传递的数据。JWT规定了7个官方字段供选用。 iss (issuer):签发人 exp (expiration time):过期时间 sub (subject):主题 aud (audience):受众 nbf (Not Before):生效时间 iat (lssued At):签发时间 jti (JWT ID):编号 除了官方字段你还可以在这个部分定义私有字段下面就是一个例子。 {sub: 1234567890,name : John Doe,“userid”:2admin: true} 注意JWT 默认是不加密的任何人都可以读到所以不要把秘密信息放在这个部分。这个JSON 对象也要使用Base64URL 算法转成字符串。 Signature Signature部分是对前两部分的签名防止数据篡改。 首先需要指定一个密钥(secret)。这个密钥只有服务器才知道不能泄露给用户。然后使用Header里面指定的签名算法(默认是 HMAC SHA256)按照下面的公式产生签名。 HMACSHA256(base64UrlEncode(header) .”base64UrlEncode(payload),secret) 算出签名以后把 Header、Payload、Signature 三个部分拼成一个字符串每个部分之间用点(.)分隔就可以返回给用户。 1.项目添加hutool依赖 dependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion5.8.18/version/dependency http://t.csdnimg.cn/TA0Xx基于文章中连接数据库的实例基础上进行的前后端分离设计 2.搭建好一个vue项目 所需的导入包 3.修改配置文件 main.js 全局导入引入 import Vue from vue import App from ./App.vue import router from ./routerVue.config.productionTip falseimport ElementUI from element-ui; import element-ui/lib/theme-chalk/index.css;Vue.use(ElementUI); import axios from axios // 后端项目的时候 http://localhost:8080 // axios设置一个默认的路径 // 创建实例时配置默认值 const instance axios.create({// 访问路径的时候假的一个基础的路径baseURL: http://localhost:8080/,// withCredentials: true }); 请求拦截器与响应拦截器 // 请求拦截器 // instance.interceptors.request.use( config {// config 前端 访问后端的时候 参数// 如果sessionStorage里面于token 携带着token 过去if(sessionStorage.getItem(token)){// token的值 放到请求头里面let token sessionStorage.getItem(token);config.headers[token]token;}// config.headers[Authorization]yylreturn config; }, error {// 超出 2xx 范围的状态码都会触发该函数。// 对响应错误做点什么return Promise.reject(error); });// 添加响应拦截器 instance.interceptors.response.use( response {console.log(response)// 状态码 500if(response.data.code!200){alert(chucuole)console.log(response.data);router.push({path:/login});return;}return response; }, error {// 超出 2xx 范围的状态码都会触发该函数。// 对响应错误做点什么return Promise.reject(error); });Vue.prototype.$axios instance; // 引入组件 挂载点 new Vue({router,render: h h(App) }).$mount(#app) 4.搭建一个.vue页面并在 router 目录下的 index.js 文件配置好路由 templatediv classlogin-containerel-form :modelruleForm status-icon :rulesrules refruleForm label-width100px classlogin-formel-form-item label用户名 propusernameel-input typetext v-modelruleForm.username autocompleteoff/el-input/el-form-itemel-form-item label确认密码 proppasswordel-input typepassword v-modelruleForm.password autocompleteoff/el-input/el-form-itemel-form-itemel-button typeprimary clicksubmitForm(ruleForm)提交/el-buttonel-button clickresetForm(ruleForm)重置/el-button/el-form-item/el-form/div /template 搭建的页面包含基本的登录表单在新建一个页面用于成功的页面展示如 图中跳转的main.vue methods: {submitForm(formName) {this.$refs[formName].validate((valid) {if (valid) {alert(submit!);// 请求 userlogin userlogin//post i请求 json 数据 后端接受的时候 RequestBodythis.$axios.post(userlogin,qs.stringify(this.ruleForm)).then(r{// 获取token的值console.log(r.data.t);// 存起来sessionStorage.setItem(token,r.data.t)// 成功之后 跳转 /mainthis.$router.push(/main);//console.log(r.data);})} else {console.log(error submit!!);return false;}});},} import Vue from vue import VueRouter from vue-router import HomeView from ../views/HomeView.vueVue.use(VueRouter)const routes [{path: /,name: home,component: HomeView},{path: /login,name: login,component: () import(/* webpackChunkName: about */ ../views/login.vue)},{path: /about,name: about,// route level code-splitting// this generates a separate chunk (about.[hash].js) for this route// which is lazy-loaded when the route is visited.component: () import(/* webpackChunkName: about */ ../views/AboutView.vue)},{path: /main,name: main,component: () import(/* webpackChunkName: about */ ../views/main.vue)}, ] // 针对ElementUI导航栏中重复导航报错问题 const originalPush VueRouter.prototype.push VueRouter.prototype.push function push(location) {return originalPush.call(this, location).catch(err err) } 这里配置了导航重复导航的问题我们在响应拦截器配置了code非200的跳转登录的情况为了避免登录失败导致跳转登录页面重复导航的问题 5.后端加入跨域的配置文件 import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter;Configuration public class CrossConfig {Beanpublic CorsFilter corsFilter() {final UrlBasedCorsConfigurationSource source new UrlBasedCorsConfigurationSource();final CorsConfiguration corsConfiguration new CorsConfiguration();//corsConfiguration.setAllowCredentials(true); // 允许 携带cookie 的信息corsConfiguration.addAllowedHeader(*); // 允许所有的头corsConfiguration.addAllowedOrigin(*);// 允许所有的请求源corsConfiguration.addAllowedMethod(*); // 所欲的方法 get post delete putsource.registerCorsConfiguration(/**, corsConfiguration); // 所有的路径都允许跨域return new CorsFilter(source);}} 6.统一返回数据实体 Data AllArgsConstructor // NoArgsConstructor // public class ResultT {/*** code编码*/private Integer code 200;/*** 消息*/private String msg 操作成功;/*** 具体的数据*/private T t;/*** 成功的静态方法*/public static T Result success(T t){return new Result(200,操作成功,t);}public static T Result T fail(){return new Result(500,操作失败,null);}public static T Result T forbidden(){return new Result(403,权限不允许,null);} } 7.对实现了UserDetailsService接口的service层进行了修改 Service public class MyUserDetailService implements UserDetailsService {Resourceprivate TabUserMapper userMapper;Resourceprivate TabUserRoleMapper userRoleMapper;Resourceprivate TabRoleMapper roleMapper;Resourceprivate TabMenuMapper menuMapper;// 根据用户的名字 加载用户的信息Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { // username 代表前端传递过来的名字 // 根据名字去数据库查询一下有没有这个用户的信息QueryWrapper queryWrapper new QueryWrapper();queryWrapper.eq(username,username);TabUser tabUser userMapper.selectOne(queryWrapper);if(tabUser ! null) { // 有值 查询用户对应的角色的idQueryWrapper queryWrapper1 new QueryWrapper();queryWrapper1.eq(uid,tabUser.getId());ListTabUserRole tabUserRoles userRoleMapper.selectList(queryWrapper1);ListInteger rids tabUserRoles.stream().map(tabUserRole - tabUserRole.getRid()).collect(Collectors.toList()); // 根据角色的id 查询rcodeListTabRole tabRoles roleMapper.selectBatchIds(rids); // 角色的修信息 角色管理 修改角色的名字ListSimpleGrantedAuthority collect tabRoles.stream().map(tabRole - new SimpleGrantedAuthority(ROLE_ tabRole.getRcode())).collect(Collectors.toList()); // 根据角色的id 查询菜单的mcodeListTabMenu menus menuMapper.selectCodeByRids(rids);ListSimpleGrantedAuthority resources menus.stream().map(tabMenu - new SimpleGrantedAuthority(tabMenu.getMcode())).collect(Collectors.toList()); // 将角色的所有信息,和资源信息合并在一起ListSimpleGrantedAuthority allresource Stream.concat(collect.stream(), resources.stream()).collect(Collectors.toList());return new User(username, tabUser.getPassword(), allresource);}return null;} } 8.数据链路层对前后端的认证进行判断与返回的JSON数据 Component public class JwtFilter extends OncePerRequestFilter {Overrideprotected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {/*解析token1.获取token - 存在 - 解析不存在返回 null 没有认证2.效验token真的还是假的 真- 过 - 用户的信息存放到安全框架的上下文路径里面假- 返回一个Json 数据 没有认证* */String[] whitename {/userlogin};String token request.getHeader(token); // token存在if(StringUtils.isNotBlank(token)) { // 存在 解析boolean verify JWTUtil.verify(token, hp.getBytes());if(verify) { // 效验合格 // 获取用户的名字 和密码的信息JWT jwt JWTUtil.parseToken(token);String username (String) jwt.getPayload(username);ListString resources (ListString) jwt.getPayload(resources); // 资源的信息ListSimpleGrantedAuthority collect resources.stream().map(s - new SimpleGrantedAuthority(s)).collect(Collectors.toList()); // 保存用户的信息UsernamePasswordAuthenticationToken usertoken new UsernamePasswordAuthenticationToken(username, null, collect); // 存起来用户的信息SecurityContextHolder.getContext().setAuthentication(usertoken); // 放行filterChain.doFilter(request,response);}else {Result result new Result(401, 没有登录, null);printJsonData(response,result);}}else { // 查看是否在白名单 如果在 就放行String requestURL request.getRequestURI();if(ArrayUtils.contains(whitename,requestURL)) {filterChain.doFilter(request,response);}else {Result result new Result(401, 没有登录, null);printJsonData(response,result);}}}public void printJsonData(HttpServletResponse response, Result result) {try {response.setContentType(application/json;charsetutf8); //json格式 编码是中文ObjectMapper objectMapper new ObjectMapper();String s objectMapper.writeValueAsString(result);// 使用objectMapper将result转化为json字符串PrintWriter writer response.getWriter();writer.print(s);writer.flush();writer.close();}catch (Exception e) {e.printStackTrace();}} } 9.对config文件进行修改(前后端分离情况) Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter {Resourceprivate JwtFilter jwtFilter;Overrideprotected void configure(HttpSecurity http) throws Exception {// 配置 登录form 表单 // 路劲前面必须加 /http.formLogin().loginProcessingUrl(/userlogin).successHandler((request, response, authentication) - {System.out.println(authenticationauthentication); // 资源的信息Collection? extends GrantedAuthority authorities authentication.getAuthorities();ListString allresources authorities.stream().map(s - s.getAuthority()).collect(Collectors.toList());System.out.println(allresourcesallresources); // 认证成功 // 生成tokenMap map new HashMap();map.put(username,authentication.getName()); // 认证成功之后 用户的名字map.put(resources,allresources); // 资源的信息设置签发时间 // Calendar instance Calendar.getInstance(); //获取当前的时间 // Date time instance.getTime();过期的时间设置为2小时之后 // instance.add(Calendar.HOUR,2); //两个小时之后 // Date time1 instance.getTime(); // map.put(JWTPayload.EXPIRES_AT,time1); // map.put(JWTPayload.ISSUED_AT,time); // map.put(JWTPayload.NOT_BEFORE,time);String token JWTUtil.createToken(map, hp.getBytes());System.out.println(token);Result result new Result(200,登录成功,token);printJsonData(response,result);}) //前后端分离的时候 认证成功 走的方法.failureHandler((request, response, exception) - {Result result new Result(500, 失败, null);printJsonData(response,result);}); //认证失败 走的方法http.authorizeRequests().antMatchers(/userlogin).permitAll(); //代表放行 /userloginhttp.authorizeRequests().anyRequest().authenticated(); // 权限不允许的时候http.exceptionHandling().accessDeniedHandler((request, response, accessDeniedException) - {Result result new Result(403, 权限不允许, null);printJsonData(response,result);});http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class); // csrf 方便html文件 能够通过http.csrf().disable();http.cors(); // 可以跨域}Resourceprivate UserDetailsService userDetailsService;Beanpublic PasswordEncoder getPassword() {return new BCryptPasswordEncoder();}// 自定义用户的信息Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.userDetailsService(userDetailsService).passwordEncoder(getPassword());}public void printJsonData(HttpServletResponse response, Result result) {try {response.setContentType(application/json;charsetutf8);ObjectMapper objectMapper new ObjectMapper();String s objectMapper.writeValueAsString(result);PrintWriter writer response.getWriter();writer.print(s);writer.flush();writer.close();}catch (Exception e) {e.printStackTrace();}} } 10.配置完成
文章转载自:
http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn
http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn
http://www.morning.xknmn.cn.gov.cn.xknmn.cn
http://www.morning.wdqhg.cn.gov.cn.wdqhg.cn
http://www.morning.ntgjm.cn.gov.cn.ntgjm.cn
http://www.morning.yrpg.cn.gov.cn.yrpg.cn
http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn
http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn
http://www.morning.mhnrx.cn.gov.cn.mhnrx.cn
http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn
http://www.morning.ypdmr.cn.gov.cn.ypdmr.cn
http://www.morning.srkzd.cn.gov.cn.srkzd.cn
http://www.morning.tbjb.cn.gov.cn.tbjb.cn
http://www.morning.gl-group.cn.gov.cn.gl-group.cn
http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn
http://www.morning.qttft.cn.gov.cn.qttft.cn
http://www.morning.mzgq.cn.gov.cn.mzgq.cn
http://www.morning.jwxnr.cn.gov.cn.jwxnr.cn
http://www.morning.qjxxc.cn.gov.cn.qjxxc.cn
http://www.morning.xsklp.cn.gov.cn.xsklp.cn
http://www.morning.qbtkg.cn.gov.cn.qbtkg.cn
http://www.morning.sgqw.cn.gov.cn.sgqw.cn
http://www.morning.zqzzn.cn.gov.cn.zqzzn.cn
http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn
http://www.morning.xinxianzhi005.com.gov.cn.xinxianzhi005.com
http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn
http://www.morning.dqzcf.cn.gov.cn.dqzcf.cn
http://www.morning.prsxj.cn.gov.cn.prsxj.cn
http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn
http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn
http://www.morning.lmyq.cn.gov.cn.lmyq.cn
http://www.morning.hlhqs.cn.gov.cn.hlhqs.cn
http://www.morning.drywd.cn.gov.cn.drywd.cn
http://www.morning.nrcbx.cn.gov.cn.nrcbx.cn
http://www.morning.rdtq.cn.gov.cn.rdtq.cn
http://www.morning.ndtzy.cn.gov.cn.ndtzy.cn
http://www.morning.frsxt.cn.gov.cn.frsxt.cn
http://www.morning.c7491.cn.gov.cn.c7491.cn
http://www.morning.xsjfk.cn.gov.cn.xsjfk.cn
http://www.morning.ygth.cn.gov.cn.ygth.cn
http://www.morning.dqrhz.cn.gov.cn.dqrhz.cn
http://www.morning.wdykx.cn.gov.cn.wdykx.cn
http://www.morning.qmnhw.cn.gov.cn.qmnhw.cn
http://www.morning.rsnn.cn.gov.cn.rsnn.cn
http://www.morning.wrysm.cn.gov.cn.wrysm.cn
http://www.morning.cmzcp.cn.gov.cn.cmzcp.cn
http://www.morning.c7512.cn.gov.cn.c7512.cn
http://www.morning.ryrgx.cn.gov.cn.ryrgx.cn
http://www.morning.syhwc.cn.gov.cn.syhwc.cn
http://www.morning.lstmg.cn.gov.cn.lstmg.cn
http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn
http://www.morning.wknbc.cn.gov.cn.wknbc.cn
http://www.morning.flzqq.cn.gov.cn.flzqq.cn
http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn
http://www.morning.sfwfk.cn.gov.cn.sfwfk.cn
http://www.morning.qxltp.cn.gov.cn.qxltp.cn
http://www.morning.ybnzn.cn.gov.cn.ybnzn.cn
http://www.morning.jbfjp.cn.gov.cn.jbfjp.cn
http://www.morning.rpzqk.cn.gov.cn.rpzqk.cn
http://www.morning.jbxd.cn.gov.cn.jbxd.cn
http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn
http://www.morning.wyzby.cn.gov.cn.wyzby.cn
http://www.morning.lbggk.cn.gov.cn.lbggk.cn
http://www.morning.fqsxf.cn.gov.cn.fqsxf.cn
http://www.morning.xgjhy.cn.gov.cn.xgjhy.cn
http://www.morning.dplmq.cn.gov.cn.dplmq.cn
http://www.morning.qwbtr.cn.gov.cn.qwbtr.cn
http://www.morning.ndpwg.cn.gov.cn.ndpwg.cn
http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn
http://www.morning.qfwzm.cn.gov.cn.qfwzm.cn
http://www.morning.cjmmt.cn.gov.cn.cjmmt.cn
http://www.morning.qcrhb.cn.gov.cn.qcrhb.cn
http://www.morning.rkck.cn.gov.cn.rkck.cn
http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn
http://www.morning.gbqgr.cn.gov.cn.gbqgr.cn
http://www.morning.bhxzx.cn.gov.cn.bhxzx.cn
http://www.morning.ndfwh.cn.gov.cn.ndfwh.cn
http://www.morning.nkmw.cn.gov.cn.nkmw.cn
http://www.morning.qllcp.cn.gov.cn.qllcp.cn
http://www.morning.fhghy.cn.gov.cn.fhghy.cn
http://www.tj-hxxt.cn/news/254983.html

相关文章:

  • 分析网站建设前期的seo准备工作湖北专业网站建设耗材
  • wordpress建站linux网站开发环境ide
  • seo网站推广的目的包括哪个方面建立网站要怎么做
  • 凡科建站官网电脑版杭州市建设银行网站
  • 成都模板网建站中山那些网站公司
  • jsp怎样做网站网站建设的一些背景图片
  • 咖啡网站设计模板seo扣费系统源码
  • 画室网站模板wordpress 获取指定文章标题
  • 贷款类网站怎样做wordpress反向代理
  • 包头做网站的公司招聘信息全媒体广告加盟
  • 网站开发公司架构自学做视频网站
  • 中国住房和城乡建设厅网站怀化seo优化
  • 河北省住房城乡建设网站域名信息
  • 那些网站是asp做的网站建设公司成就
  • 网站优化方案案例器材管理网站开发
  • 建设自己的淘宝优惠券网站在微信上怎么开店
  • sql注入网站源码wordpress 减少head
  • 网站换模板.net 手机网站开发
  • 网站开发视频教程百度网盘一个公司做两个网站可以吗
  • 能够做代理的网站有哪些问题免费商标图案设计logo
  • 二级域名解析网站wordpress模板制作兼职
  • 帝国cms手机网站上海网站建设公司 红威
  • 营销型网站建设步骤网站建设支付接口
  • 企业怎么建设自己的网站招商加盟项目推荐
  • 网站公司怎么做的好长春开发公司
  • 国外手机网站模板用discuz做的网站
  • 搭建网站多少钱wordpress网站设置关键词设置
  • 商城网站建设定制企业注册登记流程
  • 国内有做外汇的正规网站吗长春启做网站多少
  • 手机高端网站开发网页浏览器大全