[BAEL-16733] - Update package name and tests in spring-security-core
This commit is contained in:
parent
03977951bb
commit
b172804fe1
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.app;
|
||||
package com.baeldung.app;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
|
@ -12,9 +12,9 @@ import org.springframework.web.filter.DelegatingFilterProxy;
|
|||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories("org.baeldung.repository")
|
||||
@ComponentScan("org.baeldung")
|
||||
@EntityScan("org.baeldung.entity")
|
||||
@EnableJpaRepositories("com.baeldung.repository")
|
||||
@ComponentScan("com.baeldung")
|
||||
@EntityScan("com.baeldung.entity")
|
||||
public class App extends SpringBootServletInitializer {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class, args);
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.auditing;
|
||||
package com.baeldung.auditing;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEvent;
|
||||
import org.springframework.boot.actuate.security.AbstractAuthorizationAuditListener;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.auditing;
|
||||
package com.baeldung.auditing;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -1,11 +1,12 @@
|
|||
package org.baeldung.config;
|
||||
package com.baeldung.config;
|
||||
|
||||
import org.baeldung.entity.Task;
|
||||
import org.baeldung.repository.TaskRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.baeldung.entity.Task;
|
||||
import com.baeldung.repository.TaskRepository;
|
||||
|
||||
@Component
|
||||
public class DatabaseLoader implements CommandLineRunner {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.config;
|
||||
package com.baeldung.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
|
@ -1,7 +1,5 @@
|
|||
package org.baeldung.controller;
|
||||
package com.baeldung.controller;
|
||||
|
||||
import org.baeldung.entity.Task;
|
||||
import org.baeldung.service.TaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -9,6 +7,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.baeldung.entity.Task;
|
||||
import com.baeldung.service.TaskService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("api/tasks")
|
||||
public class TaskController {
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.entity;
|
||||
package com.baeldung.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.filter;
|
||||
package com.baeldung.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.methodsecurity.annotation;
|
||||
package com.baeldung.methodsecurity.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.methodsecurity.config;
|
||||
package com.baeldung.methodsecurity.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.methodsecurity.entity;
|
||||
package com.baeldung.methodsecurity.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
package org.baeldung.methodsecurity.repository;
|
||||
package com.baeldung.methodsecurity.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.baeldung.methodsecurity.entity.CustomUser;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.methodsecurity.entity.CustomUser;
|
||||
|
||||
@Service
|
||||
public class UserRoleRepository {
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
package org.baeldung.methodsecurity.service;
|
||||
package com.baeldung.methodsecurity.service;
|
||||
|
||||
import org.baeldung.methodsecurity.repository.UserRoleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.methodsecurity.repository.UserRoleRepository;
|
||||
|
||||
@Service("userDetailService")
|
||||
public class CustomUserDetailsService implements UserDetailsService {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.methodsecurity.service;
|
||||
package com.baeldung.methodsecurity.service;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,13 +1,10 @@
|
|||
package org.baeldung.methodsecurity.service;
|
||||
package com.baeldung.methodsecurity.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
|
||||
import org.baeldung.methodsecurity.annotation.IsViewer;
|
||||
import org.baeldung.methodsecurity.entity.CustomUser;
|
||||
import org.baeldung.methodsecurity.repository.UserRoleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.security.access.prepost.PostAuthorize;
|
||||
|
@ -18,6 +15,10 @@ import org.springframework.security.core.context.SecurityContext;
|
|||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.methodsecurity.annotation.IsViewer;
|
||||
import com.baeldung.methodsecurity.entity.CustomUser;
|
||||
import com.baeldung.methodsecurity.repository.UserRoleRepository;
|
||||
|
||||
@Service
|
||||
public class UserRoleService {
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import org.baeldung.entity.Task;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.baeldung.entity.Task;
|
||||
|
||||
public interface TaskRepository extends CrudRepository<Task, Long> {
|
||||
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
package org.baeldung.service;
|
||||
package com.baeldung.service;
|
||||
|
||||
import org.baeldung.entity.Task;
|
||||
import org.baeldung.repository.TaskRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreFilter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.entity.Task;
|
||||
import com.baeldung.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.baeldung.app.App;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.app.App;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = App.class)
|
||||
public class SpringContextIntegrationTest {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.baeldung.app.App;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.app.App;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = App.class)
|
||||
public class SpringContextTest {
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.baeldung.methodsecurity;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.baeldung.methodsecurity.service.SystemService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -13,15 +12,17 @@ import org.springframework.security.test.context.support.WithMockUser;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.methodsecurity.service.SystemService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TestClassLevelSecurityUnitTest {
|
||||
public class ClassLevelSecurityIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
SystemService systemService;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.methodsecurity.*")
|
||||
@ComponentScan("com.baeldung.methodsecurity.*")
|
||||
public static class SpringConfig {
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.methodsecurity.service.UserRoleService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,15 +18,17 @@ import org.springframework.security.test.context.support.WithMockUser;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.methodsecurity.service.UserRoleService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TestMethodSecurityUnitTest {
|
||||
public class MethodSecurityIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
UserRoleService userRoleService;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.methodsecurity.*")
|
||||
@ComponentScan("com.baeldung.methodsecurity.*")
|
||||
public static class SpringConfig {
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.baeldung.methodsecurity;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.baeldung.methodsecurity.service.UserRoleService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -12,10 +11,12 @@ import org.springframework.security.test.context.support.WithMockUser;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.methodsecurity.service.UserRoleService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@WithMockUser(username = "john", roles = { "VIEWER" })
|
||||
public class TestWithMockUserAtClassLevelUnitTest {
|
||||
public class MockUserAtClassLevelIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() {
|
||||
|
@ -27,7 +28,7 @@ public class TestWithMockUserAtClassLevelUnitTest {
|
|||
UserRoleService userService;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.methodsecurity.*")
|
||||
@ComponentScan("com.baeldung.methodsecurity.*")
|
||||
public static class SpringConfig {
|
||||
|
||||
}
|
|
@ -2,8 +2,6 @@ package com.baeldung.methodsecurity;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.baeldung.methodsecurity.entity.CustomUser;
|
||||
import org.baeldung.methodsecurity.service.UserRoleService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -14,15 +12,18 @@ import org.springframework.security.test.context.support.WithUserDetails;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.methodsecurity.entity.CustomUser;
|
||||
import com.baeldung.methodsecurity.service.UserRoleService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TestWithUserDetailsUnitTest {
|
||||
public class UserDetailsIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
UserRoleService userService;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.methodsecurity.*")
|
||||
@ComponentScan("com.baeldung.methodsecurity.*")
|
||||
public static class SpringConfig {
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.baeldung.app.App;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
|
@ -20,6 +19,8 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.baeldung.app.App;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
|
|
Loading…
Reference in New Issue