├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── audit4j-demo-annotation-int ├── pom.xml └── src │ └── main │ ├── java │ ├── audit │ │ └── AuditAspect.java │ └── org │ │ └── audit4j │ │ └── demo │ │ ├── App.java │ │ └── CardManagement.java │ └── resources │ └── audit4j.conf.yaml ├── audit4j-demo-hibernate ├── README.md ├── audit4jdb.lck ├── audit4jdb.log ├── audit4jdb.properties ├── audit4jdb.script ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── audt4j │ │ └── demo │ │ └── hibernate │ │ ├── bootstrap │ │ └── WebInitializer.java │ │ ├── config │ │ ├── AppConfig.java │ │ ├── AuditConfig.java │ │ ├── AuditMetaData.java │ │ ├── PersistanceConfig.java │ │ ├── SecurityConfig.java │ │ └── core │ │ │ ├── SpringMvcInitializer.java │ │ │ └── SpringSecurityInitializer.java │ │ ├── dao │ │ ├── UserDao.java │ │ └── impl │ │ │ └── UserDaoImpl.java │ │ ├── model │ │ ├── Payment.java │ │ └── User.java │ │ ├── service │ │ ├── InventoryService.java │ │ ├── Item.java │ │ ├── PaymentService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── InventoryServiceImpl.java │ │ │ ├── PaymentServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── web │ │ └── controller │ │ ├── AuditDemoController.java │ │ └── HelloController.java │ ├── resources │ ├── META-INF │ │ └── qms-persistance.xml │ ├── audit4j.conf.yaml │ └── db │ │ └── sql │ │ ├── create-db.sql │ │ └── insert-data.sql │ └── webapp │ └── WEB-INF │ └── pages │ ├── admin.jsp │ ├── demo.jsp │ ├── hello.jsp │ └── login.jsp ├── audit4j-demo-http ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── audit4j │ │ └── demo │ │ └── http │ │ ├── LoginServlet.java │ │ └── UserService.java │ ├── resources │ └── audit4j.conf.yaml │ └── webapp │ ├── LoginSuccess.jsp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── pages │ │ ├── admin.jsp │ │ ├── hello.jsp │ │ └── login.jsp │ └── web.xml │ └── login.html ├── audit4j-demo-spring-petclinic ├── .gitignore ├── .springBeans ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ ├── org │ │ │ └── springframework │ │ │ │ └── samples │ │ │ │ └── petclinic │ │ │ │ ├── model │ │ │ │ ├── BaseEntity.java │ │ │ │ ├── NamedEntity.java │ │ │ │ ├── Owner.java │ │ │ │ ├── Person.java │ │ │ │ ├── Pet.java │ │ │ │ ├── PetType.java │ │ │ │ ├── Specialty.java │ │ │ │ ├── Vet.java │ │ │ │ ├── Vets.java │ │ │ │ ├── Visit.java │ │ │ │ └── package-info.java │ │ │ │ ├── repository │ │ │ │ ├── OwnerRepository.java │ │ │ │ ├── PetRepository.java │ │ │ │ ├── VetRepository.java │ │ │ │ ├── VisitRepository.java │ │ │ │ ├── jdbc │ │ │ │ │ ├── JdbcOwnerRepositoryImpl.java │ │ │ │ │ ├── JdbcPet.java │ │ │ │ │ ├── JdbcPetRepositoryImpl.java │ │ │ │ │ ├── JdbcPetRowMapper.java │ │ │ │ │ ├── JdbcVetRepositoryImpl.java │ │ │ │ │ ├── JdbcVisitRepositoryImpl.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── jpa │ │ │ │ │ ├── JpaOwnerRepositoryImpl.java │ │ │ │ │ ├── JpaPetRepositoryImpl.java │ │ │ │ │ ├── JpaVetRepositoryImpl.java │ │ │ │ │ ├── JpaVisitRepositoryImpl.java │ │ │ │ │ └── package-info.java │ │ │ │ └── springdatajpa │ │ │ │ │ ├── SpringDataOwnerRepository.java │ │ │ │ │ ├── SpringDataPetRepository.java │ │ │ │ │ ├── SpringDataVetRepository.java │ │ │ │ │ └── SpringDataVisitRepository.java │ │ │ │ ├── service │ │ │ │ ├── ClinicService.java │ │ │ │ └── ClinicServiceImpl.java │ │ │ │ ├── util │ │ │ │ ├── AuditMetaData.java │ │ │ │ ├── CallMonitoringAspect.java │ │ │ │ └── EntityUtils.java │ │ │ │ └── web │ │ │ │ ├── CrashController.java │ │ │ │ ├── OwnerController.java │ │ │ │ ├── PetController.java │ │ │ │ ├── PetTypeFormatter.java │ │ │ │ ├── PetValidator.java │ │ │ │ ├── VetController.java │ │ │ │ ├── VetsAtomView.java │ │ │ │ ├── VisitController.java │ │ │ │ └── package-info.java │ │ ├── overview.html │ │ └── test.html │ ├── resources │ │ ├── cache │ │ │ ├── ehcache.xml │ │ │ └── ehcache.xsd │ │ ├── dandelion │ │ │ └── datatables │ │ │ │ └── datatables.properties │ │ ├── db │ │ │ ├── hsqldb │ │ │ │ ├── initDB.sql │ │ │ │ └── populateDB.sql │ │ │ └── mysql │ │ │ │ ├── initDB.sql │ │ │ │ ├── petclinic_db_setup_mysql.txt │ │ │ │ └── populateDB.sql │ │ ├── db_readme.txt │ │ ├── logback.xml │ │ ├── messages │ │ │ ├── messages.properties │ │ │ ├── messages_de.properties │ │ │ └── messages_en.properties │ │ └── spring │ │ │ ├── audit-config.xml │ │ │ ├── business-config.xml │ │ │ ├── data-access.properties │ │ │ ├── datasource-config.xml │ │ │ ├── mvc-core-config.xml │ │ │ ├── mvc-view-config.xml │ │ │ └── tools-config.xml │ └── webapp │ │ ├── WEB-INF │ │ ├── jsp │ │ │ ├── exception.jsp │ │ │ ├── fragments │ │ │ │ ├── bodyHeader.jsp │ │ │ │ ├── footer.jsp │ │ │ │ └── staticFiles.jsp │ │ │ ├── owners │ │ │ │ ├── createOrUpdateOwnerForm.jsp │ │ │ │ ├── findOwners.jsp │ │ │ │ ├── ownerDetails.jsp │ │ │ │ └── ownersList.jsp │ │ │ ├── pets │ │ │ │ ├── createOrUpdatePetForm.jsp │ │ │ │ └── createOrUpdateVisitForm.jsp │ │ │ ├── vets │ │ │ │ └── vetList.jsp │ │ │ └── welcome.jsp │ │ ├── no-spring-config-files-there.txt │ │ ├── tags │ │ │ ├── inputField.tag │ │ │ └── selectField.tag │ │ └── web.xml │ │ └── resources │ │ ├── css │ │ └── petclinic.css │ │ └── images │ │ ├── banner-graphic.png │ │ ├── bullet-arrow.png │ │ ├── pets.png │ │ ├── spring-pivotal-logo.png │ │ ├── springsource-logo.png │ │ └── submit-bg.png │ └── test │ └── java │ └── org │ └── springframework │ └── samples │ └── petclinic │ ├── model │ └── ValidatorTests.java │ ├── service │ ├── AbstractClinicServiceTests.java │ ├── ClinicServiceJdbcTests.java │ ├── ClinicServiceJpaTests.java │ └── ClinicServiceSpringDataJpaTests.java │ └── web │ ├── VisitsViewTests-config.xml │ └── VisitsViewTests.java ├── audit4j-demo-spring ├── .gitignore ├── README.md ├── audit4jdb.lck ├── audit4jdb.log ├── audit4jdb.properties ├── audit4jdb.script ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── audt4j │ │ └── demo │ │ └── spring │ │ ├── config │ │ ├── AppConfig.java │ │ ├── AuditConfig.java │ │ ├── AuditMetaData.java │ │ ├── SecurityConfig.java │ │ └── core │ │ │ ├── SpringMvcInitializer.java │ │ │ └── SpringSecurityInitializer.java │ │ ├── model │ │ ├── Payment.java │ │ └── User.java │ │ ├── service │ │ ├── InventoryService.java │ │ ├── Item.java │ │ ├── PaymentService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── InventoryServiceImpl.java │ │ │ ├── PaymentServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── web │ │ └── controller │ │ ├── AuditDemoController.java │ │ └── HelloController.java │ ├── resources │ └── audit4j.conf.yaml │ └── webapp │ └── WEB-INF │ └── pages │ ├── admin.jsp │ ├── demo.jsp │ ├── hello.jsp │ └── login.jsp ├── audit4j-demo-springboot ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── hello │ │ │ ├── Application.java │ │ │ ├── AuditConfig.java │ │ │ ├── AuditMetaData.java │ │ │ ├── GreetingController.java │ │ │ ├── MvcConfig.java │ │ │ └── WebSecurityConfig.java │ └── resources │ │ └── templates │ │ ├── hello.html │ │ ├── home.html │ │ └── login.html │ └── test │ └── java │ └── hello │ └── GreetingControllerTest.java ├── audit4j-integration-tests ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── hello │ │ ├── Application.java │ │ ├── AuditConfig.java │ │ ├── AuditMetaData.java │ │ ├── GreetingController.java │ │ ├── MvcConfig.java │ │ ├── WebSecurityConfig.java │ │ └── data │ │ ├── Address.java │ │ └── User.java │ └── test │ ├── java │ ├── hello │ │ ├── SpringBootAuditedTest.java │ │ └── stage │ │ │ ├── GivenSomeState.java │ │ │ ├── ThenSomeOutcome.java │ │ │ └── WhenSomeAction.java │ └── org │ │ └── audit4j │ │ └── validation │ │ └── jgiven │ │ ├── CombinedConsoleAndFileAuditHandlerTest.java │ │ ├── CombinedConsoleAndFileAuditHandlerWithConfigFileTest.java │ │ ├── ConsoleAuditHandlerTest.java │ │ ├── ConsoleAuditHandlerWithFileConfigTest.java │ │ ├── ConsoleAuditHandlerWithFileConfigWithLayoutTest.java │ │ ├── ConsoleAuditHandlerWithLayoutTest.java │ │ ├── FileAuditHandlerTest.java │ │ ├── FileAuditHandlerWithFileConfigTest.java │ │ ├── enumeration │ │ └── Version.java │ │ ├── stage │ │ ├── GivenSomeState.java │ │ ├── ThenSomeOutcome.java │ │ └── WhenSomeAction.java │ │ └── util │ │ └── TesterUtil.java │ └── resources │ ├── audit4j-console-layout.conf.yml │ ├── audit4j-console.conf.yml │ ├── audit4j-file-console.conf.yml │ ├── audit4j-file.conf.yml │ └── audit4j-h2.conf.yml ├── audit4j-kotlin-demo-springboot ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ └── springframework │ │ │ └── samples │ │ │ └── petclinic │ │ │ ├── AuditConfig.kt │ │ │ ├── AuditMetaData.kt │ │ │ ├── PetClinicApplication.kt │ │ │ ├── model │ │ │ ├── BaseEntity.kt │ │ │ ├── NamedEntity.kt │ │ │ └── Person.kt │ │ │ ├── owner │ │ │ ├── Owner.kt │ │ │ ├── OwnerController.kt │ │ │ ├── OwnerRepository.kt │ │ │ ├── Pet.kt │ │ │ ├── PetController.kt │ │ │ ├── PetRepository.kt │ │ │ ├── PetType.kt │ │ │ ├── PetTypeFormater.kt │ │ │ ├── PetValidator.kt │ │ │ └── VisitController.kt │ │ │ ├── system │ │ │ ├── CacheConfig.kt │ │ │ ├── CrashController.kt │ │ │ └── WelcomeControler.kt │ │ │ ├── vet │ │ │ ├── Specialty.kt │ │ │ ├── Vet.kt │ │ │ ├── VetController.kt │ │ │ ├── VetRepository.kt │ │ │ └── Vets.kt │ │ │ └── visit │ │ │ ├── Visit.kt │ │ │ └── VisitRepository.kt │ ├── less │ │ ├── header.less │ │ ├── petclinic.less │ │ ├── responsive.less │ │ └── typography.less │ ├── resources │ │ ├── application.properties │ │ ├── banner.txt │ │ ├── db │ │ │ └── hsqldb │ │ │ │ ├── data.sql │ │ │ │ └── schema.sql │ │ ├── messages │ │ │ └── messages.properties │ │ ├── static │ │ │ └── resources │ │ │ │ ├── fonts │ │ │ │ ├── montserrat-webfont.eot │ │ │ │ ├── montserrat-webfont.svg │ │ │ │ ├── montserrat-webfont.ttf │ │ │ │ ├── montserrat-webfont.woff │ │ │ │ ├── varela_round-webfont.eot │ │ │ │ ├── varela_round-webfont.svg │ │ │ │ ├── varela_round-webfont.ttf │ │ │ │ └── varela_round-webfont.woff │ │ │ │ └── images │ │ │ │ ├── favicon.png │ │ │ │ ├── pets.png │ │ │ │ ├── platform-bg.png │ │ │ │ ├── spring-logo-dataflow-mobile.png │ │ │ │ ├── spring-logo-dataflow.png │ │ │ │ └── spring-pivotal-logo.png │ │ └── templates │ │ │ ├── error.html │ │ │ ├── fragments │ │ │ ├── inputField.html │ │ │ ├── layout.html │ │ │ └── selectField.html │ │ │ ├── owners │ │ │ ├── createOrUpdateOwnerForm.html │ │ │ ├── findOwners.html │ │ │ ├── ownerDetails.html │ │ │ └── ownersList.html │ │ │ ├── pets │ │ │ ├── createOrUpdatePetForm.html │ │ │ └── createOrUpdateVisitForm.html │ │ │ ├── vets │ │ │ └── vetList.html │ │ │ └── welcome.html │ └── wro │ │ ├── wro.properties │ │ └── wro.xml │ └── test │ └── kotlin │ └── org │ └── springframework │ └── samples │ └── petclinic │ ├── model │ └── ValidatorTests.kt │ ├── owner │ ├── OwnerControllerTests.kt │ ├── PetControllerTests.kt │ ├── PetTypeFormatterTest.kt │ └── VisitControllerTests.kt │ ├── service │ ├── ClinicServiceTests.kt │ └── EntityUtils.kt │ ├── system │ ├── CrashControllerTests.kt │ └── ProductionConfigurationTests.kt │ └── vet │ ├── VetControllerTests.kt │ └── VetTests.kt └── sample └── audit4j.conf.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | .idea/ 8 | *.iml 9 | *.audit 10 | .settings 11 | target 12 | .classpath 13 | .project 14 | */jgiven-reports/* 15 | 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | - openjdk7 6 | 7 | script: cd audit4j-demo-spring-petclinic && mvn clean package && cd ../audit4j-demo-springboot && mvn clean package && cd ../audit4j-kotlin-demo-springboot && mvn clean package 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/audit4j/audit4j-demo.svg?branch=master)](https://travis-ci.org/audit4j/audit4j-demo) 2 | 3 | # Audit4j-demo 4 | Sample audit4j applications. 5 | 6 | ## Audit4j-demo-springboot 7 | 8 | example taken from SpringBoot documentation https://spring.io/guides/gs/securing-web/ 9 | 10 | the login page is http://localhost:8080 11 | 12 | The users passwords are user/password and user2/password2. 13 | 14 | the following page http://localhost:8080/hello is audited. 15 | 16 | ## Audit4j-annotation-int 17 | Simple example showing how to integrate the @Audit annotation using aspectj. 18 | 19 | ## Audit4j-kotlin-demo-springboot 20 | example showing the usage of audit4j with Kotlin "Petclinic" application 21 | 22 | ### Links and sources 23 | this example is coming from the following github repositories 24 | https://github.com/spring-petclinic/spring-petclinic-kotlin 25 | https://github.com/spring-projects/spring-petclinic 26 | 27 | ### Example with Audit4j and Kotlin language 28 | 29 | Of course the annotation @Audit works fine. 30 | 31 | #### AuditManager 32 | ```kotlin 33 | AuditManager 34 | val actor = MyApplicationContext.getAuthenticatedUser() 35 | var manager = AuditManager.getInstance() 36 | manager.audit(AuditEvent(actor, "myMethod", Field("myParam1Name", myParam1), Field("myParam2Name", myParam2))) 37 | ``` 38 | #### EventBuilder 39 | ```kotlin 40 | val actor = MyApplicationContext.getAuthenticatedUser() 41 | var builder = EventBuilder(); 42 | builder.addActor(actor).addAction("myMethod").addField("myParam1Name", myParam1).addField("myParam2Name", myParam2) 43 | var manager = AuditManager.getInstance() 44 | manager.audit(builder.build()) 45 | ``` 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /audit4j-demo-annotation-int/src/main/java/org/audit4j/demo/App.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.demo; 2 | 3 | public class App { 4 | 5 | public static void main(String[] args) { 6 | 7 | CardManagement cardmanagement = new CardManagement(); 8 | cardmanagement.decrypt("daee458ddaa", "AA"); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /audit4j-demo-annotation-int/src/main/java/org/audit4j/demo/CardManagement.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.demo; 2 | 3 | import org.audit4j.core.annotation.Audit; 4 | import org.audit4j.core.annotation.AuditField; 5 | 6 | public class CardManagement { 7 | 8 | @Audit 9 | public String decrypt(@AuditField(field="encryptedCardNumber") 10 | String encryptedCardNumber, 11 | @AuditField(field="algo") 12 | String algo) { 13 | //dummy value 14 | return "123456790123456"; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /audit4j-demo-annotation-int/src/main/resources/audit4j.conf.yaml: -------------------------------------------------------------------------------- 1 | # To Activate this configuration, remove or comment Spring configuration. 2 | # see @org.audt4j.demo.spring.config.AuditConfig for more details. 3 | 4 | !Configuration 5 | handlers: 6 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 7 | layout: !org.audit4j.core.layout.SimpleLayout {} 8 | metaData: !org.audit4j.core.DummyMetaData {} 9 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate demo project 2 | Sample audit4j applications. 3 | 4 | To deploy the application: mvn jetty:run and access using http://localhost:8091 -------------------------------------------------------------------------------- /audit4j-demo-hibernate/audit4jdb.lck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-hibernate/audit4jdb.lck -------------------------------------------------------------------------------- /audit4j-demo-hibernate/audit4jdb.log: -------------------------------------------------------------------------------- 1 | /*C3*/SET SCHEMA PUBLIC 2 | create table if not exists audit (uuid varchar(200) NOT NULL,timestamp varchar(100) NOT NULL,actor varchar(200) NOT NULL,origin varchar(200),action varchar(200) NOT NULL,elements varchar(20000)) 3 | DISCONNECT 4 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/audit4jdb.properties: -------------------------------------------------------------------------------- 1 | #HSQL Database Engine 2.3.2 2 | #Sun Aug 07 22:04:16 IST 2016 3 | version=2.3.2 4 | modified=yes 5 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/bootstrap/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.bootstrap; 2 | import javax.servlet.FilterRegistration; 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.ServletRegistration.Dynamic; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.web.WebApplicationInitializer; 9 | import org.springframework.web.context.ContextLoaderListener; 10 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 11 | import org.springframework.web.filter.DelegatingFilterProxy; 12 | import org.springframework.web.servlet.DispatcherServlet; 13 | 14 | /** 15 | * The Class WebInitializer. 16 | * 17 | * @author JanithB 18 | */ 19 | public class WebInitializer { 20 | 21 | /* 22 | * (non-Javadoc) 23 | * 24 | * @see 25 | * org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet 26 | * .ServletContext) 27 | */ 28 | 29 | public void onStartup(ServletContext servletContext) { 30 | AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); 31 | ctx.setConfigLocation("org.audt4j.demo.hibernate.config"); 32 | servletContext.addListener(new ContextLoaderListener(ctx)); 33 | ctx.setServletContext(servletContext); 34 | Dynamic servlet = servletContext.addServlet("dispatcher", 35 | new DispatcherServlet(ctx)); 36 | servlet.addMapping("/*"); 37 | servlet.setLoadOnStartup(1); 38 | FilterRegistration.Dynamic springSecurityFilterChain = servletContext 39 | .addFilter("springSecurityFilterChain", 40 | new DelegatingFilterProxy()); 41 | springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*"); 42 | springSecurityFilterChain.setAsyncSupported(true); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 9 | import org.springframework.web.servlet.view.JstlView; 10 | 11 | @EnableWebMvc 12 | @Configuration 13 | @ComponentScan({ "org.audt4j.demo.hibernate.*" }) 14 | @EnableAspectJAutoProxy 15 | public class AppConfig { 16 | 17 | @Bean 18 | public InternalResourceViewResolver viewResolver() { 19 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 20 | viewResolver.setViewClass(JstlView.class); 21 | viewResolver.setPrefix("/WEB-INF/pages/"); 22 | viewResolver.setSuffix(".jsp"); 23 | return viewResolver; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/AuditConfig.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.audit4j.core.handler.ConsoleAuditHandler; 7 | import org.audit4j.core.handler.Handler; 8 | import org.audit4j.core.layout.SimpleLayout; 9 | import org.audit4j.handler.db.DatabaseAuditHandler; 10 | import org.audit4j.integration.spring.SpringAudit4jConfig; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | @Configuration 15 | public class AuditConfig { 16 | 17 | // If you want to load configurations from file 18 | // (resources/audit4j.conf.yaml), 19 | // comment below method 20 | @Bean 21 | public DatabaseAuditHandler databaseHandler() { 22 | DatabaseAuditHandler dbHandler = new DatabaseAuditHandler(); 23 | dbHandler.setEmbedded("true"); 24 | return dbHandler; 25 | } 26 | 27 | // If you want to load configurations from file 28 | // (resources/audit4j.conf.yaml), 29 | // comment below method 30 | @Bean 31 | public SpringAudit4jConfig springAudit4jConfig() { 32 | SpringAudit4jConfig springAudit4jConfig = new SpringAudit4jConfig(); 33 | springAudit4jConfig.setLayout(new SimpleLayout()); 34 | List handlers = new ArrayList(); 35 | handlers.add(new ConsoleAuditHandler()); 36 | 37 | handlers.add(databaseHandler()); 38 | springAudit4jConfig.setHandlers(handlers); 39 | springAudit4jConfig.setMetaData(new AuditMetaData()); 40 | return springAudit4jConfig; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/AuditMetaData.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config; 2 | 3 | import javax.servlet.ServletRequest; 4 | 5 | import org.audit4j.core.MetaData; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.security.core.context.SecurityContextHolder; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | 12 | public class AuditMetaData implements MetaData{ 13 | private static final long serialVersionUID = 7243065407615627372L; 14 | 15 | @Override 16 | public String getOrigin() { 17 | try { 18 | return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr(); 19 | }catch(Exception e){ 20 | e.printStackTrace(); 21 | } 22 | return "unidentified"; 23 | } 24 | 25 | @Override 26 | public String getActor() { 27 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 28 | if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { 29 | return ((UserDetails) authentication.getPrincipal()).getUsername(); 30 | } 31 | return "anonymous"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | 10 | @Configuration 11 | @EnableWebSecurity 12 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 13 | 14 | @Autowired 15 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 16 | auth.inMemoryAuthentication().withUser("test").password("123").roles("USER"); 17 | } 18 | 19 | //.csrf() is optional, enabled by default, if using WebSecurityConfigurerAdapter constructor 20 | @Override 21 | protected void configure(HttpSecurity http) throws Exception { 22 | 23 | http.authorizeRequests() 24 | .antMatchers("/demo/**").access("hasRole('ROLE_USER')") 25 | //.antMatchers("/auditDemo/**").access("hasRole('ROLE_USER')") 26 | .and() 27 | .formLogin().loginPage("/login").failureUrl("/login?error") 28 | .usernameParameter("username").passwordParameter("password") 29 | 30 | .and() 31 | .logout().logoutSuccessUrl("/login?logout") 32 | .and() 33 | .csrf(); 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/core/SpringMvcInitializer.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config.core; 2 | 3 | import org.audt4j.demo.hibernate.config.AppConfig; 4 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 5 | 6 | 7 | public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{ 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { AppConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return null; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/config/core/SpringSecurityInitializer.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.config.core; 2 | 3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 | 5 | public class SpringSecurityInitializer { 6 | 7 | } -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.dao; 2 | 3 | import org.audt4j.demo.hibernate.model.User; 4 | 5 | public interface UserDao { 6 | 7 | User getUserByUserName(String userName); 8 | 9 | User addUser(User user); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.dao.impl; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | import javax.persistence.Query; 8 | import javax.transaction.Transactional; 9 | 10 | import org.audt4j.demo.hibernate.dao.UserDao; 11 | import org.audt4j.demo.hibernate.model.User; 12 | import org.springframework.stereotype.Repository; 13 | 14 | @Repository("userDao") 15 | public class UserDaoImpl implements UserDao { 16 | 17 | @PersistenceContext 18 | private EntityManager entityManager; 19 | 20 | @Override 21 | public User getUserByUserName(String userName) { 22 | Query query = entityManager.createQuery("SELECT u FROM User u WHERE u.username=:userName"); 23 | query.setParameter("userName", userName); 24 | query.setMaxResults(1); 25 | 26 | List users = query.getResultList(); 27 | if (users == null || users.isEmpty()) { 28 | return null; 29 | } 30 | return users.get(0); 31 | } 32 | 33 | @Override 34 | public User addUser(User user) { 35 | entityManager.persist(user); 36 | entityManager.flush(); 37 | return user; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/model/Payment.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.audt4j.demo.hibernate.service.Item; 7 | 8 | public class Payment { 9 | 10 | private Double totalPrize; 11 | 12 | private String user; 13 | 14 | private List items = new ArrayList(); 15 | 16 | public Payment(String user, Double totalPrize, Item item){ 17 | this.user = user; 18 | this.totalPrize = totalPrize; 19 | this.items.add(item); 20 | } 21 | 22 | public Payment(){} 23 | 24 | public Double getTotalPrize() { 25 | return totalPrize; 26 | } 27 | 28 | public void setTotalPrize(Double totalPrize) { 29 | this.totalPrize = totalPrize; 30 | } 31 | 32 | public String getUser() { 33 | return user; 34 | } 35 | 36 | public void setUser(String user) { 37 | this.user = user; 38 | } 39 | 40 | public List getItems() { 41 | return items; 42 | } 43 | 44 | public void setItems(List items) { 45 | this.items = items; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/InventoryService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service; 2 | 3 | 4 | public interface InventoryService { 5 | 6 | void addItem(Item item); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/Item.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service; 2 | 3 | 4 | public class Item { 5 | 6 | private String name; 7 | 8 | private Double value; 9 | 10 | public Item(){ 11 | 12 | } 13 | 14 | public Item(String name, Double value){ 15 | this.name=name; 16 | this.value = value; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public Double getValue() { 28 | return value; 29 | } 30 | 31 | public void setValue(Double value) { 32 | this.value = value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.audt4j.demo.hibernate.model.Payment; 7 | 8 | public interface PaymentService { 9 | 10 | void checkout(Payment payment); 11 | 12 | void savePayment(String userId, List items); 13 | 14 | void saveCreditCard(String validName, Date expiry, String cardNumber); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/UserService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service; 2 | 3 | import org.audt4j.demo.hibernate.model.User; 4 | 5 | public interface UserService { 6 | 7 | 8 | void saveUser(User user); 9 | 10 | User getUserByuserName(String userName); 11 | 12 | void login(String userName, String password); 13 | 14 | void changePassword(String oldPassword, String newPassword); 15 | } 16 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/impl/InventoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service.impl; 2 | 3 | import org.audit4j.core.AuditManager; 4 | import org.audit4j.core.dto.EventBuilder; 5 | import org.audt4j.demo.hibernate.service.InventoryService; 6 | import org.audt4j.demo.hibernate.service.Item; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service("inventoryService") 10 | public class InventoryServiceImpl implements InventoryService { 11 | 12 | @Override 13 | public void addItem(Item item) { 14 | AuditManager.getInstance().audit( 15 | new EventBuilder().addAction("addInventoryItem").addField("itemName", item.getName()) 16 | .addField("itemValue", item.getValue()).build()); 17 | 18 | //Method Body 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/impl/PaymentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service.impl; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.audit4j.core.annotation.Audit; 7 | import org.audit4j.core.annotation.AuditField; 8 | import org.audit4j.core.annotation.DeIdentify; 9 | import org.audit4j.core.annotation.SelectionType; 10 | import org.audt4j.demo.hibernate.model.Payment; 11 | import org.audt4j.demo.hibernate.service.Item; 12 | import org.audt4j.demo.hibernate.service.PaymentService; 13 | import org.springframework.stereotype.Service; 14 | 15 | @Service("paymentService") 16 | public class PaymentServiceImpl implements PaymentService { 17 | 18 | @Override 19 | @Audit(selection=SelectionType.MARKED) 20 | public void savePayment(@AuditField(field = "paymentUserId") String userId, 21 | @AuditField(field = "paymentItems") List items) { 22 | 23 | } 24 | 25 | @Override 26 | @Audit(selection=SelectionType.MARKED) 27 | public void saveCreditCard(@AuditField(field = "cardUserName") String validName, 28 | @AuditField(field = "expiryDate") Date expiry, 29 | @AuditField(field = "cardNumber") @DeIdentify(fromRight = 4) String cardNumber) { 30 | 31 | } 32 | 33 | @Override 34 | @Audit(action = "checkoutPayment") 35 | public void checkout(Payment payment) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.service.impl; 2 | 3 | import javax.transaction.Transactional; 4 | 5 | import org.audit4j.core.annotation.IgnoreAudit; 6 | import org.audt4j.demo.hibernate.dao.UserDao; 7 | import org.audt4j.demo.hibernate.model.User; 8 | import org.audt4j.demo.hibernate.service.UserService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | @Service("userService") 13 | public class UserServiceImpl implements UserService { 14 | 15 | @Autowired 16 | private UserDao userDao; 17 | 18 | public void addUser() { 19 | 20 | } 21 | 22 | @Override 23 | @Transactional 24 | public void login(String userName, String password) { 25 | User user = userDao.getUserByUserName(userName); 26 | 27 | } 28 | 29 | @Override 30 | public User getUserByuserName(String userName) { 31 | return new User("admin"); 32 | } 33 | 34 | @Override 35 | @Transactional 36 | public void saveUser(User user) { 37 | userDao.addUser(user); 38 | 39 | } 40 | 41 | @Override 42 | @IgnoreAudit 43 | public void changePassword(String oldPassword, String newPassword) { 44 | // Method Body 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/web/controller/AuditDemoController.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.web.controller; 2 | 3 | import org.audt4j.demo.hibernate.model.User; 4 | import org.audt4j.demo.hibernate.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | 10 | @Controller 11 | public class AuditDemoController { 12 | 13 | @Autowired 14 | private UserService userService; 15 | 16 | @RequestMapping(value = "/testAddUser", method = RequestMethod.GET) 17 | public String testWithoutAnnotations() { 18 | 19 | userService.saveUser(new User("aa", "bb")); 20 | return "redirect:/demo"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/java/org/audt4j/demo/hibernate/web/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.hibernate.web.controller; 2 | 3 | import org.audt4j.demo.hibernate.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | @Controller 12 | public class HelloController { 13 | 14 | @Autowired 15 | private UserService userService; 16 | 17 | @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET) 18 | public ModelAndView welcomePage() { 19 | 20 | ModelAndView model = new ModelAndView(); 21 | model.setViewName("hello"); 22 | return model; 23 | } 24 | 25 | @RequestMapping(value = "/demo**", method = RequestMethod.GET) 26 | public ModelAndView adminPage() { 27 | ModelAndView model = new ModelAndView(); 28 | model.addObject("title", "Sample Secured page"); 29 | model.addObject("message", "This is protected page!"); 30 | model.setViewName("demo"); 31 | return model; 32 | } 33 | 34 | // @Audit 35 | @RequestMapping(value = "/login", method = RequestMethod.GET) 36 | public ModelAndView login(@RequestParam(value = "error", required = false) String error, 37 | @RequestParam(value = "logout", required = false) String logout) { 38 | userService.login("test", "123"); 39 | ModelAndView model = new ModelAndView(); 40 | if (error != null) { 41 | model.addObject("error", "Invalid username and password!"); 42 | } 43 | 44 | if (logout != null) { 45 | model.addObject("msg", "You've been logged out successfully."); 46 | } 47 | model.setViewName("login"); 48 | return model; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/resources/META-INF/qms-persistance.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | org.audt4j.demo.hibernate.model.User 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/resources/audit4j.conf.yaml: -------------------------------------------------------------------------------- 1 | # To Activate this configuration, remove or comment Spring configuration. 2 | # see @org.audt4j.demo.spring.config.AuditConfig for more details. 3 | 4 | !Configuration 5 | handlers: 6 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 7 | layout: !org.audit4j.core.layout.SimpleLayout {} 8 | metaData: !org.audt4j.demo.spring.config.AuditMetaData {} 9 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/resources/db/sql/create-db.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE users ( 2 | id INTEGER PRIMARY KEY, 3 | user_name VARCHAR(30), 4 | first_name VARCHAR(50), 5 | last_name VARCHAR(50), 6 | password VARCHAR(50), 7 | ); -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/resources/db/sql/insert-data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO users VALUES (1, 'mkyong', 'mkyong@gmail.com'); 2 | INSERT INTO users VALUES (2, 'alex', 'alex@yahoo.com'); 3 | INSERT INTO users VALUES (3, 'joel', 'joel@gmail.com'); -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/webapp/WEB-INF/pages/admin.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | <%@page session="true"%> 3 | 4 | 5 |

