Перенос проекта с Maven на Ant
Есть проект на Maven, созданный по туториалу с Spring Boot и Spring Security.
Проект представляет себя простейший веб-сервис. При набивании в адресную строку "localhost:8080/api/v1/developers" выводится список всех разработчиков, а если к строке добавить /1, /2 или /3, то выведется разработчик данного номера (Сам список определен в классе Developer, а его вывод через HTTP-запросы описан в DeveloperRestControllerV1 ). Но перед тем, как получать списки, пользователь должен авторизоваться. Настройки авторизации и доступа определены в SecurityConfig и Role. Запускается приложение с помощью Spring Boot в SpringsecurityApplication.
Код SpringsecurityApplication.java, запускающего Spring:
package com.example.springsecurity;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringsecurityApplication {
public static void main(String[] args) {
SpringApplication.run(SpringsecurityApplication.class, args);
}
}
Код SecurityConfig.java:
package com.example.springsecurity.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.http.HttpMethod;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers(HttpMethod.GET, "/api/**").hasAnyRole(Role.ADMIN.name(), Role.USER.name())
.antMatchers(HttpMethod.POST, "/api/**").hasRole(Role.ADMIN.name())
.antMatchers(HttpMethod.DELETE, "/api/**").hasRole(Role.ADMIN.name())
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
@Bean
@Override
protected UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager(
User.builder()
.username("admin")
.password(passwordEncoder().encode("admin"))
.roles(Role.ADMIN.name())
.build(),
User.builder()
.username("user")
.password(passwordEncoder().encode("user"))
.roles(Role.USER.name())
.build()
);
}
@Bean
protected PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
}
Код Role.java:
package com.example.springsecurity.config;
public enum Role {
USER,
ADMIN;
}
Код Developer.java:
package com.example.springsecurity.model;
import lombok.Data;
import lombok.AllArgsConstructor;
@Data
@AllArgsConstructor
public class Developer {
private Long id;
private String firstName;
private String lastName;
}
Код DeveloperRestControllerV1.java:
package com.example.springsecurity.rest;
import com.example.springsecurity.model.Developer;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@RestController
@RequestMapping("/api/v1/developers")
public class DeveloperRestControllerV1 {
private List<Developer> DEVELOPERS = Stream.of(
new Developer(1L, "Ivan", "Ivanov"),
new Developer(2L, "Sergey", "Sergeev"),
new Developer(3L, "Petr", "Petrov")
).collect(Collectors.toList());
@GetMapping
public List<Developer> getAll(){
return DEVELOPERS;
}
@GetMapping("/{id}")
public Developer getById(@PathVariable Long id){
return DEVELOPERS.stream().filter(developer -> developer.getId().equals(id))
.findFirst()
.orElse(null);
}
@PostMapping
public Developer create(@RequestBody Developer developer){
this.DEVELOPERS.add(developer);
return developer;
}
@DeleteMapping("/{id}")
public void delete(@PathVariable Long id){
this.DEVELOPERS.removeIf(developer -> developer.getId().equals(id));
}
}
Нужно перенести этот проект на Ant. Библиотеки можно просто скопировать из Maven-проекта, классы можно перенести. Однако попытки запустить Spring Boot из Ant успехом не увенчались. Скорее всего, нужно поправить что-то в каком-то конфигурационном файле. Мануалов Spring Boot + Ant практически нет, есть одна страница в официальной документации Spring. Но в проекте со скопированными зависимостями, классами и взятой из мануала кодом не работает Spring Security (Все страницы доступны). Как правильно полностью перенести этот проект с Maven на Ant? Это должно быть возможно, так как и Ant, и Maven являются не более чем связывателями зависимостей и сборщиками проектов.