본문 바로가기

개발일지

swagger-ui 연동 재 테스트 1

728x90

기존에 작업했었던 swagger-ui 연동부분을 다시 테스트 해봤다. 

문제는 버전이 올라가면서 보안부분및 인터페이스 관련하여 rest 서비스를 다시 테스트해보려고 한다.

https://csksoft.tistory.com/57

 

STS4 / JPA / swagger2 / H2 db연동 테스트 샘플 프로젝트 따라하기

2021.03.23 - [개발일지] - STS / Swagger2 / lombok / Gradle Project 환경 설정 STS / Swagger2 / lombok / Gradle Project 환경 설정 2년전에 SpringBoot / Swagger2 / lombok / Gradle Project 환경 설정 2. S..

csksoft.tistory.com

 

예전에는 localhost:8080/swagger-ui.html 주소로 하면 swagger 화면이 보였는데...

갑자기 안보이니 꽤나 당황스러운 상황이 되었다.  좀더 찾아보니 주소를 아래 처럼 하면 된다. 

이것 땜에 왜 안되지 하고 아까운 시간을 버렸음. ㅠㅠ

버전이 업드레이드 되면 수정되는 사항이 있으니 체크가 항상 필요하네요. 에휴

http://localhost:8080/swagger-ui/index.html

그럼 다시 프로젝트를 생성하여 테스트 시작 합니다. 

이클립스 IDE 버전은 Version: 2021-12 을 사용함.

1. 프로젝트 생성

여기서 Spring boot 버전을 수정하는 이유는 swagger-ui 를 사용하려고 하는데... maven install 하면 오류가 발생하여 어쩔 수 없이 버전을 다운하였음. 아래 화면처럼 pom.xml 수정 변경함.

이제 maven.build를 실행합니다. 그러나 그래도 오류가 발생하는데...

이런 오류가 발생 하는데.. 아무튼 다시 해결합니다. 

https://stackoverflow.com/questions/36427868/failed-to-execute-goal-org-apache-maven-pluginsmaven-surefire-plugin2-12test

 

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

I have been trying from a couple of days to resolve the following error but I am unable to resolve it :( My module's pom.xml file is: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns...

stackoverflow.com

이 부분을 추가합니다.
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.19.1</version>
</plugin>

이렇게 추가함.

 

그리고 여기에 두개의 파일을 추가함.

SecurityConfig.java

package com.ifapi.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

//	@Value("${spring.security.user.name}")
//	String name;
	
//	@Value("${spring.security.user.name}")
//	String name;
	
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		// TODO Auto-generated method stub
		http.csrf().disable().authorizeRequests().anyRequest().fullyAuthenticated().and().httpBasic();
	}

	@Autowired
	public void configureGloval(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication()
		.withUser("user") // name
		.password("passwd")// "{noop}" + 
		.roles("ADMIN");
	}
	
	@Bean
	public static NoOpPasswordEncoder passEncoder() {
		return (NoOpPasswordEncoder)NoOpPasswordEncoder.getInstance();
	}
	
}

application.yml 파일 추가

server:
  servlet:
    context-path : /ifapi

IfapiTest2Application.java에도 customOpenAPI 추가

지금까지 작업한 소스 프로젝트 

IfapiTest-2.zip
0.06MB

 

소스에 보면 BASIC 인증을 처리하였으므로 초기에는 ID : user , PW: passwd 로 설정하였음.

로그인을 하면 아래 화면 처럼 뜹니다.

728x90