-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
447 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
shogun-lib/src/test/java/de/terrestris/shogun/lib/config/AuditConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.terrestris.shogun.lib.config; | ||
|
||
import org.hibernate.envers.AuditReader; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
|
||
@Configuration | ||
public class AuditConfig { | ||
|
||
private final EntityManagerFactory entityManagerFactory; | ||
|
||
AuditConfig(EntityManagerFactory entityManagerFactory) { | ||
this.entityManagerFactory = entityManagerFactory; | ||
} | ||
|
||
@Bean | ||
AuditReader auditReader() { | ||
return AuditReaderFactory.get(entityManagerFactory.createEntityManager()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
shogun-lib/src/test/java/de/terrestris/shogun/lib/config/MethodSecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package de.terrestris.shogun.lib.config; | ||
|
||
import de.terrestris.shogun.lib.security.access.BasePermissionEvaluator; | ||
import de.terrestris.shogun.lib.security.access.entity.BaseEntityPermissionEvaluator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; | ||
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { | ||
|
||
@Autowired | ||
private BasePermissionEvaluator basePermissionEvaluator; | ||
|
||
@Autowired | ||
private List<BaseEntityPermissionEvaluator> permissionEvaluators; | ||
|
||
@Override | ||
protected MethodSecurityExpressionHandler createExpressionHandler() { | ||
DefaultMethodSecurityExpressionHandler expressionHandler = | ||
new DefaultMethodSecurityExpressionHandler(); | ||
expressionHandler.setPermissionEvaluator(basePermissionEvaluator); | ||
|
||
return expressionHandler; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
shogun-lib/src/test/java/de/terrestris/shogun/lib/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package de.terrestris.shogun.lib.config; | ||
|
||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
@EnableAutoConfiguration | ||
@ComponentScan(basePackages = { | ||
"de.terrestris.shoguncore.controller" | ||
}) | ||
public class WebConfig implements WebMvcConfigurer { } |
25 changes: 25 additions & 0 deletions
25
shogun-lib/src/test/java/de/terrestris/shogun/lib/config/WebSecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.terrestris.shogun.lib.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
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; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http | ||
.authorizeRequests() | ||
.anyRequest() | ||
.authenticated() | ||
.and() | ||
.csrf() | ||
.disable(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
shogun-lib/src/test/java/de/terrestris/shogun/lib/controller/ApplicationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.terrestris.shogun.lib.controller; | ||
|
||
import de.terrestris.shogun.lib.model.Application; | ||
import de.terrestris.shogun.lib.repository.ApplicationRepository; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ContextConfiguration(classes = { | ||
Application.class | ||
}) | ||
public class ApplicationControllerTest extends BaseControllerTest<ApplicationController, ApplicationRepository, Application> { | ||
|
||
@Before | ||
public void setBasePath() { | ||
basePath = "/applications"; | ||
} | ||
|
||
@Before | ||
public void setEntityClass() { | ||
entityClass = Application.class; | ||
} | ||
|
||
@Before | ||
public void insertTestData() { | ||
Application entity1 = new Application(); | ||
Application entity2 = new Application(); | ||
Application entity3 = new Application(); | ||
|
||
entity1.setName("Application 1"); | ||
entity2.setName("Application 2"); | ||
entity3.setName("Application 3"); | ||
|
||
ArrayList<Application> entities = new ArrayList<>(); | ||
|
||
entities.add(entity1); | ||
entities.add(entity2); | ||
entities.add(entity3); | ||
|
||
List<Application> persistedEntities = (List<Application>) repository.saveAll(entities); | ||
|
||
testData = persistedEntities; | ||
} | ||
|
||
@After | ||
public void cleanupTestData() { | ||
repository.deleteAll(testData); | ||
} | ||
|
||
} |
Oops, something went wrong.