Title : ${title}

6 |

Message : ${message}

7 | 8 | 9 |
10 | 12 |
13 | 18 | 19 | 20 |

21 | Welcome : ${pageContext.request.userPrincipal.name} | Logout 23 |

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/webapp/WEB-INF/pages/demo.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | <%@page session="true"%> 3 | 4 | 5 | 6 | Audit4j Demo Application 7 | 8 | 9 | 10 | 11 |
12 | 14 |
15 | 20 | 21 | 22 | 23 |

24 | Welcome : ${pageContext.request.userPrincipal.name} | Logout 26 |

27 |
28 | 29 |

Test Without Annotation

30 |

31 | Please see this 33 | documentation section for more details. 34 |

35 | 36 | Example from: 37 | org.audt4j.demo.spring.service.impl.UserServiceImpl 38 | 39 | 40 |

41 | Click here to test 42 |

43 |
44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/webapp/WEB-INF/pages/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@page session="false"%> 2 | 3 | 4 | 5 |

Welcome to audit4j spring demo application

6 |

Please login before access the Demo Page

7 | 8 | User: test
9 | Passeord: 123 10 | 11 | -------------------------------------------------------------------------------- /audit4j-demo-hibernate/src/main/webapp/WEB-INF/pages/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Login Page 5 | 36 | 37 | 38 | 39 |

