当前位置:   article > 正文

SpringSecurity + JWT,从入门到精通!

spring security+jwt流程详解
权限系统躲不开的概念,在Shiro和Spring Security之间,你一般选啥?在前后端分离的项目中,你知道怎么Spring security整合Jwt么,来看看这篇文章哈!

作者:小小____

https://segmentfault.com/a/1190000023052493

思维导图如下

RBAC 全称为基于角色的权限控制,本段将会从什么是 RBAC,模型分类,什么是权限,用户组的使用,实例分析等几个方面阐述 RBAC

思维导图

绘制思维导图如下

什么是 RBAC

RBAC 全称为用户角色权限控制,通过角色关联用户,角色关联权限,这种方式,间阶的赋予用户的权限,如下图所示

对于通常的系统而言,存在多个用户具有相同的权限,在分配的时候,要为指定的用户分配相关的权限,修改的时候也要依次的对这几个用户的权限进行修改,有了角色这个权限,在修改权限的时候,只需要对角色进行修改,就可以实现相关的权限的修改。这样做增加了效率,减少了权限漏洞的发生。

模型分类

对于 RBAC 模型来说,分为以下几个模型 分别是 RBAC0,RBAC1,RBAC2,RBAC3,这四个模型,这段将会依次介绍这四个模型,其中最常用的模型有 RBAC0.

RBAC0

RBAC0 是最简单的 RBAC 模型,这里面包含了两种。

用户和角色是多对一的关系,即一个用户只充当一种角色,一个角色可以有多个角色的担当。
用户和角色是多对多的关系,即,一个用户可以同时充当多个角色,一个角色可以有多个用户。
此系统功能单一,人员较少,这里举个栗子,张三既是行政,也负责财务,此时张三就有俩个权限,分别是行政权限,和财务权限两个部分。

RBAC1

相对于 RBAC0 模型来说,增加了子角色,引入了继承的概念。

RBAC2 模型

这里 RBAC2 模型,在 RBAC0 模型的基础上,增加了一些功能,以及限制

角色互斥

即,同一个用户不能拥有两个互斥的角色,举个例子,在财务系统中,一个用户不能拥有会计员和审计这两种角色。

基数约束

即,用一个角色,所拥有的成员是固定的,例如对于 CEO 这种角色,同一个角色,也只能有一个用户。

先决条件

即,对于该角色来说,如果想要获得更高的角色,需要先获取低一级别的角色。举个栗子,对于副总经理和经理这两个权限来说,需要先有副总经理权限,才能拥有经理权限,其中副总经理权限是经理权限的先决条件。

运行时互斥

即,一个用户可以拥有两个角色,但是这俩个角色不能同时使用,需要切换角色才能进入另外一个角色。举个栗子,对于总经理和专员这两个角色,系统只能在一段时间,拥有其一个角色,不能同时对这两种角色进行操作。

RBAC3 模型

即,RBAC1,RBAC2,两者模型全部累计,称为统一模型。

什么是权限

权限是资源的集合,这里的资源指的是软件中的所有的内容,即,对页面的操作权限,对页面的访问权限,对数据的增删查改的权限。举个栗子。对于下图中的系统而言,

拥有,计划管理,客户管理,合同管理,出入库通知单管理,粮食安全追溯,粮食统计查询,设备管理这几个页面,对这几个页面的访问,以及是否能够访问到菜单,都属于权限。

用户组的使用

对于用户组来说,是把众多的用户划分为一组,进行批量授予角色,即,批量授予权限。举个栗子,对于部门来说,一个部门拥有一万多个员工,这些员工都拥有相同的角色,如果没有用户组,可能需要一个个的授予相关的角色,在拥有了用户组以后,只需要,把这些用户全部划分为一组,然后对该组设置授予角色,就等同于对这些用户授予角色。

优点:减少工作量,便于理解,增加多级管理,等。

首先添加依赖

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-security</artifactId>
  4. </dependency>

然后添加相关的访问接口

  1. package com.example.demo.web;
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. @RestController
  5. @RequestMapping("/test")
  6. public class Test {
  7. @RequestMapping("/test")
  8. public String test(){
  9. return "test";
  10. }
  11. }
  12. 关注公众号:MarkerHub,回复[999]获取前后端入门教程,以及企业面试题!

