|  |  |  | 
|---|
|  |  |  | config.setAllowCredentials(true); | 
|---|
|  |  |  | config.addAllowedOrigin("*"); | 
|---|
|  |  |  | config.addAllowedHeader("*"); | 
|---|
|  |  |  | config.addAllowedMethod("*"); | 
|---|
|  |  |  | config.setMaxAge(3600L); | 
|---|
|  |  |  | config.setMaxAge(36000L); | 
|---|
|  |  |  | config.setAllowedMethods(Arrays.asList("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")); | 
|---|
|  |  |  | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | 
|---|
|  |  |  | source.registerCorsConfiguration("/**", config); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else if (e instanceof AuthMethodNotSupportedException) { | 
|---|
|  |  |  | mapper.writeValue(response.getWriter(), ErrorResponse.of(e.getMessage(), ErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mapper.writeValue(response.getWriter(), ErrorResponse.of("Authentication failed", ErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED)); | 
|---|
|  |  |  | //        mapper.writeValue(response.getWriter(), ErrorResponse.of("Authentication failed", ErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED)); | 
|---|
|  |  |  | mapper.writeValue(response.getWriter(), ErrorResponse.of(e.getMessage(), ErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | throw new AuthMethodNotSupportedException("Authentication method not supported"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginRequest loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isBlank(loginRequest.getUsername()) | 
|---|
|  |  |  | || StringUtils.isBlank(loginRequest.getPassword()) | 
|---|
|  |  |  | || loginRequest.getMode() == null) { | 
|---|
|  |  |  | throw new AuthenticationServiceException("Username or Password not provided"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()); | 
|---|
|  |  |  | // 此处存储登录方式由客户端发送过来 | 
|---|
|  |  |  | token.setDetails(loginRequest.getMode()); | 
|---|