Login

40 | 41 |
42 | 43 |

Login with Username and Password

44 | 45 | 46 |
${error}
47 |
48 | 49 |
${msg}
50 |
51 | 52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 66 | 67 |
User:
Password:
68 | 69 | 71 | 72 |
73 |
74 | 75 | 76 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/java/org/audit4j/demo/http/LoginServlet.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.demo.http; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import org.audit4j.core.annotation.Audit; 14 | 15 | /** 16 | * Servlet implementation class LoginServlet 17 | */ 18 | @Audit 19 | @WebServlet(description = "Login Servlet", urlPatterns = { "/LoginServlet" }) 20 | public class LoginServlet extends HttpServlet { 21 | private static final long serialVersionUID = 1L; 22 | 23 | private UserService userService; 24 | 25 | public LoginServlet() { 26 | userService = new UserService(); 27 | } 28 | 29 | public void init() throws ServletException { 30 | 31 | } 32 | 33 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 34 | throws ServletException, IOException { 35 | System.out.println("---------------------------"); 36 | System.out.println(getServletContext().getRealPath("/LoginServlet.class")); 37 | System.out.println(System.getProperty("java.class.path")); 38 | 39 | // get request parameters for userID and password 40 | String user = request.getParameter("user"); 41 | String pwd = request.getParameter("pwd"); 42 | 43 | log("User=" + user + "::password=" + pwd); 44 | 45 | if (userService.login(user, pwd)) { 46 | response.sendRedirect("LoginSuccess.jsp"); 47 | } else { 48 | RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.html"); 49 | PrintWriter out = response.getWriter(); 50 | out.println("Either user name or password is wrong."); 51 | rd.include(request, response); 52 | 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/java/org/audit4j/demo/http/UserService.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.demo.http; 2 | 3 | import org.audit4j.core.annotation.Audit; 4 | 5 | @Audit 6 | public class UserService { 7 | 8 | 9 | public boolean login(final String userName, final String password){ 10 | if (userName.equals("test") && password.equals("123")) { 11 | return true; 12 | } 13 | return false; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/resources/audit4j.conf.yaml: -------------------------------------------------------------------------------- 1 | !Configuration 2 | handlers: 3 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 4 | layout: !org.audit4j.core.layout.SimpleLayout {} 5 | metaData: !org.audit4j.core.DummyMetaData {} 6 | properties: 7 | log.file.location: user.dir 8 | #commands: -codeGen=true -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/LoginSuccess.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=US-ASCII" 2 | pageEncoding="US-ASCII"%> 3 | 4 | 5 | 6 | 7 | Login Success Page 8 | 9 | 10 |

Hi Pankaj, Login successful.

11 | Login Page 12 | 13 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/WEB-INF/pages/admin.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | <%@page session="true"%> 3 | 4 | 5 |

Title : ${title}

6 |

Message : ${message}

7 | 8 | 9 |
10 | 12 |
13 | 18 | 19 | 20 |

21 | Welcome : ${pageContext.request.userPrincipal.name} | Logout 23 |

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/WEB-INF/pages/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@page session="false"%> 2 | 3 | 4 |

Title : ${title}

5 |

Message : ${message}

6 | 7 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/WEB-INF/pages/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Login Page 5 | 36 | 37 | 38 | 39 |

Spring Security Custom Login Form (Annotation)

40 | 41 |
42 | 43 |

Login with Username and Password

44 | 45 | 46 |
${error}
47 |
48 | 49 |
${msg}
50 |
51 | 52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 66 | 67 |
User:
Password:
68 | 69 | 71 | 72 |
73 |
74 | 75 | 76 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | LoginExample 7 | 8 | login.html 9 | 10 | 11 | 12 | org.audit4j.core.web.AuditContextListener 13 | 14 | 15 | 16 | 17 | -codeGen 18 | true 19 | 20 | 21 | 22 | 25 | -------------------------------------------------------------------------------- /audit4j-demo-http/src/main/webapp/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Login Page 6 | 7 | 8 | 9 |
10 | 11 | Username: 12 |
13 | Password: 14 |
15 | 16 |
17 | 18 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/.gitignore: -------------------------------------------------------------------------------- 1 | target/* 2 | .settings/* 3 | .classpath 4 | .project 5 | .idea 6 | *.iml 7 | /target 8 | audit4jdb* -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/spring/datasource-config.xml 11 | src/main/resources/spring/mvc-core-config.xml 12 | src/main/resources/spring/mvc-view-config.xml 13 | src/main/resources/spring/business-config.xml 14 | 15 | 16 | src/main/resources/spring/tools-config.xml 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.GeneratedValue; 19 | import javax.persistence.GenerationType; 20 | import javax.persistence.Id; 21 | import javax.persistence.MappedSuperclass; 22 | 23 | /** 24 | * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property. 25 | * 26 | * @author Ken Krebs 27 | * @author Juergen Hoeller 28 | */ 29 | @MappedSuperclass 30 | public class BaseEntity { 31 | @Id 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) 33 | protected Integer id; 34 | 35 | 36 | public void setId(Integer id) { 37 | this.id = id; 38 | } 39 | 40 | public Integer getId() { 41 | return id; 42 | } 43 | 44 | public boolean isNew() { 45 | return (this.id == null); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Column; 19 | import javax.persistence.MappedSuperclass; 20 | 21 | 22 | /** 23 | * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects 24 | * needing these properties. 25 | * 26 | * @author Ken Krebs 27 | * @author Juergen Hoeller 28 | */ 29 | @MappedSuperclass 30 | public class NamedEntity extends BaseEntity { 31 | 32 | @Column(name = "name") 33 | private String name; 34 | 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getName() { 41 | return this.name; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return this.getName(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Column; 19 | import javax.persistence.MappedSuperclass; 20 | 21 | import org.hibernate.validator.constraints.NotEmpty; 22 | 23 | /** 24 | * Simple JavaBean domain object representing an person. 25 | * 26 | * @author Ken Krebs 27 | */ 28 | @MappedSuperclass 29 | public class Person extends BaseEntity { 30 | 31 | @Column(name = "first_name") 32 | @NotEmpty 33 | protected String firstName; 34 | 35 | @Column(name = "last_name") 36 | @NotEmpty 37 | protected String lastName; 38 | 39 | public String getFirstName() { 40 | return this.firstName; 41 | } 42 | 43 | public void setFirstName(String firstName) { 44 | this.firstName = firstName; 45 | } 46 | 47 | public String getLastName() { 48 | return this.lastName; 49 | } 50 | 51 | public void setLastName(String lastName) { 52 | this.lastName = lastName; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/PetType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | /** 22 | * @author Juergen Hoeller 23 | * Can be Cat, Dog, Hamster... 24 | */ 25 | @Entity 26 | @Table(name = "types") 27 | public class PetType extends NamedEntity { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/Specialty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | /** 22 | * Models a {@link Vet Vet's} specialty (for example, dentistry). 23 | * 24 | * @author Juergen Hoeller 25 | */ 26 | @Entity 27 | @Table(name = "specialties") 28 | public class Specialty extends NamedEntity { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/Vets.java: -------------------------------------------------------------------------------- 1 | /* 2 | /* 3 | * Copyright 2002-2013 the original author or authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.springframework.samples.petclinic.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | /** 26 | * Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link 27 | * org.springframework.web.servlet.view.xml.MarshallingView}. 28 | * 29 | * @author Arjen Poutsma 30 | */ 31 | @XmlRootElement 32 | public class Vets { 33 | 34 | private List vets; 35 | 36 | @XmlElement 37 | public List getVetList() { 38 | if (vets == null) { 39 | vets = new ArrayList(); 40 | } 41 | return vets; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/model/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * The classes in this package represent PetClinic's business layer. 5 | * 6 | */ 7 | package org.springframework.samples.petclinic.model; 8 | 9 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.Vet; 22 | 23 | /** 24 | * Repository class for Vet domain objects All method names are compliant with Spring Data naming 25 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 26 | * 27 | * @author Ken Krebs 28 | * @author Juergen Hoeller 29 | * @author Sam Brannen 30 | * @author Michael Isvy 31 | */ 32 | public interface VetRepository { 33 | 34 | /** 35 | * Retrieve all Vets from the data store. 36 | * 37 | * @return a Collection of Vets 38 | */ 39 | Collection findAll() throws DataAccessException; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.BaseEntity; 22 | import org.springframework.samples.petclinic.model.Visit; 23 | 24 | /** 25 | * Repository class for Visit domain objects All method names are compliant with Spring Data naming 26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | * @author Sam Brannen 31 | * @author Michael Isvy 32 | */ 33 | public interface VisitRepository { 34 | 35 | /** 36 | * Save a Visit to the data store, either inserting or updating it. 37 | * 38 | * @param visit the Visit to save 39 | * @see BaseEntity#isNew 40 | */ 41 | void save(Visit visit) throws DataAccessException; 42 | 43 | List findByPetId(Integer petId); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import org.springframework.samples.petclinic.model.Pet; 19 | 20 | /** 21 | * Subclass of Pet that carries temporary id properties which are only relevant for a JDBC implementation of the 22 | * ClinicService. 23 | * 24 | * @author Juergen Hoeller 25 | */ 26 | class JdbcPet extends Pet { 27 | 28 | private int typeId; 29 | 30 | private int ownerId; 31 | 32 | 33 | public void setTypeId(int typeId) { 34 | this.typeId = typeId; 35 | } 36 | 37 | public int getTypeId() { 38 | return this.typeId; 39 | } 40 | 41 | public void setOwnerId(int ownerId) { 42 | this.ownerId = ownerId; 43 | } 44 | 45 | public int getOwnerId() { 46 | return this.ownerId; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import java.sql.ResultSet; 19 | import java.sql.SQLException; 20 | import java.util.Date; 21 | 22 | import org.joda.time.DateTime; 23 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 24 | 25 | /** 26 | * {@link BeanPropertyRowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties 27 | * of the {@link JdbcPet} class. 28 | */ 29 | class JdbcPetRowMapper extends BeanPropertyRowMapper { 30 | 31 | @Override 32 | public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException { 33 | JdbcPet pet = new JdbcPet(); 34 | pet.setId(rs.getInt("id")); 35 | pet.setName(rs.getString("name")); 36 | Date birthDate = rs.getDate("birth_date"); 37 | pet.setBirthDate(new DateTime(birthDate)); 38 | pet.setTypeId(rs.getInt("type_id")); 39 | pet.setOwnerId(rs.getInt("owner_id")); 40 | return pet; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * The classes in this package represent the JDBC implementation 5 | * of PetClinic's persistence layer. 6 | * 7 | */ 8 | package org.springframework.samples.petclinic.repository.jdbc; 9 | 10 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import java.util.List; 19 | 20 | import javax.persistence.EntityManager; 21 | import javax.persistence.PersistenceContext; 22 | 23 | import org.springframework.samples.petclinic.model.Pet; 24 | import org.springframework.samples.petclinic.model.PetType; 25 | import org.springframework.samples.petclinic.repository.PetRepository; 26 | import org.springframework.stereotype.Repository; 27 | 28 | /** 29 | * JPA implementation of the {@link PetRepository} interface. 30 | * 31 | * @author Mike Keith 32 | * @author Rod Johnson 33 | * @author Sam Brannen 34 | * @author Michael Isvy 35 | * @since 22.4.2006 36 | */ 37 | @Repository 38 | public class JpaPetRepositoryImpl implements PetRepository { 39 | 40 | @PersistenceContext 41 | private EntityManager em; 42 | 43 | @Override 44 | @SuppressWarnings("unchecked") 45 | public List findPetTypes() { 46 | return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList(); 47 | } 48 | 49 | @Override 50 | public Pet findById(int id) { 51 | return this.em.find(Pet.class, id); 52 | } 53 | 54 | @Override 55 | public void save(Pet pet) { 56 | if (pet.getId() == null) { 57 | this.em.persist(pet); 58 | } 59 | else { 60 | this.em.merge(pet); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import java.util.Collection; 19 | 20 | import javax.persistence.EntityManager; 21 | import javax.persistence.PersistenceContext; 22 | 23 | import org.springframework.cache.annotation.Cacheable; 24 | import org.springframework.samples.petclinic.model.Vet; 25 | import org.springframework.samples.petclinic.repository.VetRepository; 26 | import org.springframework.stereotype.Repository; 27 | 28 | /** 29 | * JPA implementation of the {@link VetRepository} interface. 30 | * 31 | * @author Mike Keith 32 | * @author Rod Johnson 33 | * @author Sam Brannen 34 | * @author Michael Isvy 35 | * @since 22.4.2006 36 | */ 37 | @Repository 38 | public class JpaVetRepositoryImpl implements VetRepository { 39 | 40 | @PersistenceContext 41 | private EntityManager em; 42 | 43 | 44 | @Override 45 | @Cacheable(value = "vets") 46 | @SuppressWarnings("unchecked") 47 | public Collection findAll() { 48 | return this.em.createQuery("SELECT distinct vet FROM Vet vet left join fetch vet.specialties ORDER BY vet.lastName, vet.firstName").getResultList(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * The classes in this package represent the JPA implementation 5 | * of PetClinic's persistence layer. 6 | * 7 | */ 8 | package org.springframework.samples.petclinic.repository.jpa; 9 | 10 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.data.jpa.repository.Query; 21 | import org.springframework.data.repository.Repository; 22 | import org.springframework.data.repository.query.Param; 23 | import org.springframework.samples.petclinic.model.Owner; 24 | import org.springframework.samples.petclinic.repository.OwnerRepository; 25 | 26 | /** 27 | * Spring Data JPA specialization of the {@link OwnerRepository} interface 28 | * 29 | * @author Michael Isvy 30 | * @since 15.1.2013 31 | */ 32 | public interface SpringDataOwnerRepository extends OwnerRepository, Repository { 33 | 34 | @Override 35 | @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%") 36 | public Collection findByLastName(@Param("lastName") String lastName); 37 | 38 | @Override 39 | @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id") 40 | public Owner findById(@Param("id") int id); 41 | } 42 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.data.jpa.repository.Query; 22 | import org.springframework.data.repository.Repository; 23 | import org.springframework.samples.petclinic.model.Pet; 24 | import org.springframework.samples.petclinic.model.PetType; 25 | import org.springframework.samples.petclinic.repository.PetRepository; 26 | 27 | /** 28 | * Spring Data JPA specialization of the {@link PetRepository} interface 29 | * 30 | * @author Michael Isvy 31 | * @since 15.1.2013 32 | */ 33 | public interface SpringDataPetRepository extends PetRepository, Repository { 34 | 35 | @Override 36 | @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name") 37 | List findPetTypes() throws DataAccessException; 38 | } 39 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import org.springframework.data.repository.Repository; 19 | import org.springframework.samples.petclinic.model.Vet; 20 | import org.springframework.samples.petclinic.repository.VetRepository; 21 | 22 | /** 23 | * Spring Data JPA specialization of the {@link VetRepository} interface 24 | * 25 | * @author Michael Isvy 26 | * @since 15.1.2013 27 | */ 28 | public interface SpringDataVetRepository extends VetRepository, Repository { 29 | } 30 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import org.springframework.data.repository.Repository; 19 | import org.springframework.samples.petclinic.model.Visit; 20 | import org.springframework.samples.petclinic.repository.VisitRepository; 21 | 22 | /** 23 | * Spring Data JPA specialization of the {@link VisitRepository} interface 24 | * 25 | * @author Michael Isvy 26 | * @since 15.1.2013 27 | */ 28 | public interface SpringDataVisitRepository extends VisitRepository, Repository { 29 | } 30 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/util/AuditMetaData.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.util; 2 | 3 | import org.audit4j.core.MetaData; 4 | 5 | public class AuditMetaData implements MetaData{ 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | @Override 10 | public String getActor() { 11 | return "annonymous"; 12 | } 13 | 14 | @Override 15 | public String getOrigin() { 16 | return "origin"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/CrashController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | 22 | /** 23 | * Controller used to showcase what happens when an exception is thrown 24 | * 25 | * @author Michael Isvy 26 | *

27 | * Also see how the bean of type 'SimpleMappingExceptionResolver' has been declared inside 28 | * /WEB-INF/mvc-core-config.xml 29 | */ 30 | @Controller 31 | public class CrashController { 32 | 33 | @RequestMapping(value = "/oups", method = RequestMethod.GET) 34 | public String triggerException() { 35 | throw new RuntimeException("Expected: controller used to showcase what " + 36 | "happens when an exception is thrown"); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import org.springframework.samples.petclinic.model.Pet; 19 | import org.springframework.util.StringUtils; 20 | import org.springframework.validation.Errors; 21 | 22 | /** 23 | * Validator for Pet forms. 24 | * 25 | * @author Ken Krebs 26 | * @author Juergen Hoeller 27 | */ 28 | public class PetValidator { 29 | 30 | public void validate(Pet pet, Errors errors) { 31 | String name = pet.getName(); 32 | // name validaation 33 | if (!StringUtils.hasLength(name)) { 34 | errors.rejectValue("name", "required", "required"); 35 | } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) { 36 | errors.rejectValue("name", "duplicate", "already exists"); 37 | } 38 | 39 | // type valication 40 | if (pet.isNew() && pet.getType() == null) { 41 | errors.rejectValue("type", "required", "required"); 42 | } 43 | 44 | // type valication 45 | if (pet.getBirthDate()==null) { 46 | errors.rejectValue("birthDate", "required", "required"); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/VetController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.samples.petclinic.model.Vets; 22 | import org.springframework.samples.petclinic.service.ClinicService; 23 | import org.springframework.stereotype.Controller; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | 26 | /** 27 | * @author Juergen Hoeller 28 | * @author Mark Fisher 29 | * @author Ken Krebs 30 | * @author Arjen Poutsma 31 | */ 32 | @Controller 33 | public class VetController { 34 | 35 | private final ClinicService clinicService; 36 | 37 | 38 | @Autowired 39 | public VetController(ClinicService clinicService) { 40 | this.clinicService = clinicService; 41 | } 42 | 43 | @RequestMapping("/vets") 44 | public String showVetList(Map model) { 45 | // Here we are returning an object of type 'Vets' rather than a collection of Vet objects 46 | // so it is simpler for Object-Xml mapping 47 | Vets vets = new Vets(); 48 | vets.getVetList().addAll(this.clinicService.findVets()); 49 | model.put("vets", vets); 50 | return "vets/vetList"; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * The classes in this package represent PetClinic's web presentation layer. 5 | * 6 | */ 7 | package org.springframework.samples.petclinic.web; 8 | 9 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | The Spring Data Binding framework, an internal library used by Spring Web Flow. 5 |

6 | 7 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/java/test.html: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 |

Organisation

18 | 19 |

Speakers

20 | 21 | 22 | 23 | 29 | 30 | 31 | 37 | 38 | 39 |
24 | Sergiu Bodiu 25 |

Sergiu Bodiu

26 |

Java Consultant at Bank of America

27 | Seasoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse. 28 |
32 | Sergiu Bodiu 33 |

Sergiu Bodiu

34 |

Java Consultant at Bank of America

35 | Seasoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse. 36 |
40 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/cache/ehcache.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/dandelion/datatables/datatables.properties: -------------------------------------------------------------------------------- 1 | # ================================== 2 | # Dandelion-Datatables configuration 3 | # ================================== 4 | 5 | # Disable the asset management of Dandelion-Core for all non-DataTable-related assets 6 | main.standalone=true -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/db/hsqldb/initDB.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE vet_specialties IF EXISTS; 2 | DROP TABLE vets IF EXISTS; 3 | DROP TABLE specialties IF EXISTS; 4 | DROP TABLE visits IF EXISTS; 5 | DROP TABLE pets IF EXISTS; 6 | DROP TABLE types IF EXISTS; 7 | DROP TABLE owners IF EXISTS; 8 | 9 | 10 | CREATE TABLE vets ( 11 | id INTEGER IDENTITY PRIMARY KEY, 12 | first_name VARCHAR(30), 13 | last_name VARCHAR(30) 14 | ); 15 | CREATE INDEX vets_last_name ON vets (last_name); 16 | 17 | CREATE TABLE specialties ( 18 | id INTEGER IDENTITY PRIMARY KEY, 19 | name VARCHAR(80) 20 | ); 21 | CREATE INDEX specialties_name ON specialties (name); 22 | 23 | CREATE TABLE vet_specialties ( 24 | vet_id INTEGER NOT NULL, 25 | specialty_id INTEGER NOT NULL 26 | ); 27 | ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id); 28 | ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id); 29 | 30 | CREATE TABLE types ( 31 | id INTEGER IDENTITY PRIMARY KEY, 32 | name VARCHAR(80) 33 | ); 34 | CREATE INDEX types_name ON types (name); 35 | 36 | CREATE TABLE owners ( 37 | id INTEGER IDENTITY PRIMARY KEY, 38 | first_name VARCHAR(30), 39 | last_name VARCHAR(30), 40 | address VARCHAR(255), 41 | city VARCHAR(80), 42 | telephone VARCHAR(20) 43 | ); 44 | CREATE INDEX owners_last_name ON owners (last_name); 45 | 46 | CREATE TABLE pets ( 47 | id INTEGER IDENTITY PRIMARY KEY, 48 | name VARCHAR(30), 49 | birth_date DATE, 50 | type_id INTEGER NOT NULL, 51 | owner_id INTEGER NOT NULL 52 | ); 53 | ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id); 54 | ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id); 55 | CREATE INDEX pets_name ON pets (name); 56 | 57 | CREATE TABLE visits ( 58 | id INTEGER IDENTITY PRIMARY KEY, 59 | pet_id INTEGER NOT NULL, 60 | visit_date DATE, 61 | description VARCHAR(255) 62 | ); 63 | ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id); 64 | CREATE INDEX visits_pet_id ON visits (pet_id); 65 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/db/mysql/initDB.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS petclinic; 2 | GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; 3 | 4 | USE petclinic; 5 | 6 | CREATE TABLE IF NOT EXISTS vets ( 7 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 8 | first_name VARCHAR(30), 9 | last_name VARCHAR(30), 10 | INDEX(last_name) 11 | ) engine=InnoDB; 12 | 13 | CREATE TABLE IF NOT EXISTS specialties ( 14 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 15 | name VARCHAR(80), 16 | INDEX(name) 17 | ) engine=InnoDB; 18 | 19 | CREATE TABLE IF NOT EXISTS vet_specialties ( 20 | vet_id INT(4) UNSIGNED NOT NULL, 21 | specialty_id INT(4) UNSIGNED NOT NULL, 22 | FOREIGN KEY (vet_id) REFERENCES vets(id), 23 | FOREIGN KEY (specialty_id) REFERENCES specialties(id), 24 | UNIQUE (vet_id,specialty_id) 25 | ) engine=InnoDB; 26 | 27 | CREATE TABLE IF NOT EXISTS types ( 28 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 29 | name VARCHAR(80), 30 | INDEX(name) 31 | ) engine=InnoDB; 32 | 33 | CREATE TABLE IF NOT EXISTS owners ( 34 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 35 | first_name VARCHAR(30), 36 | last_name VARCHAR(30), 37 | address VARCHAR(255), 38 | city VARCHAR(80), 39 | telephone VARCHAR(20), 40 | INDEX(last_name) 41 | ) engine=InnoDB; 42 | 43 | CREATE TABLE IF NOT EXISTS pets ( 44 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 45 | name VARCHAR(30), 46 | birth_date DATE, 47 | type_id INT(4) UNSIGNED NOT NULL, 48 | owner_id INT(4) UNSIGNED NOT NULL, 49 | INDEX(name), 50 | FOREIGN KEY (owner_id) REFERENCES owners(id), 51 | FOREIGN KEY (type_id) REFERENCES types(id) 52 | ) engine=InnoDB; 53 | 54 | CREATE TABLE IF NOT EXISTS visits ( 55 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 56 | pet_id INT(4) UNSIGNED NOT NULL, 57 | visit_date DATE, 58 | description VARCHAR(255), 59 | FOREIGN KEY (pet_id) REFERENCES pets(id) 60 | ) engine=InnoDB; -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | === Spring PetClinic sample application - MySQL Configuration === 3 | ================================================================================ 4 | 5 | @author Sam Brannen 6 | @author Costin Leau 7 | 8 | -------------------------------------------------------------------------------- 9 | 10 | 1) Download and install the MySQL database (e.g., MySQL Community Server 5.1.x), 11 | which can be found here: http://dev.mysql.com/downloads/ 12 | 13 | 2) Download Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x), which 14 | can be found here: http://dev.mysql.com/downloads/connector/j/ 15 | Copy the Connector/J JAR file (e.g., mysql-connector-java-5.1.5-bin.jar) into 16 | the db/mysql directory. Alternatively, uncomment the mysql-connector from the 17 | Petclinic pom. 18 | 19 | 3) Create the PetClinic database and user by executing the "db/mysql/createDB.txt" 20 | script. 21 | 22 | 4) Open "src/main/resources/spring/jdbc.properties"; comment out all properties in the 23 | "HSQL Settings" section; uncomment all properties in the "MySQL Settings" 24 | section. -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/db_readme.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | === Spring PetClinic sample application - Database Configuration === 3 | ================================================================================ 4 | 5 | @author Costin Leau 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | In its default configuration, Petclinic uses an in-memory database (HSQLDB) which 10 | gets populated at startup with data. A similar setup is provided for Mysql in case 11 | a persistent database configuration is needed. 12 | Note that whenever the database type is changed, the data-access.properties file needs to 13 | be updated. 14 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | %-5level %logger{0} - %msg%n 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/messages/messages.properties: -------------------------------------------------------------------------------- 1 | welcome=Welcome 2 | required=is required 3 | notFound=has not been found 4 | duplicate=is already in use 5 | nonNumeric=must be all numeric 6 | duplicateFormSubmission=Duplicate form submission is not allowed 7 | typeMismatch.date=invalid date 8 | typeMismatch.birthDate=invalid date 9 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/messages/messages_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/resources/messages/messages_de.properties -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/messages/messages_en.properties: -------------------------------------------------------------------------------- 1 | # This file is intentionally empty. Message look-ups will fall back to the default "messages.properties" file. -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/resources/spring/data-access.properties: -------------------------------------------------------------------------------- 1 | # Properties file with JDBC and JPA settings. 2 | # 3 | # Applied by from 4 | # various application context XML files (e.g., "applicationContext-*.xml"). 5 | # Targeted at system administrators, to avoid touching the context XML files. 6 | 7 | #------------------------------------------------------------------------------- 8 | # HSQL Settings 9 | 10 | jdbc.driverClassName=org.hsqldb.jdbcDriver 11 | jdbc.url=jdbc:hsqldb:mem:petclinic 12 | jdbc.username=audit4j 13 | jdbc.password=audit4j 14 | 15 | # Properties that control the population of schema and data for a new data source 16 | jdbc.initLocation=classpath:db/hsqldb/initDB.sql 17 | jdbc.dataLocation=classpath:db/hsqldb/populateDB.sql 18 | 19 | # Property that determines which database to use with an AbstractJpaVendorAdapter 20 | jpa.database=HSQL 21 | 22 | jpa.showSql=false 23 | 24 | #------------------------------------------------------------------------------- 25 | # MySQL Settings 26 | 27 | #jdbc.driverClassName=com.mysql.jdbc.Driver 28 | #jdbc.url=jdbc:mysql://localhost:3306/petclinic 29 | #jdbc.username=root 30 | #jdbc.password= 31 | 32 | # Properties that control the population of schema and data for a new data source 33 | #jdbc.initLocation=classpath:db/mysql/initDB.sql 34 | #jdbc.dataLocation=classpath:db/mysql/populateDB.sql 35 | 36 | # Property that determines which Hibernate dialect to use 37 | # (only applied with "applicationContext-hibernate.xml") 38 | #hibernate.dialect=org.hibernate.dialect.MySQLDialect 39 | 40 | # Property that determines which database to use with an AbstractJpaVendorAdapter 41 | #jpa.database=MYSQL 42 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/exception.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 |

Something happened...

16 | 17 |

${exception.message}

18 | 19 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 3 | 4 | 5 | 6 | 7 | 22 | 23 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/fragments/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | 3 | 6 | 7 | 8 | 9 | PetClinic :: a Spring Framework demonstration 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 6 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 7 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 8 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |

24 | New Owner 25 |

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 |
44 |
45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 6 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 |

Find Owners

17 | 18 | 19 | 21 |
22 |
23 | 24 | 25 | 26 |
27 |
28 | 29 |
30 |
31 |
32 | 33 |
34 | Add Owner 35 | 36 | 37 | 38 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 6 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 7 | <%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %> 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |

Owners

17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 6 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |

31 | New 32 | Pet 33 |

34 | 35 | 37 |
38 | 39 | 40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 |
62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 6 | <%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 |

Veterinarians

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | none 28 | 29 | 30 | 31 | 32 | 33 | 36 | 39 | 40 |
34 | ">View as XML 35 | 37 | ">Subscribe to Atom feed 38 |
41 | 42 | 43 |
44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/jsp/welcome.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |

15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/no-spring-config-files-there.txt: -------------------------------------------------------------------------------- 1 | All Spring config files (including Spring MVC ones) are inside src/main/resource. 2 | There are mostly 2 reasons to that: 3 | - All Spring config files are grouped into one single place 4 | - It is simpler to reference them from inside JUnit tests -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/tags/inputField.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ attribute name="name" required="true" rtexprvalue="true" 5 | description="Name of corresponding property in bean object" %> 6 | <%@ attribute name="label" required="true" rtexprvalue="true" 7 | description="Label appears in red color if input is considered as invalid after submission" %> 8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 | 16 | ${status.errorMessage} 17 |
18 |
19 |
-------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/WEB-INF/tags/selectField.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ attribute name="name" required="true" rtexprvalue="true" 5 | description="Name of corresponding property in bean object" %> 6 | <%@ attribute name="label" required="true" rtexprvalue="true" 7 | description="Label appears in red color if input is considered as invalid after submission" %> 8 | <%@ attribute name="names" required="true" rtexprvalue="true" type="java.util.List" 9 | description="Names in the list" %> 10 | <%@ attribute name="size" required="true" rtexprvalue="true" 11 | description="Size of Select" %> 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | ${status.errorMessage} 21 |
22 |
23 |
-------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/css/petclinic.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding-top: 10px; 3 | margin-left: 50px; 4 | width: 700px; 5 | } 6 | 7 | .form-horizontal { 8 | width: 100%; 9 | } 10 | 11 | input[type="text"] { 12 | height: 25px; 13 | } 14 | 15 | .navbar .nav > li > a { 16 | color: #000000; 17 | } 18 | 19 | .form-horizontal .control-label { 20 | text-align: left; 21 | } 22 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/banner-graphic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/banner-graphic.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/bullet-arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/bullet-arrow.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/pets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/pets.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/spring-pivotal-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/spring-pivotal-logo.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/springsource-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/springsource-logo.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/main/webapp/resources/images/submit-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-demo-spring-petclinic/src/main/webapp/resources/images/submit-bg.png -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.model; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.Locale; 6 | import java.util.Set; 7 | 8 | import javax.validation.ConstraintViolation; 9 | import javax.validation.Validator; 10 | 11 | import org.assertj.core.api.Assertions; 12 | import org.junit.Assert; 13 | import org.junit.Test; 14 | import org.springframework.context.i18n.LocaleContextHolder; 15 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; 16 | 17 | /** 18 | * 19 | * @author Michael Isvy 20 | * Simple test to make sure that Bean Validation is working 21 | * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) 22 | * 23 | */ 24 | public class ValidatorTests { 25 | 26 | private Validator createValidator() { 27 | LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); 28 | localValidatorFactoryBean.afterPropertiesSet(); 29 | return localValidatorFactoryBean; 30 | } 31 | 32 | @Test 33 | public void shouldNotValidateWhenFirstNameEmpty() { 34 | 35 | LocaleContextHolder.setLocale(Locale.ENGLISH); 36 | Person person = new Person(); 37 | person.setFirstName(""); 38 | person.setLastName("smith"); 39 | 40 | Validator validator = createValidator(); 41 | Set> constraintViolations = validator.validate(person); 42 | 43 | Assert.assertEquals(1, constraintViolations.size()); 44 | ConstraintViolation violation = constraintViolations.iterator().next(); 45 | assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); 46 | assertThat(violation.getMessage()).isEqualTo("may not be empty"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.service; 17 | 18 | import org.junit.runner.RunWith; 19 | import org.springframework.test.context.ActiveProfiles; 20 | import org.springframework.test.context.ContextConfiguration; 21 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 | 23 | /** 24 | *

Integration test using the jdbc profile. 25 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

26 | * 27 | * @author Thomas Risberg 28 | * @author Michael Isvy 29 | */ 30 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 31 | @RunWith(SpringJUnit4ClassRunner.class) 32 | @ActiveProfiles("jdbc") 33 | public class ClinicServiceJdbcTests extends AbstractClinicServiceTests { 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java: -------------------------------------------------------------------------------- 1 | 2 | package org.springframework.samples.petclinic.service; 3 | 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.ActiveProfiles; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | /** 10 | *

Integration test using the jpa profile. 11 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

12 | * 13 | * @author Rod Johnson 14 | * @author Sam Brannen 15 | * @author Michael Isvy 16 | */ 17 | 18 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ActiveProfiles("jpa") 21 | public class ClinicServiceJpaTests extends AbstractClinicServiceTests { 22 | 23 | } -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java: -------------------------------------------------------------------------------- 1 | 2 | package org.springframework.samples.petclinic.service; 3 | 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.ActiveProfiles; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | /** 10 | *

Integration test using the 'Spring Data' profile. 11 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

12 | * @author Michael Isvy 13 | */ 14 | 15 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ActiveProfiles("spring-data-jpa") 18 | public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { 19 | 20 | } -------------------------------------------------------------------------------- /audit4j-demo-spring-petclinic/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /audit4j-demo-spring/.gitignore: -------------------------------------------------------------------------------- 1 | audit4jdb* -------------------------------------------------------------------------------- /audit4j-demo-spring/README.md: -------------------------------------------------------------------------------- 1 | # Spring demo project 2 | Sample audit4j applications. 3 | 4 | To deploy the application: mvn jetty:run and access using http://localhost:8091 -------------------------------------------------------------------------------- /audit4j-demo-spring/audit4jdb.lck: -------------------------------------------------------------------------------- 1 | HSQLLOCKV0a -------------------------------------------------------------------------------- /audit4j-demo-spring/audit4jdb.log: -------------------------------------------------------------------------------- 1 | /*C3*/SET SCHEMA PUBLIC 2 | create table if not exists audit (uuid varchar(200) NOT NULL,timestamp varchar(100) NOT NULL,actor varchar(200) NOT NULL,origin varchar(200),action varchar(200) NOT NULL,elements varchar(20000)) 3 | DISCONNECT 4 | -------------------------------------------------------------------------------- /audit4j-demo-spring/audit4jdb.properties: -------------------------------------------------------------------------------- 1 | #HSQL Database Engine 2.3.2 2 | #Wed Jul 27 23:00:50 IST 2016 3 | version=2.3.2 4 | modified=yes 5 | -------------------------------------------------------------------------------- /audit4j-demo-spring/audit4jdb.script: -------------------------------------------------------------------------------- 1 | SET DATABASE UNIQUE NAME HSQLDB562D19B36C 2 | SET DATABASE GC 0 3 | SET DATABASE DEFAULT RESULT MEMORY ROWS 0 4 | SET DATABASE EVENT LOG LEVEL 0 5 | SET DATABASE TRANSACTION CONTROL LOCKS 6 | SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED 7 | SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE 8 | SET DATABASE TEXT TABLE DEFAULTS '' 9 | SET DATABASE SQL NAMES FALSE 10 | SET DATABASE SQL REFERENCES FALSE 11 | SET DATABASE SQL SIZE TRUE 12 | SET DATABASE SQL TYPES FALSE 13 | SET DATABASE SQL TDC DELETE TRUE 14 | SET DATABASE SQL TDC UPDATE TRUE 15 | SET DATABASE SQL TRANSLATE TTI TYPES TRUE 16 | SET DATABASE SQL CONCAT NULLS TRUE 17 | SET DATABASE SQL UNIQUE NULLS TRUE 18 | SET DATABASE SQL CONVERT TRUNCATE TRUE 19 | SET DATABASE SQL AVG SCALE 0 20 | SET DATABASE SQL DOUBLE NAN TRUE 21 | SET FILES WRITE DELAY 500 MILLIS 22 | SET FILES BACKUP INCREMENT TRUE 23 | SET FILES CACHE SIZE 10000 24 | SET FILES CACHE ROWS 50000 25 | SET FILES SCALE 32 26 | SET FILES LOB SCALE 32 27 | SET FILES DEFRAG 0 28 | SET FILES NIO TRUE 29 | SET FILES NIO SIZE 256 30 | SET FILES LOG TRUE 31 | SET FILES LOG SIZE 50 32 | CREATE USER "audit4jdbuser" PASSWORD DIGEST '70d986a5af9ae45d66a7e87b0be79b5c' 33 | ALTER USER "audit4jdbuser" SET LOCAL TRUE 34 | CREATE SCHEMA PUBLIC AUTHORIZATION DBA 35 | SET SCHEMA PUBLIC 36 | CREATE MEMORY TABLE PUBLIC.AUDIT(UUID VARCHAR(200) NOT NULL,TIMESTAMP VARCHAR(100) NOT NULL,ACTOR VARCHAR(200) NOT NULL,ORIGIN VARCHAR(200),ACTION VARCHAR(200) NOT NULL,ELEMENTS VARCHAR(20000)) 37 | ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1 38 | SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC 39 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC 40 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC 41 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC 42 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC 43 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC 44 | GRANT DBA TO "audit4jdbuser" 45 | SET SCHEMA SYSTEM_LOBS 46 | INSERT INTO BLOCKS VALUES(0,2147483647,0) 47 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.springframework.web.servlet.view.JstlView; 9 | 10 | @EnableWebMvc 11 | @Configuration 12 | @ComponentScan({ "org.audt4j.demo.spring.*" }) 13 | public class AppConfig { 14 | 15 | @Bean 16 | public InternalResourceViewResolver viewResolver() { 17 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 18 | viewResolver.setViewClass(JstlView.class); 19 | viewResolver.setPrefix("/WEB-INF/pages/"); 20 | viewResolver.setSuffix(".jsp"); 21 | return viewResolver; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/config/AuditMetaData.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.config; 2 | 3 | import javax.servlet.ServletRequest; 4 | 5 | import org.audit4j.core.MetaData; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.security.core.context.SecurityContextHolder; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | 12 | public class AuditMetaData implements MetaData{ 13 | private static final long serialVersionUID = 7243065407615627372L; 14 | 15 | @Override 16 | public String getOrigin() { 17 | try { 18 | return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr(); 19 | }catch(Exception e){ 20 | e.printStackTrace(); 21 | } 22 | return "unidentified"; 23 | } 24 | 25 | @Override 26 | public String getActor() { 27 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 28 | if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { 29 | return ((UserDetails) authentication.getPrincipal()).getUsername(); 30 | } 31 | return "anonymous"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | 10 | @Configuration 11 | @EnableWebSecurity 12 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 13 | 14 | @Autowired 15 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 16 | auth.inMemoryAuthentication().withUser("test").password("123").roles("USER"); 17 | } 18 | 19 | //.csrf() is optional, enabled by default, if using WebSecurityConfigurerAdapter constructor 20 | @Override 21 | protected void configure(HttpSecurity http) throws Exception { 22 | 23 | http.authorizeRequests() 24 | .antMatchers("/demo/**").access("hasRole('ROLE_USER')") 25 | //.antMatchers("/auditDemo/**").access("hasRole('ROLE_USER')") 26 | .and() 27 | .formLogin().loginPage("/login").failureUrl("/login?error") 28 | .usernameParameter("username").passwordParameter("password") 29 | 30 | .and() 31 | .logout().logoutSuccessUrl("/login?logout") 32 | .and() 33 | .csrf(); 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/config/core/SpringMvcInitializer.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.config.core; 2 | 3 | import org.audt4j.demo.spring.config.AppConfig; 4 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 5 | 6 | 7 | public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 8 | 9 | @Override 10 | protected Class[] getRootConfigClasses() { 11 | return new Class[] { AppConfig.class }; 12 | } 13 | 14 | @Override 15 | protected Class[] getServletConfigClasses() { 16 | return null; 17 | } 18 | 19 | @Override 20 | protected String[] getServletMappings() { 21 | return new String[] { "/" }; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/config/core/SpringSecurityInitializer.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.config.core; 2 | 3 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 4 | 5 | public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer { 6 | 7 | } -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/model/Payment.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.audt4j.demo.spring.service.Item; 7 | 8 | public class Payment { 9 | 10 | private Double totalPrize; 11 | 12 | private String user; 13 | 14 | private List items = new ArrayList(); 15 | 16 | public Payment(String user, Double totalPrize, Item item){ 17 | this.user = user; 18 | this.totalPrize = totalPrize; 19 | this.items.add(item); 20 | } 21 | 22 | public Payment(){} 23 | 24 | public Double getTotalPrize() { 25 | return totalPrize; 26 | } 27 | 28 | public void setTotalPrize(Double totalPrize) { 29 | this.totalPrize = totalPrize; 30 | } 31 | 32 | public String getUser() { 33 | return user; 34 | } 35 | 36 | public void setUser(String user) { 37 | this.user = user; 38 | } 39 | 40 | public List getItems() { 41 | return items; 42 | } 43 | 44 | public void setItems(List items) { 45 | this.items = items; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/InventoryService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service; 2 | 3 | 4 | public interface InventoryService { 5 | 6 | void addItem(Item item); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/Item.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service; 2 | 3 | 4 | public class Item { 5 | 6 | private String name; 7 | 8 | private Double value; 9 | 10 | public Item(){ 11 | 12 | } 13 | 14 | public Item(String name, Double value){ 15 | this.name=name; 16 | this.value = value; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public Double getValue() { 28 | return value; 29 | } 30 | 31 | public void setValue(Double value) { 32 | this.value = value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.audt4j.demo.spring.model.Payment; 7 | 8 | public interface PaymentService { 9 | 10 | void checkout(Payment payment); 11 | 12 | void savePayment(String userId, List items); 13 | 14 | void saveCreditCard(String validName, Date expiry, String cardNumber); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/UserService.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service; 2 | 3 | import org.audt4j.demo.spring.model.User; 4 | 5 | public interface UserService { 6 | 7 | 8 | void saveUser(User user); 9 | 10 | User getUserByuserName(String userName); 11 | 12 | void login(String userName, String password); 13 | 14 | void changePassword(String oldPassword, String newPassword); 15 | } 16 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/impl/InventoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service.impl; 2 | 3 | import org.audit4j.core.AuditManager; 4 | import org.audit4j.core.dto.EventBuilder; 5 | import org.audt4j.demo.spring.service.InventoryService; 6 | import org.audt4j.demo.spring.service.Item; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service("inventoryService") 10 | public class InventoryServiceImpl implements InventoryService { 11 | 12 | @Override 13 | public void addItem(Item item) { 14 | AuditManager.getInstance().audit( 15 | new EventBuilder().addAction("addInventoryItem").addField("itemName", item.getName()) 16 | .addField("itemValue", item.getValue()).build()); 17 | 18 | //Method Body 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/impl/PaymentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service.impl; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.audit4j.core.annotation.Audit; 7 | import org.audit4j.core.annotation.AuditField; 8 | import org.audit4j.core.annotation.DeIdentify; 9 | import org.audt4j.demo.spring.model.Payment; 10 | import org.audt4j.demo.spring.service.Item; 11 | import org.audt4j.demo.spring.service.PaymentService; 12 | import org.springframework.stereotype.Service; 13 | 14 | @Service("paymentService") 15 | public class PaymentServiceImpl implements PaymentService { 16 | 17 | @Override 18 | @Audit 19 | public void savePayment(@AuditField(field = "paymentUserId") String userId, 20 | @AuditField(field = "paymentItems") List items) { 21 | 22 | } 23 | 24 | @Override 25 | @Audit 26 | public void saveCreditCard(@AuditField(field = "cardUserName") String validName, 27 | @AuditField(field = "expiryDate") Date expiry, 28 | @AuditField(field = "cardNumber") @DeIdentify(fromRight = 4) String cardNumber) { 29 | 30 | } 31 | 32 | @Override 33 | @Audit(action = "checkoutPayment") 34 | public void checkout(Payment payment) { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.service.impl; 2 | 3 | import org.audit4j.core.annotation.Audit; 4 | import org.audit4j.core.annotation.DeIdentify; 5 | import org.audit4j.core.annotation.IgnoreAudit; 6 | import org.audt4j.demo.spring.model.User; 7 | import org.audt4j.demo.spring.service.UserService; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service("userService") 11 | @Audit 12 | public class UserServiceImpl implements UserService { 13 | 14 | @Override 15 | public void login(String userName, @DeIdentify String password) { 16 | // Method Body 17 | 18 | } 19 | 20 | @Override 21 | public User getUserByuserName(String userName) { 22 | return new User("admin"); 23 | } 24 | 25 | @Override 26 | public void saveUser(User user) { 27 | // Method Body 28 | 29 | } 30 | 31 | @Override 32 | @IgnoreAudit 33 | public void changePassword(String oldPassword, String newPassword) { 34 | // Method Body 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/java/org/audt4j/demo/spring/web/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.audt4j.demo.spring.web.controller; 2 | 3 | import org.audt4j.demo.spring.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | @Controller 12 | public class HelloController { 13 | 14 | @Autowired 15 | private UserService userService; 16 | 17 | @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET) 18 | public ModelAndView welcomePage() { 19 | 20 | ModelAndView model = new ModelAndView(); 21 | model.setViewName("hello"); 22 | return model; 23 | } 24 | 25 | @RequestMapping(value = "/demo**", method = RequestMethod.GET) 26 | public ModelAndView adminPage() { 27 | ModelAndView model = new ModelAndView(); 28 | model.addObject("title", "Sample Secured page"); 29 | model.addObject("message", "This is protected page!"); 30 | model.setViewName("demo"); 31 | return model; 32 | } 33 | 34 | // @Audit 35 | @RequestMapping(value = "/login", method = RequestMethod.GET) 36 | public ModelAndView login(@RequestParam(value = "error", required = false) String error, 37 | @RequestParam(value = "logout", required = false) String logout) { 38 | userService.login("test", "123"); 39 | ModelAndView model = new ModelAndView(); 40 | if (error != null) { 41 | model.addObject("error", "Invalid username and password!"); 42 | } 43 | 44 | if (logout != null) { 45 | model.addObject("msg", "You've been logged out successfully."); 46 | } 47 | model.setViewName("login"); 48 | return model; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/resources/audit4j.conf.yaml: -------------------------------------------------------------------------------- 1 | # To Activate this configuration, remove or comment Spring configuration. 2 | # see @org.audt4j.demo.spring.config.AuditConfig for more details. 3 | 4 | !Configuration 5 | handlers: 6 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 7 | layout: !org.audit4j.core.layout.SimpleLayout {} 8 | metaData: !org.audt4j.demo.spring.config.AuditMetaData {} 9 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/webapp/WEB-INF/pages/admin.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | <%@page session="true"%> 3 | 4 | 5 |

Title : ${title}

6 |

Message : ${message}

7 | 8 | 9 |
10 | 12 |
13 | 18 | 19 | 20 |

21 | Welcome : ${pageContext.request.userPrincipal.name} | Logout 23 |

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/webapp/WEB-INF/pages/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@page session="false"%> 2 | 3 | 4 | 5 |

Welcome to audit4j spring demo application

6 |

Please login before access the Demo Page

7 | 8 | User: test
9 | Passeord: 123 10 | 11 | -------------------------------------------------------------------------------- /audit4j-demo-spring/src/main/webapp/WEB-INF/pages/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 | 3 | 4 | Login Page 5 | 36 | 37 | 38 | 39 |

Login

40 | 41 |
42 | 43 |

Login with Username and Password

44 | 45 | 46 |
${error}
47 |
48 | 49 |
${msg}
50 |
51 | 52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 66 | 67 |
User:
Password:
68 | 69 | 71 | 72 |
73 |
74 | 75 | 76 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/README.md: -------------------------------------------------------------------------------- 1 | # Spring demo project 2 | Sample audit4j applications. 3 | 4 | To deploy the application: mvn jetty:run and access using http://localhost:8091 5 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/java/hello/Application.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class Application { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/java/hello/AuditMetaData.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.servlet.ServletRequest; 7 | 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.audit4j.core.MetaData; 10 | import org.springframework.security.core.Authentication; 11 | import org.springframework.security.core.GrantedAuthority; 12 | import org.springframework.security.core.context.SecurityContextHolder; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.web.context.request.RequestContextHolder; 15 | import org.springframework.web.context.request.ServletRequestAttributes; 16 | 17 | public class AuditMetaData implements MetaData { 18 | 19 | private static final long serialVersionUID = 7243065407615627372L; 20 | 21 | @Override 22 | public String getOrigin() { 23 | try { 24 | return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr(); 25 | }catch(Exception e){ 26 | e.printStackTrace(); 27 | } 28 | return "unidentified"; 29 | } 30 | 31 | @Override 32 | public String getActor() { 33 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 34 | if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { 35 | return ((UserDetails) authentication.getPrincipal()).getUsername()+ " "+getRoles(); 36 | } 37 | return "anonymous"; 38 | } 39 | 40 | //how to have a string giving the list of roles that the user has 41 | private String getRoles() { 42 | 43 | List roles = new ArrayList(); 44 | for( GrantedAuthority author :SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { 45 | roles.add(author.toString()); 46 | } 47 | if(roles.isEmpty()) { 48 | return "no role"; 49 | } else 50 | return "roles=["+StringUtils.join(roles, ",")+ "]"; 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/java/hello/GreetingController.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.audit4j.core.annotation.Audit; 4 | import org.audit4j.core.annotation.AuditField; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | 10 | 11 | @Controller 12 | public class GreetingController { 13 | 14 | static Logger LOGGER = LoggerFactory.getLogger(GreetingController.class); 15 | 16 | @Audit 17 | @RequestMapping("/hello") 18 | public String hello() { 19 | LOGGER.info("hello called"); 20 | return "hello"; 21 | } 22 | 23 | @Audit 24 | public void foo1(@AuditField(field="stringOne") String string1, @AuditField(field="stringTwo") String string2) { 25 | // TODO Auto-generated method stub 26 | 27 | } 28 | 29 | @Audit 30 | public void foo2(String string1, String string2) { 31 | // TODO Auto-generated method stub 32 | 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/java/hello/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class MvcConfig extends WebMvcConfigurerAdapter { 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/home").setViewName("home"); 13 | registry.addViewController("/").setViewName("home"); 14 | //registry.addViewController("/hello").setViewName("hello"); 15 | registry.addViewController("/login").setViewName("login"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/java/hello/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | 10 | @Configuration 11 | @EnableWebSecurity 12 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 13 | @Override 14 | protected void configure(HttpSecurity http) throws Exception { 15 | http 16 | .authorizeRequests() 17 | .antMatchers("/", "/home").permitAll() 18 | .anyRequest().authenticated() 19 | .and() 20 | .formLogin() 21 | .loginPage("/login") 22 | .permitAll() 23 | .and() 24 | .logout() 25 | .permitAll(); 26 | } 27 | 28 | @Autowired 29 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 30 | auth. 31 | inMemoryAuthentication() 32 | .withUser("user").password("password").roles("USER","USER2") 33 | .and() 34 | .withUser("user2").password("password2").roles("USER","USER2"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Hello World! 6 | 7 | 8 |

Hello [[${#httpServletRequest.remoteUser}]]!

9 |
10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Spring Security Example 5 | 6 | 7 |

Welcome!

8 | 9 |

Click here to see a greeting.

10 | 11 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Spring Security Example 6 | 7 | 8 |
9 | Invalid username and password. 10 |
11 |
12 | You have been logged out. 13 |
14 |
15 |
16 |
17 |
18 |
19 | 20 | -------------------------------------------------------------------------------- /audit4j-demo-springboot/src/test/java/hello/GreetingControllerTest.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class GreetingControllerTest { 13 | 14 | @Autowired 15 | private GreetingController greetingController; 16 | 17 | @Test 18 | public void test() { 19 | //greetingController.hello(); 20 | greetingController.foo1("e1","e2"); 21 | greetingController.foo2("f1","f2"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/Application.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class Application { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/AuditMetaData.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.servlet.ServletRequest; 7 | 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.audit4j.core.MetaData; 10 | import org.springframework.security.core.Authentication; 11 | import org.springframework.security.core.GrantedAuthority; 12 | import org.springframework.security.core.context.SecurityContextHolder; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.web.context.request.RequestContextHolder; 15 | import org.springframework.web.context.request.ServletRequestAttributes; 16 | 17 | public class AuditMetaData implements MetaData { 18 | 19 | private static final long serialVersionUID = 7243065407615627372L; 20 | 21 | @Override 22 | public String getOrigin() { 23 | try { 24 | return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr(); 25 | }catch(Exception e){ 26 | e.printStackTrace(); 27 | } 28 | return "unidentified"; 29 | } 30 | 31 | @Override 32 | public String getActor() { 33 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 34 | if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { 35 | return ((UserDetails) authentication.getPrincipal()).getUsername()+ " "+getRoles(); 36 | } 37 | return "anonymous"; 38 | } 39 | 40 | //how to have a string giving the list of roles that the user has 41 | private String getRoles() { 42 | 43 | List roles = new ArrayList(); 44 | for( GrantedAuthority author :SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { 45 | roles.add(author.toString()); 46 | } 47 | if(roles.isEmpty()) { 48 | return "no role"; 49 | } else 50 | return "roles=["+StringUtils.join(roles, ",")+ "]"; 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/GreetingController.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import org.audit4j.core.annotation.Audit; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | 13 | import hello.data.User; 14 | 15 | 16 | @Controller 17 | public class GreetingController { 18 | 19 | static Logger LOGGER = LoggerFactory.getLogger(GreetingController.class); 20 | 21 | @Audit 22 | @RequestMapping("/hello") 23 | public String hello() { 24 | LOGGER.info("hello called"); 25 | return "hello"; 26 | } 27 | 28 | @Audit 29 | public void foo1(User[] d1, BigDecimal d2) { 30 | // TODO Auto-generated method stub 31 | 32 | } 33 | 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class MvcConfig extends WebMvcConfigurerAdapter { 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/home").setViewName("home"); 13 | registry.addViewController("/").setViewName("home"); 14 | //registry.addViewController("/hello").setViewName("hello"); 15 | registry.addViewController("/login").setViewName("login"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | 10 | @Configuration 11 | @EnableWebSecurity 12 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 13 | @Override 14 | protected void configure(HttpSecurity http) throws Exception { 15 | http 16 | .authorizeRequests() 17 | .antMatchers("/", "/home").permitAll() 18 | .anyRequest().authenticated() 19 | .and() 20 | .formLogin() 21 | .loginPage("/login") 22 | .permitAll() 23 | .and() 24 | .logout() 25 | .permitAll(); 26 | } 27 | 28 | @Autowired 29 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 30 | auth. 31 | inMemoryAuthentication() 32 | .withUser("user").password("password").roles("USER","USER2") 33 | .and() 34 | .withUser("user2").password("password2").roles("USER","USER2"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/data/Address.java: -------------------------------------------------------------------------------- 1 | package hello.data; 2 | 3 | public class Address { 4 | 5 | private String city; 6 | private String postCode; 7 | 8 | public String getCity() { 9 | return city; 10 | } 11 | public void setCity(String city) { 12 | this.city = city; 13 | } 14 | public String getPostCode() { 15 | return postCode; 16 | } 17 | public void setPostCode(String postCode) { 18 | this.postCode = postCode; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Address [city=" + city + ", postCode=" + postCode + "]"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/main/java/hello/data/User.java: -------------------------------------------------------------------------------- 1 | package hello.data; 2 | 3 | public class User { 4 | 5 | private String lastName; 6 | private String firtName; 7 | private Address address; 8 | private Double val =1.0; 9 | 10 | public String getLastName() { 11 | return lastName; 12 | } 13 | 14 | public void setLastName(String lastName) { 15 | this.lastName = lastName; 16 | } 17 | 18 | public String getFirtName() { 19 | return firtName; 20 | } 21 | 22 | public void setFirtName(String firtName) { 23 | this.firtName = firtName; 24 | } 25 | 26 | public Address getAddress() { 27 | return address; 28 | } 29 | 30 | public void setAddress(Address address) { 31 | this.address = address; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "User [lastName=" + lastName + ", firtName=" + firtName + ", address=" + address + ", val=" + val + "]"; 37 | } 38 | 39 | 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/hello/SpringBootAuditedTest.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import com.tngtech.jgiven.junit.ScenarioTest; 15 | 16 | import hello.data.User; 17 | import hello.stage.GivenSomeState; 18 | import hello.stage.ThenSomeOutcome; 19 | import hello.stage.WhenSomeAction; 20 | 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest 23 | public class SpringBootAuditedTest 24 | extends ScenarioTest { 25 | 26 | @Autowired 27 | private GreetingController greetingController; 28 | 29 | 30 | @Ignore 31 | @Test 32 | public void springbootApplicationWithAuditedMethodTest() { 33 | 34 | List ints = new ArrayList(); 35 | ints.add(new User()); 36 | ints.add(new User()); 37 | 38 | given().spring_boot_application_started_with_audit4j_with_a_programming_configuration_using_ConsoleAuditHandler(); 39 | when().the_method_$_annotated_with_audited_is_called_with_the_arguments_$_$_$("foo", new User(),1, ints, greetingController ); 40 | then().the_file_log_contains_$_line(1, "getFilePath()"); 41 | // .and().the_file_log_contains_the_expected_output_for_event_builder(getFilePath()); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/hello/stage/GivenSomeState.java: -------------------------------------------------------------------------------- 1 | package hello.stage; 2 | 3 | 4 | import com.tngtech.jgiven.Stage; 5 | 6 | public class GivenSomeState extends Stage { 7 | 8 | public GivenSomeState spring_boot_application_started_with_audit4j_with_a_programming_configuration_using_ConsoleAuditHandler() { 9 | return self(); 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/hello/stage/ThenSomeOutcome.java: -------------------------------------------------------------------------------- 1 | package hello.stage; 2 | 3 | 4 | import com.tngtech.jgiven.Stage; 5 | import com.tngtech.jgiven.annotation.Hidden; 6 | 7 | 8 | public class ThenSomeOutcome extends Stage { 9 | 10 | public ThenSomeOutcome the_file_log_contains_$_line(int i, @Hidden String string) { 11 | return self(); 12 | 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/hello/stage/WhenSomeAction.java: -------------------------------------------------------------------------------- 1 | package hello.stage; 2 | 3 | 4 | import java.math.BigDecimal; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.tngtech.jgiven.Stage; 9 | import com.tngtech.jgiven.annotation.Hidden; 10 | import com.tngtech.jgiven.annotation.Quoted; 11 | 12 | import hello.GreetingController; 13 | import hello.data.User; 14 | 15 | public class WhenSomeAction extends Stage { 16 | 17 | public void the_method_$_annotated_with_audited_is_called_with_the_arguments_$_$_$( 18 | @Quoted String methodName, @Quoted User arg0, 19 | @Quoted int val, 20 | @Quoted List array, 21 | @Hidden GreetingController greetingController) { 22 | 23 | User[] ints = new User[2]; 24 | ints[0]=new User(); 25 | ints[1]=new User(); 26 | 27 | greetingController.foo1(ints, new BigDecimal(1)); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/org/audit4j/validation/jgiven/enumeration/Version.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.validation.jgiven.enumeration; 2 | 3 | public enum Version { 4 | 5 | V250("v2.5.0"); 6 | 7 | private String name =""; 8 | 9 | Version(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/org/audit4j/validation/jgiven/stage/WhenSomeAction.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.validation.jgiven.stage; 2 | 3 | import org.audit4j.core.AuditManager; 4 | import org.audit4j.validation.jgiven.util.TesterUtil; 5 | 6 | import com.tngtech.jgiven.Stage; 7 | 8 | public class WhenSomeAction extends Stage { 9 | 10 | 11 | public WhenSomeAction a_message_is_sent_to_the_audit_manager_with_event_builder() { 12 | 13 | TesterUtil.sendMessageWithEventBuilder(); 14 | 15 | return self(); 16 | 17 | } 18 | 19 | public WhenSomeAction audit_manager_is_stopped() { 20 | AuditManager.shutdown(); 21 | return self(); 22 | 23 | } 24 | 25 | public WhenSomeAction a_message_is_sent_to_the_audit_manager_with_audit_event() { 26 | TesterUtil.sendMessageWithAuditEvent(); 27 | return self(); 28 | } 29 | 30 | public WhenSomeAction audit_manager_is_disabled() { 31 | AuditManager.disable(); 32 | return self(); 33 | } 34 | 35 | 36 | } -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/java/org/audit4j/validation/jgiven/util/TesterUtil.java: -------------------------------------------------------------------------------- 1 | package org.audit4j.validation.jgiven.util; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | import org.audit4j.core.AuditManager; 7 | import org.audit4j.core.dto.AuditEvent; 8 | import org.audit4j.core.dto.EventBuilder; 9 | import org.audit4j.core.dto.Field; 10 | 11 | public class TesterUtil { 12 | 13 | public final static String expectedOutputEV ="Init Actor|Default Origin|myMethodEV==>myParam1Name java.lang.String:sfd,myParam2Name java.lang.String:sdfdsf,"; 14 | public final static String expectedOutputAE ="Init Actor|Default Origin|myMethodAE==>myParam1Name java.lang.String:sfd,myParam2Name java.lang.String:sdfdsf,"; 15 | 16 | 17 | private static final String ACTOR = "Init Actor"; 18 | 19 | public static void sendMessageWithEventBuilder() { 20 | AuditManager.getInstance().audit( 21 | new EventBuilder().addActor(ACTOR).addAction("myMethodEV").addField("myParam1Name", "sfd") 22 | .addField("myParam2Name", "sdfdsf").build()); 23 | } 24 | 25 | public static void sendMessageWithAuditEvent() { 26 | AuditManager.getInstance().audit( 27 | new AuditEvent(ACTOR, "myMethodAE", new Field("myParam1Name", "sfd"), 28 | new Field("myParam2Name", "sdfdsf"))); 29 | } 30 | 31 | public static String getAuditFileName() { 32 | Date date = new Date(); 33 | SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd"); 34 | String postFix = dt.format(date); 35 | 36 | return "Audit_Log-"+postFix+".audit"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/resources/audit4j-console-layout.conf.yml: -------------------------------------------------------------------------------- 1 | !Configuration # Mandatory 2 | 3 | # Configure handlers, One or more handlers must be configured. 4 | handlers: 5 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 6 | 7 | # Configure handlers, Either one handler must be configured. 8 | layout: !org.audit4j.core.layout.CustomizableLayout 9 | dateFormat: yyyy/MM/dd HH:mm:ss 10 | template: ${eventDate}|${uuid}|${actor}|${action}|${origin} => ${foreach fields field}[${field.name}:${field.value}]${end} 11 | 12 | # Configure meta data. 13 | metaData: !org.audit4j.core.DummyMetaData {} 14 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/resources/audit4j-console.conf.yml: -------------------------------------------------------------------------------- 1 | !Configuration # Mandatory 2 | 3 | # Configure handlers, One or more handlers must be configured. 4 | handlers: 5 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 6 | 7 | # Configure handlers, Either one handler must be configured. 8 | layout: !org.audit4j.core.layout.SimpleLayout {} 9 | 10 | # Configure meta data. 11 | metaData: !org.audit4j.core.DummyMetaData {} 12 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/resources/audit4j-file-console.conf.yml: -------------------------------------------------------------------------------- 1 | !Configuration # Mandatory 2 | 3 | # Configure handlers, One or more handlers must be configured. 4 | handlers: 5 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 6 | - !org.audit4j.core.handler.file.FileAuditHandler {} 7 | 8 | # Configure handlers, Either one handler must be configured. 9 | layout: !org.audit4j.core.layout.SimpleLayout {} 10 | 11 | # Configure meta data. 12 | metaData: !org.audit4j.core.DummyMetaData {} 13 | 14 | # Configure additional properties. 15 | properties: 16 | log.file.location: user.dir 17 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/resources/audit4j-file.conf.yml: -------------------------------------------------------------------------------- 1 | !Configuration # Mandatory 2 | 3 | # Configure handlers, One or more handlers must be configured. 4 | handlers: 5 | - !org.audit4j.core.handler.file.FileAuditHandler {} 6 | 7 | # Configure handlers, Either one handler must be configured. 8 | layout: !org.audit4j.core.layout.SimpleLayout {} 9 | 10 | # Configure meta data. 11 | metaData: !org.audit4j.core.DummyMetaData {} 12 | 13 | # Configure additional properties. 14 | properties: 15 | log.file.location: user.dir 16 | -------------------------------------------------------------------------------- /audit4j-integration-tests/src/test/resources/audit4j-h2.conf.yml: -------------------------------------------------------------------------------- 1 | !Configuration # Mandatory 2 | 3 | # Configure handlers, One or more handlers must be configured. 4 | handlers: 5 | - !org.audit4j.handler.db.DatabaseAuditHandler 6 | embedded: false 7 | db_connection_type: pooled 8 | db_driver: org.h2.Driver 9 | db_url: jdbc:h2:tcp://localhost/~/stackoverflow 10 | db_user: sa 11 | db_password: 12 | db_datasourceClass: org.h2.jdbcx.JdbcDataSource 13 | 14 | # Configure handlers, Either one handler must be configured. 15 | layout: !org.audit4j.core.layout.SimpleLayout {} 16 | 17 | # Configure meta data. 18 | metaData: !org.audit4j.core.DummyMetaData {} 19 | 20 | commands: -batchSize=4 21 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/AuditMetaData.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.servlet.ServletRequest; 6 | 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.audit4j.core.MetaData; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | 12 | class AuditMetaData : MetaData { 13 | 14 | override fun getOrigin() : String { 15 | /*try { 16 | return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr(); 17 | }catch(Exception e){ 18 | e.printStackTrace(); 19 | }*/ 20 | return "unidentified"; 21 | } 22 | 23 | override fun getActor() = "anonymous"; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/PetClinicApplication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic 17 | 18 | import org.springframework.boot.SpringApplication 19 | import org.springframework.boot.autoconfigure.SpringBootApplication 20 | 21 | /** 22 | * PetClinic Spring Boot Application. 23 | * 24 | * @author Dave Syer 25 | * @author Antoine Rey 26 | */ 27 | @SpringBootApplication 28 | open class PetClinicApplication { 29 | companion object { 30 | @JvmStatic fun main(args: Array) { 31 | SpringApplication.run(PetClinicApplication::class.java, *args) 32 | } 33 | } 34 | } 35 | /* 36 | fun main(args: Array) { 37 | SpringApplication.run(PetClinicApplication::class.java, *args) 38 | }*/ -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/model/BaseEntity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model 17 | 18 | import java.io.Serializable 19 | import javax.persistence.GeneratedValue 20 | import javax.persistence.GenerationType 21 | import javax.persistence.Id 22 | import javax.persistence.MappedSuperclass 23 | 24 | /** 25 | * Simple JavaBean domain object with an id property. Used as a base class for objects 26 | * needing this property. 27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | * @author Antoine Rey 31 | */ 32 | @MappedSuperclass 33 | open class BaseEntity : Serializable { 34 | 35 | @Id 36 | @GeneratedValue(strategy = GenerationType.IDENTITY) 37 | var id: Int? = null 38 | 39 | val isNew: Boolean 40 | get() = this.id == null 41 | 42 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/model/NamedEntity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model 17 | 18 | import javax.persistence.Column 19 | import javax.persistence.MappedSuperclass 20 | 21 | 22 | /** 23 | * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects 24 | * needing these properties. 25 | * 26 | * @author Ken Krebs 27 | * @author Juergen Hoeller 28 | * @author Antoine Rey 29 | */ 30 | @MappedSuperclass 31 | open class NamedEntity : BaseEntity() { 32 | 33 | @Column(name = "name") 34 | var name: String? = null 35 | 36 | override fun toString(): String = 37 | this.name ?: "" 38 | 39 | } 40 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/model/Person.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model 17 | 18 | 19 | import javax.persistence.Column 20 | import javax.persistence.MappedSuperclass 21 | import org.hibernate.validator.constraints.NotEmpty 22 | 23 | /** 24 | * Simple JavaBean domain object representing an person. 25 | * 26 | * @author Ken Krebs 27 | * @author Antoine Rey 28 | */ 29 | @MappedSuperclass 30 | open class Person : BaseEntity() { 31 | 32 | @Column(name = "first_name") 33 | @NotEmpty 34 | var firstName = "" 35 | 36 | @Column(name = "last_name") 37 | @NotEmpty 38 | var lastName = "" 39 | 40 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/OwnerRepository.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner 2 | 3 | import org.springframework.data.jpa.repository.Query 4 | import org.springframework.data.repository.Repository 5 | import org.springframework.data.repository.query.Param 6 | import org.springframework.transaction.annotation.Transactional 7 | 8 | interface OwnerRepository : Repository { 9 | 10 | /** 11 | * Retrieve {@link Owner}s from the data store by last name, returning all owners 12 | * whose last name starts with the given name. 13 | * @param lastName Value to search for 14 | * @return a Collection of matching {@link Owner}s (or an empty Collection if none 15 | * found) 16 | */ 17 | @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%") 18 | @Transactional(readOnly = true) 19 | fun findByLastName(@Param("lastName") lastName : String) : Collection 20 | 21 | /** 22 | * Retrieve an {@link Owner} from the data store by id. 23 | * @param id the id to search for 24 | * @return the {@link Owner} if found 25 | */ 26 | @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id") 27 | @Transactional(readOnly = true) 28 | fun findById(@Param("id") id : Int) : Owner 29 | 30 | /** 31 | * Save an {@link Owner} to the data store, either inserting or updating it. 32 | * @param owner the {@link Owner} to save 33 | */ 34 | fun save(owner : Owner) 35 | 36 | 37 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/Pet.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner 2 | 3 | import java.util.ArrayList 4 | import java.util.Collections 5 | import java.util.Date 6 | import java.util.HashSet 7 | import java.util.LinkedHashSet 8 | 9 | import javax.persistence.CascadeType 10 | import javax.persistence.Column 11 | import javax.persistence.Entity 12 | import javax.persistence.FetchType 13 | import javax.persistence.JoinColumn 14 | import javax.persistence.ManyToOne 15 | import javax.persistence.OneToMany 16 | import javax.persistence.Table 17 | import javax.persistence.Temporal 18 | import javax.persistence.TemporalType 19 | 20 | import org.springframework.beans.support.MutableSortDefinition 21 | import org.springframework.beans.support.PropertyComparator 22 | import org.springframework.format.annotation.DateTimeFormat 23 | import org.springframework.samples.petclinic.model.NamedEntity 24 | import org.springframework.samples.petclinic.visit.Visit 25 | 26 | 27 | @Entity 28 | @Table(name = "pets") 29 | class Pet : NamedEntity() { 30 | 31 | @Column(name = "birth_date") 32 | @Temporal(TemporalType.DATE) 33 | @DateTimeFormat(pattern = "yyyy-MM-dd") 34 | var birthDate: Date? = null 35 | 36 | @ManyToOne 37 | @JoinColumn(name = "type_id") 38 | var type: PetType? = null 39 | 40 | @ManyToOne 41 | @JoinColumn(name = "owner_id") 42 | var owner: Owner? = null 43 | 44 | @OneToMany(cascade = arrayOf(CascadeType.ALL), mappedBy = "petId", fetch = FetchType.EAGER) 45 | var visits: MutableSet = LinkedHashSet() 46 | 47 | 48 | fun getVisits(): List = 49 | visits.sortedWith(compareBy { it.date }) 50 | 51 | fun addVisit(visit: Visit) { 52 | visits.add(visit) 53 | visit.petId = this.id 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/PetRepository.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner; 2 | 3 | 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.Repository; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | interface PetRepository : Repository { 9 | 10 | /** 11 | * Retrieve all {@link PetType}s from the data store. 12 | * @return a Collection of {@link PetType}s. 13 | */ 14 | @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name") 15 | @Transactional(readOnly = true) 16 | fun findPetTypes() : List 17 | 18 | /** 19 | * Retrieve a {@link Pet} from the data store by id. 20 | * @param id the id to search for 21 | * @return the {@link Pet} if found 22 | */ 23 | @Transactional(readOnly = true) 24 | fun findById(id : Int) : Pet 25 | 26 | /** 27 | * Save a {@link Pet} to the data store, either inserting or updating it. 28 | * @param pet the {@link Pet} to save 29 | */ 30 | fun save(pet : Pet); 31 | 32 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/PetType.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner 2 | 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.Table; 6 | 7 | import org.springframework.samples.petclinic.model.NamedEntity; 8 | 9 | @Entity 10 | @Table(name = "types") 11 | open class PetType : NamedEntity() -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/PetTypeFormater.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner 2 | 3 | import java.text.ParseException 4 | import java.util.Locale 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.format.Formatter; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have 12 | * come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The 13 | * Spring ref doc: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI 14 | * - A nice blog entry from Gordon Dickens: http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/ 15 | *

16 | * 17 | * @author Mark Fisher 18 | * @author Juergen Hoeller 19 | * @author Michael Isvy 20 | */ 21 | @Component 22 | class PetTypeFormatter(val pets: PetRepository) : Formatter { 23 | 24 | 25 | override fun print(petType: PetType, locale: Locale): String 26 | = petType.name ?: "" 27 | 28 | 29 | override fun parse(text: String, locale: Locale): PetType { 30 | val findPetTypes = this.pets.findPetTypes() 31 | return findPetTypes.find { it.name == text } ?: 32 | throw ParseException("type not found: " + text, 0) 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/owner/PetValidator.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.owner 2 | 3 | import org.springframework.util.StringUtils 4 | import org.springframework.validation.Errors 5 | import org.springframework.validation.Validator 6 | 7 | class PetValidator : Validator { 8 | 9 | 10 | companion object { 11 | const val REQUIRED = "required" 12 | } 13 | 14 | override 15 | fun validate(obj: Any?, errors: Errors) { 16 | if (obj == null) { 17 | return 18 | } 19 | val pet = obj as Pet 20 | val name = pet.name; 21 | // name validation 22 | if (!StringUtils.hasLength(name)) { 23 | errors.rejectValue("name", REQUIRED, REQUIRED); 24 | } 25 | 26 | // type validation 27 | if (pet.isNew && pet.type == null) { 28 | errors.rejectValue("type", REQUIRED, REQUIRED); 29 | } 30 | 31 | // birth date validation 32 | if (pet.birthDate == null) { 33 | errors.rejectValue("birthDate", REQUIRED, REQUIRED); 34 | } 35 | } 36 | 37 | /** 38 | * This Validator validates *just* Pet instances 39 | */ 40 | override fun supports(clazz: Class<*>) = Pet::class.java.isAssignableFrom(clazz) 41 | 42 | 43 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/system/CacheConfig.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | import javax.cache.configuration.Configuration; 4 | import javax.cache.configuration.MutableConfiguration; 5 | 6 | import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer; 7 | import org.springframework.cache.annotation.EnableCaching; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Profile; 10 | 11 | /** 12 | * Cache could be disabled in unit test. 13 | */ 14 | @org.springframework.context.annotation.Configuration 15 | @EnableCaching 16 | @Profile("production") 17 | open class CacheConfig { 18 | 19 | @Bean 20 | fun cacheManagerCustomizer(): JCacheManagerCustomizer { 21 | return JCacheManagerCustomizer { 22 | it.createCache("vets", createCacheConfiguration()) 23 | } 24 | } 25 | 26 | private fun createCacheConfiguration(): Configuration = 27 | // Create a cache using infinite heap. A real application will want to use an 28 | // implementation dependent configuration that will better fit your needs 29 | MutableConfiguration().setStatisticsEnabled(true) 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/system/CrashController.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | 8 | /** 9 | * Controller used to showcase what happens when an exception is thrown 10 | * 11 | * @author Michael Isvy 12 | *

13 | * Also see how a view that resolves to "error" has been added ("error.html"). 14 | */ 15 | @Controller 16 | class CrashController { 17 | 18 | @GetMapping("/oups") 19 | fun triggerException() : String { 20 | throw RuntimeException( 21 | "Expected: controller used to showcase what " + "happens when an exception is thrown"); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/system/WelcomeControler.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | 4 | import org.audit4j.core.annotation.Audit 5 | import org.springframework.stereotype.Controller 6 | import org.springframework.web.bind.annotation.GetMapping 7 | 8 | @Controller 9 | open class WelcomeController { 10 | 11 | @Audit 12 | @GetMapping("/") 13 | open fun welcome() = "welcome" 14 | } 15 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/vet/Specialty.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.Table; 7 | 8 | import org.springframework.samples.petclinic.model.NamedEntity; 9 | 10 | /** 11 | * Models a {@link Vet Vet's} specialty (for example, dentistry). 12 | * 13 | * @author Juergen Hoeller 14 | */ 15 | @Entity 16 | @Table(name = "specialties") 17 | class Specialty : NamedEntity(), Serializable { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/vet/Vet.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashSet; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.FetchType; 9 | import javax.persistence.JoinColumn; 10 | import javax.persistence.JoinTable; 11 | import javax.persistence.ManyToMany; 12 | import javax.persistence.Table; 13 | import javax.xml.bind.annotation.XmlElement; 14 | 15 | import org.springframework.beans.support.MutableSortDefinition; 16 | import org.springframework.beans.support.PropertyComparator; 17 | import org.springframework.samples.petclinic.model.Person; 18 | 19 | /** 20 | * Simple JavaBean domain object representing a veterinarian. 21 | * 22 | * @author Ken Krebs 23 | * @author Juergen Hoeller 24 | * @author Sam Brannen 25 | * @author Arjen Poutsma 26 | */ 27 | @Entity 28 | @Table(name = "vets") 29 | class Vet : Person() { 30 | 31 | @ManyToMany(fetch = FetchType.EAGER) 32 | @JoinTable(name = "vet_specialties", joinColumns = arrayOf(JoinColumn(name = "vet_id")), inverseJoinColumns = arrayOf(JoinColumn(name = "specialty_id"))) 33 | var specialties: MutableSet = HashSet() 34 | 35 | 36 | @XmlElement 37 | fun getSpecialties(): List = 38 | specialties.sortedWith(compareBy { it.name }) 39 | 40 | fun getNrOfSpecialties(): Int = 41 | specialties.size 42 | 43 | 44 | fun addSpecialty(specialty: Specialty) = 45 | specialties.add(specialty) 46 | 47 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/vet/VetController.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | 8 | 9 | @Controller 10 | class VetController(val vetRepository: VetRepository) { 11 | 12 | 13 | @GetMapping("/vets.html") 14 | fun showHtmlVetList(model: MutableMap): String { 15 | val vets = Vets(vetRepository.findAll()) 16 | model.put("vets", vets) 17 | return "vets/vetList" 18 | } 19 | 20 | @GetMapping(path = arrayOf("vets.json", "vets.xml"), produces = arrayOf("application/json")) 21 | @ResponseBody 22 | fun showJsonVetList(): Vets = 23 | // Here we are returning an object of type 'Vets' rather than a collection of Vet 24 | // objects so it is simpler for Json/Object mapping 25 | Vets(vetRepository.findAll()) 26 | 27 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/vet/VetRepository.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet 2 | 3 | 4 | import org.springframework.cache.annotation.Cacheable; 5 | import org.springframework.dao.DataAccessException; 6 | import org.springframework.data.repository.Repository; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | interface VetRepository : Repository { 10 | 11 | /** 12 | * Retrieve all Vets from the data store. 13 | * 14 | * @return a Collection of Vets 15 | */ 16 | @Transactional(readOnly = true) 17 | @Cacheable("vets") 18 | fun findAll() : Collection 19 | 20 | 21 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/vet/Vets.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet 2 | 3 | import java.util.ArrayList; 4 | import javax.xml.bind.annotation.XmlElement; 5 | import javax.xml.bind.annotation.XmlRootElement; 6 | 7 | /** 8 | * Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link 9 | * org.springframework.web.servlet.view.xml.MarshallingView}. 10 | * 11 | * @author Arjen Poutsma 12 | */ 13 | 14 | @XmlRootElement 15 | data class Vets(var vetList: Collection? = null) 16 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/visit/Visit.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.visit 2 | 3 | import java.util.Date; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Table; 8 | import javax.persistence.Temporal; 9 | import javax.persistence.TemporalType; 10 | 11 | import org.hibernate.validator.constraints.NotEmpty; 12 | import org.springframework.format.annotation.DateTimeFormat; 13 | import org.springframework.samples.petclinic.model.BaseEntity; 14 | 15 | /** 16 | * Simple JavaBean domain object representing a visit. 17 | * 18 | * @author Ken Krebs 19 | * @author Dave Syer 20 | */ 21 | @Entity 22 | @Table(name = "visits") 23 | class Visit : BaseEntity() { 24 | 25 | /** 26 | * Holds value of property date. 27 | */ 28 | @Column(name = "visit_date") 29 | @Temporal(TemporalType.TIMESTAMP) 30 | @DateTimeFormat(pattern = "yyyy-MM-dd") 31 | var date: Date = Date() 32 | 33 | /** 34 | * Holds value of property description. 35 | */ 36 | @NotEmpty 37 | @Column(name = "description") 38 | var description: String? = null 39 | 40 | 41 | /** 42 | * Holds value of property owner. 43 | */ 44 | @Column(name = "pet_id") 45 | var petId: Int? = null 46 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/kotlin/org/springframework/samples/petclinic/visit/VisitRepository.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.visit 2 | 3 | import org.springframework.dao.DataAccessException 4 | import org.springframework.data.repository.Repository 5 | import org.springframework.samples.petclinic.model.BaseEntity 6 | 7 | 8 | interface VisitRepository : Repository { 9 | 10 | /** 11 | * Save a Visit to the data store, either inserting or updating it. 12 | * 13 | * @param visit the Visit to save 14 | * @see BaseEntity#isNew 15 | */ 16 | fun save(visit: Visit) 17 | 18 | fun findByPetId(petId: Int) : List 19 | 20 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/less/header.less: -------------------------------------------------------------------------------- 1 | .navbar { 2 | border-top: 4px solid #6db33f; 3 | background-color: #34302d; 4 | margin-bottom: 0px; 5 | border-bottom: 0; 6 | border-left: 0; 7 | border-right: 0; 8 | } 9 | 10 | .navbar a.navbar-brand { 11 | background: url("../images/spring-logo-dataflow.png") -1px -1px no-repeat; 12 | margin: 12px 0 6px; 13 | width: 229px; 14 | height: 46px; 15 | display: inline-block; 16 | text-decoration: none; 17 | padding: 0; 18 | } 19 | 20 | .navbar a.navbar-brand span { 21 | display: block; 22 | width: 229px; 23 | height: 46px; 24 | background: url("../images/spring-logo-dataflow.png") -1px -48px no-repeat; 25 | opacity: 0; 26 | -moz-transition: opacity 0.12s ease-in-out; 27 | -webkit-transition: opacity 0.12s ease-in-out; 28 | -o-transition: opacity 0.12s ease-in-out; 29 | } 30 | 31 | .navbar a:hover.navbar-brand span { 32 | opacity: 1; 33 | } 34 | 35 | .navbar li > a, .navbar-text { 36 | font-family: "montserratregular", sans-serif; 37 | text-shadow: none; 38 | font-size: 14px; 39 | 40 | /* line-height: 14px; */ 41 | padding: 28px 20px; 42 | transition: all 0.15s; 43 | -webkit-transition: all 0.15s; 44 | -moz-transition: all 0.15s; 45 | -o-transition: all 0.15s; 46 | -ms-transition: all 0.15s; 47 | } 48 | 49 | .navbar li > a { 50 | text-transform: uppercase; 51 | } 52 | 53 | .navbar .navbar-text { 54 | margin-top: 0; 55 | margin-bottom: 0; 56 | } 57 | .navbar li:hover > a { 58 | color: #eeeeee; 59 | background-color: #6db33f; 60 | } 61 | 62 | .navbar-toggle { 63 | border-width: 0; 64 | 65 | .icon-bar + .icon-bar { 66 | margin-top: 3px; 67 | } 68 | .icon-bar { 69 | width: 19px; 70 | height: 3px; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/less/responsive.less: -------------------------------------------------------------------------------- 1 | @media (max-width: 768px) { 2 | .navbar-toggle { 3 | position:absolute; 4 | z-index: 9999; 5 | left:0px; 6 | top:0px; 7 | } 8 | 9 | .navbar a.navbar-brand { 10 | display: block; 11 | margin: 0 auto 0 auto; 12 | width: 148px; 13 | height: 50px; 14 | float: none; 15 | background: url("../images/spring-logo-dataflow-mobile.png") 0 center no-repeat; 16 | } 17 | 18 | .homepage-billboard .homepage-subtitle { 19 | font-size: 21px; 20 | line-height: 21px; 21 | } 22 | 23 | .navbar a.navbar-brand span { 24 | display: none; 25 | } 26 | 27 | .navbar { 28 | border-top-width: 0; 29 | } 30 | 31 | .xd-container { 32 | margin-top: 20px; 33 | margin-bottom: 30px; 34 | } 35 | 36 | .index-page--subtitle { 37 | margin-top: 10px; 38 | margin-bottom: 30px; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/less/typography.less: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'varela_roundregular'; 3 | 4 | src: url('../fonts/varela_round-webfont.eot'); 5 | src: url('../fonts/varela_round-webfont.eot?#iefix') format('embedded-opentype'), 6 | url('../fonts/varela_round-webfont.woff') format('woff'), 7 | url('../fonts/varela_round-webfont.ttf') format('truetype'), 8 | url('../fonts/varela_round-webfont.svg#varela_roundregular') format('svg'); 9 | font-weight: normal; 10 | font-style: normal; 11 | } 12 | 13 | @font-face { 14 | font-family: 'montserratregular'; 15 | src: url('../fonts/montserrat-webfont.eot'); 16 | src: url('../fonts/montserrat-webfont.eot?#iefix') format('embedded-opentype'), 17 | url('../fonts/montserrat-webfont.woff') format('woff'), 18 | url('../fonts/montserrat-webfont.ttf') format('truetype'), 19 | url('../fonts/montserrat-webfont.svg#montserratregular') format('svg'); 20 | font-weight: normal; 21 | font-style: normal; 22 | } 23 | 24 | body, h1, h2, h3, p, input { 25 | margin: 0; 26 | font-weight: 400; 27 | font-family: "varela_roundregular", sans-serif; 28 | color: #34302d; 29 | } 30 | 31 | h1 { 32 | font-size: 24px; 33 | line-height: 30px; 34 | font-family: "montserratregular", sans-serif; 35 | } 36 | 37 | h2 { 38 | font-size: 18px; 39 | font-weight: 700; 40 | line-height: 24px; 41 | margin-bottom: 10px; 42 | font-family: "montserratregular", sans-serif; 43 | } 44 | 45 | h3 { 46 | font-size: 16px; 47 | line-height: 24px; 48 | margin-bottom: 10px; 49 | font-weight: 700; 50 | } 51 | 52 | p { 53 | //font-size: 15px; 54 | //line-height: 24px; 55 | } 56 | 57 | strong { 58 | font-weight: 700; 59 | font-family: "montserratregular", sans-serif; 60 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # database init, supports mysql too 2 | database=hsqldb 3 | spring.datasource.schema=classpath*:db/${database}/schema.sql 4 | spring.datasource.data=classpath*:db/${database}/data.sql 5 | spring.datasource.url=jdbc:hsqldb:mem:aname 6 | spring.datasource.username=sa 7 | spring.datasource.password= 8 | # Web 9 | spring.thymeleaf.mode=HTML 10 | 11 | # JPA 12 | spring.jpa.hibernate.ddl-auto=none 13 | 14 | # Internationalization 15 | spring.messages.basename=messages/messages 16 | 17 | # Actuator / Management 18 | management.contextPath=/manage 19 | # Spring Boot 1.5 makes actuator secure by default 20 | management.security.enabled=false 21 | 22 | # Logging 23 | logging.level.org.springframework=INFO 24 | # logging.level.org.springframework.web=DEBUG 25 | # logging.level.org.springframework.context.annotation=TRACE 26 | 27 | # Active Spring profiles 28 | #spring.profiles.active=production -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | |\ _,,,--,,_ 4 | /,`.-'`' ._ \-;;,_ 5 | _______ __|,4- ) )_ .;.(__`'-'__ ___ __ _ ___ _______ 6 | | | '---''(_/._)-'(_\_) | | | | | | | | | 7 | | _ | ___|_ _| | | | | |_| | | | __ _ _ 8 | | |_| | |___ | | | | | | | | | | \ \ \ \ 9 | | ___| ___| | | | _| |___| | _ | | _| \ \ \ \ 10 | | | | |___ | | | |_| | | | | | | |_ ) ) ) ) 11 | |___| |_______| |___| |_______|_______|___|_| |__|___|_______| / / / / 12 | ==================================================================/_/_/_/ 13 | 14 | :: Built with Spring Boot :: ${spring-boot.version} -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/messages/messages.properties: -------------------------------------------------------------------------------- 1 | welcome=Welcome 2 | required=is required 3 | notFound=has not been found 4 | duplicate=is already in use 5 | nonNumeric=must be all numeric 6 | duplicateFormSubmission=Duplicate form submission is not allowed 7 | typeMismatch.date=invalid date 8 | typeMismatch.birthDate=invalid date -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/favicon.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/pets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/pets.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/platform-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/platform-bg.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-logo-dataflow-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-logo-dataflow-mobile.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-logo-dataflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-logo-dataflow.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-pivotal-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/audit4j/audit4j-demo/16d62da66a3807e95b45717baa80710abbc1b64a/audit4j-kotlin-demo-springboot/src/main/resources/static/resources/images/spring-pivotal-logo.png -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Something happened...

8 |

Exception message

9 | 10 | 11 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/fragments/inputField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
8 | 9 |
10 | 12 | 15 | 16 | 19 | Error 20 | 21 |
22 |
23 |
24 |
25 | 26 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/fragments/selectField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
8 | 9 | 10 |
11 | 15 | 18 | 19 | 22 | Error 23 | 24 |
25 |
26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/owners/createOrUpdateOwnerForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |

Owner

7 |
8 |
9 | 11 | 13 | 15 | 17 | 19 |
20 |
21 |
22 | 26 |
27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/owners/findOwners.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |

Find Owners

7 | 8 |
10 |
11 |
12 | 13 |
14 |
17 |

Error

18 |
19 |
20 |
21 |
22 |
23 |
24 | 26 |
27 |
28 | 29 |
30 | 31 |
32 | Add Owner 33 | 34 | 35 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/owners/ownersList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Owners

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 28 | 29 | 30 |
NameAddressCityTelephonePets
22 | 23 | 25 | 26 | 27 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/pets/createOrUpdatePetForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |

7 | New 8 | Pet 9 |

10 |
11 | 12 |
13 |
14 | 15 |
16 | 17 |
18 |
19 | 21 | 23 | 25 |
26 |
27 |
28 | 32 |
33 |
34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/pets/createOrUpdateVisitForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |

7 | New 8 | Visit 9 |

10 | 11 | Pet 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 28 | 29 |
NameBirth DateTypeOwner
30 | 31 |
32 |
33 | 35 | 37 |
38 | 39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 | 47 |
48 | Previous Visits 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
DateDescription
59 | 60 | 61 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/vets/vetList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 |

Veterinarians

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 |
NameSpecialties
none
26 | 27 | 28 | 29 | 30 | 31 | 32 |
View as XMLView as JSON
33 | 34 | 35 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/resources/templates/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Welcome

8 |
9 |
10 | 11 |
12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/wro/wro.properties: -------------------------------------------------------------------------------- 1 | #List of preProcessors 2 | preProcessors=lessCssImport 3 | #List of postProcessors 4 | postProcessors=less4j -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/main/wro/wro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | classpath:META-INF/resources/webjars/bootstrap/3.3.6/less/bootstrap.less 4 | /petclinic.less 5 | 6 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/test/kotlin/org/springframework/samples/petclinic/model/ValidatorTests.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.model 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.Test 5 | import org.springframework.context.i18n.LocaleContextHolder 6 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean 7 | import java.util.* 8 | import javax.validation.Validator 9 | 10 | class ValidatorTests { 11 | 12 | private fun createValidator(): Validator { 13 | val localValidatorFactoryBean = LocalValidatorFactoryBean() 14 | localValidatorFactoryBean.afterPropertiesSet() 15 | return localValidatorFactoryBean 16 | } 17 | 18 | @Test 19 | fun shouldNotValidateWhenFirstNameEmpty() { 20 | 21 | LocaleContextHolder.setLocale(Locale.ENGLISH) 22 | val person = Person() 23 | person.firstName = "" 24 | person.lastName = "smith" 25 | 26 | val validator = createValidator() 27 | val constraintViolations = validator.validate(person) 28 | 29 | assertThat(constraintViolations.size).isEqualTo(1) 30 | val violation = constraintViolations.iterator().next() 31 | assertThat(violation.propertyPath.toString()).isEqualTo("firstName") 32 | assertThat(violation.message).isEqualTo("may not be empty") 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/test/kotlin/org/springframework/samples/petclinic/service/EntityUtils.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.orm.ObjectRetrievalFailureException; 6 | import org.springframework.samples.petclinic.model.BaseEntity; 7 | 8 | /** 9 | * Utility methods for handling entities. Separate from the BaseEntity class mainly because of dependency on the 10 | * ORM-associated ObjectRetrievalFailureException. 11 | * 12 | * @author Juergen Hoeller 13 | * @author Sam Brannen 14 | * @see org.springframework.samples.petclinic.model.BaseEntity 15 | * @since 29.10.2003 16 | */ 17 | abstract class EntityUtils { 18 | 19 | /** 20 | * Look up the entity of the given class with the given id in the given collection. 21 | * 22 | * @param entities the collection to search 23 | * @param entityClass the entity class to look up 24 | * @param entityId the entity id to look up 25 | * @return the found entity 26 | * @throws ObjectRetrievalFailureException if the entity was not found 27 | */ 28 | /*public static T getById(Collection entities, Class entityClass, int entityId) 29 | throws ObjectRetrievalFailureException { 30 | for (T entity : entities) { 31 | if (entity.getId() == entityId && entityClass.isInstance(entity)) { 32 | return entity; 33 | } 34 | } 35 | throw ObjectRetrievalFailureException(entityClass, entityId); 36 | }*/ 37 | 38 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/test/kotlin/org/springframework/samples/petclinic/system/CrashControllerTests.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | import org.junit.Ignore; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; 14 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; 15 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 16 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; 17 | 18 | /** 19 | * Test class for {@link CrashController} 20 | * 21 | * @author Colin But 22 | */ 23 | @RunWith(SpringRunner::class) 24 | // Waiting https://github.com/spring-projects/spring-boot/issues/5574 25 | @Ignore 26 | @WebMvcTest(controllers = arrayOf(CrashController::class)) 27 | class CrashControllerTests { 28 | 29 | @Autowired 30 | lateinit private var mockMvc: MockMvc 31 | 32 | @Test 33 | fun testTriggerException() { 34 | mockMvc.perform(get("/oups")).andExpect(view().name("exception")) 35 | .andExpect(model().attributeExists("exception")) 36 | .andExpect(forwardedUrl("exception")).andExpect(status().isOk()) 37 | } 38 | } -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/test/kotlin/org/springframework/samples/petclinic/system/ProductionConfigurationTests.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system 2 | 3 | import org.junit.Test 4 | import org.junit.runner.RunWith 5 | 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.boot.test.context.SpringBootTest 8 | import org.springframework.samples.petclinic.vet.VetRepository 9 | import org.springframework.test.context.junit4.SpringRunner 10 | 11 | @RunWith(SpringRunner::class) 12 | @SpringBootTest 13 | class ProductionConfigurationTests { 14 | 15 | @Autowired 16 | lateinit private var vets: VetRepository 17 | 18 | @Test 19 | fun testFindAll() { 20 | vets.findAll() 21 | vets.findAll() // served from cache 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /audit4j-kotlin-demo-springboot/src/test/kotlin/org/springframework/samples/petclinic/vet/VetTests.kt: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.vet 2 | 3 | import org.junit.Test; 4 | 5 | import org.springframework.util.SerializationUtils; 6 | 7 | import org.assertj.core.api.Assertions.assertThat; 8 | 9 | class VetTests { 10 | 11 | @Test 12 | fun testSerialization() { 13 | var vet = Vet(); 14 | vet.firstName="Zaphod" 15 | vet.lastName= "Beeblebrox" 16 | vet.id= 123 17 | var other = SerializationUtils 18 | .deserialize(SerializationUtils.serialize(vet)) as Vet 19 | assertThat(other.firstName).isEqualTo(vet.firstName) 20 | assertThat(other.lastName).isEqualTo(vet.lastName) 21 | assertThat(other.id).isEqualTo(vet.id!!) 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /sample/audit4j.conf.yaml: -------------------------------------------------------------------------------- 1 | !Configuration 2 | handlers: 3 | - !org.audit4j.handler.db.DatabaseAuditHandler 4 | db_connection_type: POOLED 5 | db_password: root 6 | db_url: jdbc:mysql://127.0.0.1:3306/myDB 7 | db_user: root 8 | embedded: false 9 | - !org.audit4j.core.handler.ConsoleAuditHandler {} 10 | layout: !org.audit4j.core.layout.SimpleLayout {} 11 | metaData: !org.audit4j.core.DummyMetaData {} 12 | --------------------------------------------------------------------------------