最后启动项目,在日志中查看相关的密码

访问接口,可以看到相关的登录界面

输入用户名和相关的密码

  1. 用户名:user
  2. 密码 984cccf2-ba82-468e-a404-7d32123d0f9c

登录成功

增加用户名和密码

在配置文件中,书写相关的登录和密码

  1. spring:
  2. security:
  3. user:
  4. name: ming
  5. password: 123456
  6. roles: admin

在登录页面,输入用户名和密码,即可正常登录

基于内存的认证

需要自定义类继承 WebSecurityConfigurerAdapter 代码如下

  1. package com.example.demo.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  5. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  6. import org.springframework.security.crypto.password.NoOpPasswordEncoder;
  7. import org.springframework.security.crypto.password.PasswordEncoder;
  8. @Configuration
  9. public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {
  10. @Bean
  11. PasswordEncoder passwordEncoder(){
  12. return NoOpPasswordEncoder.getInstance();
  13. }
  14. @Override
  15. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  16. auth.inMemoryAuthentication()
  17. .withUser("admin").password("123").roles("admin");
  18. }
  19. }

即,配置的用户名为 admin,密码为 123,角色为 admin

HttpSecurity

这里对一些方法进行拦截

  1. package com.ming.demo.interceptor;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.http.HttpMethod;
  6. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  7. import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  8. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  9. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  10. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  11. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  12. import org.springframework.security.crypto.password.PasswordEncoder;
  13. import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
  14. @Configuration
  15. @EnableWebSecurity
  16. public class SecurityConfig extends WebSecurityConfigurerAdapter {
  17. @Override
  18. public void configure(AuthenticationManagerBuilder auth) throws Exception {
  19. auth.inMemoryAuthentication()
  20. .withUser("itguang").password("123456").roles("USER").and()
  21. .withUser("admin").password("{noop}" + "123456").roles("ADMIN");
  22. }
  23. @Override
  24. protected void configure(HttpSecurity http) throws Exception {
  25. http.authorizeRequests()
  26. .anyRequest().permitAll()
  27. .and()
  28. .formLogin()
  29. .permitAll()
  30. .and()
  31. .logout()
  32. .permitAll();
  33. }
  34. }

即,这里完成了对所有的方法访问的拦截。

这是一个小 demo,目的,登录以后返回 jwt 生成的 token

导入依赖

添加 web 依赖

导入 JWT 和 Security 依赖

  1. <dependency>
  2. <groupId>io.jsonwebtoken</groupId>
  3. <artifactId>jjwt</artifactId>
  4. <version>0.9.1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-security</artifactId>
  9. <version>2.3.1.RELEASE</version>
  10. </dependency>

创建一个 JwtUser 实现 UserDetails

创建 一个相关的 JavaBean

  1. package com.example.demo;
  2. import org.springframework.security.core.GrantedAuthority;
  3. import org.springframework.security.core.userdetails.UserDetails;
  4. import java.util.Collection;
  5. public class JwtUser implements UserDetails {
  6. private String username;
  7. private String password;
  8. private Integer state;
  9. private Collection<? extends GrantedAuthority> authorities;
  10. public JwtUser(){
  11. }
  12. public JwtUser(String username, String password, Integer state, Collection<? extends GrantedAuthority> authorities){
  13. this.username = username;
  14. this.password = password;
  15. this.state = state;
  16. this.authorities = authorities;
  17. }
  18. @Override
  19. public Collection<? extends GrantedAuthority> getAuthorities() {
  20. return authorities;
  21. }
  22. @Override
  23. public String getPassword() {
  24. return this.password;
  25. }
  26. @Override
  27. public String getUsername() {
  28. return this.username;
  29. }
  30. @Override
  31. public boolean isAccountNonExpired() {
  32. return true;
  33. }
  34. @Override
  35. public boolean isAccountNonLocked() {
  36. return true;
  37. }
  38. @Override
  39. public boolean isCredentialsNonExpired() {
  40. return true;
  41. }
  42. @Override
  43. public boolean isEnabled() {
  44. return true;
  45. }
  46. }

编写工具类生成令牌

