统一身份认证系统
spring.security.user.name=admin spring.security.user.password=password ]]>

]]>
public class JwtUtil { public static String generateToken(String username) { return Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, "secretkey") .compact(); } public static Claims parseToken(String token) { return Jwts.parser() .setSigningKey("secretkey") .parseClaimsJws(token) .getBody(); } } ]]>
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/api/auth/**").permitAll() .anyRequest().authenticated() .and() .addFilter(new JwtAuthenticationFilter(authenticationManager())) .addFilter(new JwtAuthorizationFilter(authenticationManager())); } } ]]>