编写工具类,用来生成 token,以及刷新 token,以及验证 token。关注公众号:MarkerHub,回复[999]获取前后端入门教程,以及企业面试题!

  1. package com.example.demo;
  2. import io.jsonwebtoken.Claims;
  3. import io.jsonwebtoken.Jwts;
  4. import io.jsonwebtoken.SignatureAlgorithm;
  5. import org.springframework.security.core.userdetails.UserDetails;
  6. import java.io.Serializable;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. public class JwtTokenUtil implements Serializable {
  11. private String secret;
  12. private Long expiration;
  13. private String header;
  14. private String generateToken(Map<String, Object> claims) {
  15. Date expirationDate = new Date(System.currentTimeMillis() + expiration);
  16. return Jwts.builder().setClaims(claims).setExpiration(expirationDate).signWith(SignatureAlgorithm.HS512, secret).compact();
  17. }
  18. private Claims getClaimsFromToken(String token) {
  19. Claims claims;
  20. try {
  21. claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
  22. } catch (Exception e) {
  23. claims = null;
  24. }
  25. return claims;
  26. }
  27. public String generateToken(UserDetails userDetails) {
  28. Map<String, Object> claims = new HashMap<>(2);
  29. claims.put("sub", userDetails.getUsername());
  30. claims.put("created", new Date());
  31. return generateToken(claims);
  32. }
  33. public String getUsernameFromToken(String token) {
  34. String username;
  35. try {
  36. Claims claims = getClaimsFromToken(token);
  37. username = claims.getSubject();
  38. } catch (Exception e) {
  39. username = null;
  40. }
  41. return username;
  42. }
  43. public Boolean isTokenExpired(String token) {
  44. try {
  45. Claims claims = getClaimsFromToken(token);
  46. Date expiration = claims.getExpiration();
  47. return expiration.before(new Date());
  48. } catch (Exception e) {
  49. return false;
  50. }
  51. }
  52. public String refreshToken(String token) {
  53. String refreshedToken;
  54. try {
  55. Claims claims = getClaimsFromToken(token);
  56. claims.put("created", new Date());
  57. refreshedToken = generateToken(claims);
  58. } catch (Exception e) {
  59. refreshedToken = null;
  60. }
  61. return refreshedToken;
  62. }
  63. public Boolean validateToken(String token, UserDetails userDetails) {
  64. JwtUser user = (JwtUser) userDetails;
  65. String username = getUsernameFromToken(token);
  66. return (username.equals(user.getUsername()) && !isTokenExpired(token));
  67. }
  68. }

编写拦截器

编写 Filter 用来检测 JWT

  1. package com.example.demo;
  2. import org.apache.commons.lang.StringUtils;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
  5. import org.springframework.security.core.context.SecurityContextHolder;
  6. import org.springframework.security.core.userdetails.UserDetails;
  7. import org.springframework.security.core.userdetails.UserDetailsService;
  8. import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
  9. import org.springframework.stereotype.Component;
  10. import org.springframework.web.filter.OncePerRequestFilter;
  11. import javax.servlet.FilterChain;
  12. import javax.servlet.ServletException;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import java.io.IOException;
  16. @Component
  17. public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
  18. @Autowired
  19. private UserDetailsService userDetailsService;
  20. @Autowired
  21. private JwtTokenUtil jwtTokenUtil;
  22. @Override
  23. protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
  24. String authHeader = httpServletRequest.getHeader(jwtTokenUtil.getHeader());
  25. if (authHeader != null && StringUtils.isNotEmpty(authHeader)) {
  26. String username = jwtTokenUtil.getUsernameFromToken(authHeader);
  27. if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
  28. UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
  29. if (jwtTokenUtil.validateToken(authHeader, userDetails)) {
  30. UsernamePasswordAuthenticationToken authentication =
  31. new UsernamePasswordAuthenticationToken(userDetails,null,userDetails.getAuthorities());
  32. authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
  33. SecurityContextHolder.getContext().setAuthentication(authentication);
  34. }
  35. }
  36. }
  37. filterChain.doFilter(httpServletRequest, httpServletResponse);
  38. }
  39. }

编写 userDetailsService 的实现类

在上方代码中,编写 userDetailsService,类,实现其验证过程

  1. package com.example.demo;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.security.core.authority.SimpleGrantedAuthority;
  4. import org.springframework.security.core.userdetails.User;
  5. import org.springframework.security.core.userdetails.UserDetails;
  6. import org.springframework.security.core.userdetails.UserDetailsService;
  7. import org.springframework.security.core.userdetails.UsernameNotFoundException;
  8. import org.springframework.stereotype.Service;
  9. import javax.management.relation.Role;
  10. import java.util.List;
  11. @Service
  12. public class JwtUserDetailsServiceImpl implements UserDetailsService {
  13. @Autowired
  14. private UserMapper userMapper;
  15. @Override
  16. public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
  17. User user = userMapper.selectByUserName(s);
  18. if (user == null) {
  19. throw new UsernameNotFoundException(String.format("'%s'.这个用户不存在", s));
  20. }
  21. List<SimpleGrantedAuthority> collect = user.getRoles().stream().map(Role::getRolename).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
  22. return new JwtUser(user.getUsername(), user.getPassword(), user.getState(), collect);
  23. }
  24. }

编写登录

编写登录业务的实现类 其 login 方法会返回一个 JWTUtils 的 token

  1. @Service
  2. public class UserServiceImpl implements UserService {
  3. @Autowired
  4. private UserMapper userMapper;
  5. @Autowired
  6. private AuthenticationManager authenticationManager;
  7. @Autowired
  8. private UserDetailsService userDetailsService;
  9. @Autowired
  10. private JwtTokenUtil jwtTokenUtil;
  11. public User findByUsername(String username) {
  12. User user = userMapper.selectByUserName(username);
  13. return user;
  14. }
  15. public RetResult login(String username, String password) throws AuthenticationException {
  16. UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(username, password);
  17. final Authentication authentication = authenticationManager.authenticate(upToken);
  18. SecurityContextHolder.getContext().setAuthentication(authentication);
  19. UserDetails userDetails = userDetailsService.loadUserByUsername(username);
  20. return new RetResult(RetCode.SUCCESS.getCode(),jwtTokenUtil.generateToken(userDetails));
  21. }
  22. }

最后配置 Config

  1. @EnableGlobalMethodSecurity(prePostEnabled = true)
  2. @EnableWebSecurity
  3. public class WebSecurity extends WebSecurityConfigurerAdapter {
  4. @Autowired
  5. private UserDetailsService userDetailsService;
  6. @Autowired
  7. private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
  8. @Autowired
  9. public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
  10. authenticationManagerBuilder.userDetailsService(this.userDetailsService).passwordEncoder(passwordEncoder());
  11. }
  12. @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
  13. @Override
  14. public AuthenticationManager authenticationManagerBean() throws Exception {
  15. return super.authenticationManagerBean();
  16. }
  17. @Bean
  18. public PasswordEncoder passwordEncoder() {
  19. return new BCryptPasswordEncoder();
  20. }
  21. @Override
  22. protected void configure(HttpSecurity http) throws Exception {
  23. http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  24. .and().authorizeRequests()
  25. .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
  26. .antMatchers("/auth/**").permitAll()
  27. .anyRequest().authenticated()
  28. .and().headers().cacheControl();
  29. http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
  30. ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
  31. registry.requestMatchers(CorsUtils::isPreFlightRequest).permitAll();
  32. }
  33. @Bean
  34. public CorsFilter corsFilter() {
  35. final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
  36. final CorsConfiguration cors = new CorsConfiguration();
  37. cors.setAllowCredentials(true);
  38. cors.addAllowedOrigin("*");
  39. cors.addAllowedHeader("*");
  40. cors.addAllowedMethod("*");
  41. urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", cors);
  42. return new CorsFilter(urlBasedCorsConfigurationSource);
  43. }
  44. }

运行,返回 token

运行,返回结果为 token

这里配置 SpringSecurity 之 JSON 登录

这里需要重写 UsernamePasswordAnthenticationFilter 类,以及配置 SpringSecurity

重写 UsernamePasswordAnthenticationFilter

  1. public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
  2. @Override
  3. public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
  4. if(request.getContentType().equals(MediaType.APPLICATION_JSON_UTF8_VALUE)
  5. ||request.getContentType().equals(MediaType.APPLICATION_JSON_VALUE)){
  6. ObjectMapper mapper = new ObjectMapper();
  7. UsernamePasswordAuthenticationToken authRequest = null;
  8. try (InputStream is = request.getInputStream()){
  9. AuthenticationBean authenticationBean = mapper.readValue(is,AuthenticationBean.class);
  10. authRequest = new UsernamePasswordAuthenticationToken(
  11. authenticationBean.getUsername(), authenticationBean.getPassword());
  12. }catch (IOException e) {
  13. e.printStackTrace();
  14. authRequest = new UsernamePasswordAuthenticationToken(
  15. "", "");
  16. }finally {
  17. setDetails(request, authRequest);
  18. return this.getAuthenticationManager().authenticate(authRequest);
  19. }
  20. }
  21. else {
  22. return super.attemptAuthentication(request, response);
  23. }
  24. }
  25. }

配置 SecurityConfig

  1. @Override
  2. protected void configure(HttpSecurity http) throws Exception {
  3. http
  4. .cors().and()
  5. .antMatcher("/**").authorizeRequests()
  6. .antMatchers("/", "/login**").permitAll()
  7. .anyRequest().authenticated()
  8. .and().formLogin().loginPage("/")
  9. .and().csrf().disable();
  10. http.addFilterAt(customAuthenticationFilter(),
  11. UsernamePasswordAuthenticationFilter.class);
  12. }
  13. @Bean
  14. CustomAuthenticationFilter customAuthenticationFilter() throws Exception {
  15. CustomAuthenticationFilter filter = new CustomAuthenticationFilter();
  16. filter.setAuthenticationSuccessHandler(new SuccessHandler());
  17. filter.setAuthenticationFailureHandler(new FailureHandler());
  18. filter.setFilterProcessesUrl("/login/self");
  19. filter.setAuthenticationManager(authenticationManagerBean());
  20. return filter;
  21. }

这样就完成使用 json 登录 SpringSecurity

需要在 Config 类中配置如下内容

  1. @Bean
  2. public BCryptPasswordEncoder passwordEncoder(){
  3. return new BCryptPasswordEncoder();
  4. }

即,使用此方法,对密码进行加密, 在业务层的时候,使用此加密的方法

  1. @Service
  2. @Transactional
  3. public class UserServiceImpl implements UserService {
  4. @Resource
  5. private UserRepository userRepository;
  6. @Resource
  7. private BCryptPasswordEncoder bCryptPasswordEncoder;
  8. @Override
  9. public User add(User user) {
  10. user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
  11. User user2 = userRepository.save(user);
  12. return user2;
  13. }
  14. @Override
  15. public ResultInfo login(User user) {
  16. ResultInfo resultInfo=new ResultInfo();
  17. User user2 = userRepository.findByName(user.getName());
  18. if (user2==null) {
  19. resultInfo.setCode("-1");
  20. resultInfo.setMessage("用户名不存在");
  21. return resultInfo;
  22. }
  23. if (!bCryptPasswordEncoder.matches(user.getPassword(),user2.getPassword())) {
  24. resultInfo.setCode("-1");
  25. resultInfo.setMessage("密码不正确");
  26. return resultInfo;
  27. }
  28. resultInfo.setMessage("登录成功");
  29. return resultInfo;
  30. }
  31. }

即,使用 BCryptPasswordEncoder 对密码进行加密,保存数据库

这里使用数据库认证 SpringSecurity

设计数据表

这里设计数据表

着重配置 SpringConfig

  1. @Configurable
  2. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  3. @Autowired
  4. private UserService userService;
  5. @Bean
  6. PasswordEncoder passwordEncoder(){
  7. return new BCryptPasswordEncoder();
  8. }
  9. @Override
  10. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  11. auth.userDetailsService(userService);
  12. }
  13. @Override
  14. protected void configure(HttpSecurity http) throws Exception {
  15. http.authorizeRequests()
  16. .antMatchers("/admin/**").hasRole("admin")
  17. .anyRequest().authenticated()
  18. .and()
  19. .formLogin()
  20. .loginProcessingUrl("/login").permitAll()
  21. .and()
  22. .csrf().disable();
  23. }
  24. }

这里着重配置 SpringConfig

着重讲解了 RBAC 的权限配置,以及简单的使用 SpringSecurity,以及使用 SpringSecurity + JWT 完成前后端的分离,以及配置 json 登录,和密码加密方式,

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/983755
推荐阅读
相关标签
  

闽ICP备14008679号