Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Catalog
Genesys Catalog Server
Commits
d0a6e9f0
Commit
d0a6e9f0
authored
Jan 25, 2018
by
Maxym Borodenko
Committed by
Matija Obreza
Jan 26, 2018
Browse files
Enable auditing
parent
861e5d88
Changes
11
Hide whitespace changes
Inline
Side-by-side
genesys-catalog-core/pom.xml
View file @
d0a6e9f0
...
...
@@ -293,6 +293,12 @@
<version>
1.4-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-auditlog
</artifactId>
<version>
1.4-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-security
</artifactId>
...
...
genesys-catalog-core/src/main/java/org/genesys/catalog/model/dataset/Dataset.java
View file @
d0a6e9f0
...
...
@@ -37,6 +37,7 @@ import javax.persistence.PrePersist;
import
javax.persistence.PreUpdate
;
import
javax.persistence.Table
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.model.Publishable
;
import
org.genesys.blocks.model.UuidModel
;
import
org.genesys.blocks.security.model.AclAwareModel
;
...
...
@@ -59,6 +60,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Cacheable
@Table
(
name
=
"dataset"
)
@Audited
public
class
Dataset
extends
UuidModel
implements
Publishable
,
PublishValidationInterface
,
AclAwareModel
{
/** The Constant serialVersionUID. */
...
...
genesys-catalog-core/src/main/java/org/genesys/catalog/model/traits/Descriptor.java
View file @
d0a6e9f0
...
...
@@ -35,6 +35,7 @@ import javax.persistence.OrderColumn;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.model.Copyable
;
import
org.genesys.blocks.model.Publishable
;
import
org.genesys.blocks.model.UuidModel
;
...
...
@@ -57,6 +58,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Cacheable
@Table
(
name
=
"descriptor"
)
@Audited
@JsonIdentityInfo
(
generator
=
ObjectIdGenerators
.
PropertyGenerator
.
class
,
property
=
"uuid"
)
public
class
Descriptor
extends
UuidModel
implements
Publishable
,
Copyable
<
Descriptor
>,
AclAwareModel
{
...
...
genesys-catalog-core/src/main/java/org/genesys/catalog/model/traits/DescriptorList.java
View file @
d0a6e9f0
...
...
@@ -30,6 +30,7 @@ import javax.persistence.ManyToOne;
import
javax.persistence.OrderColumn
;
import
javax.persistence.Table
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.model.Publishable
;
import
org.genesys.blocks.model.UuidModel
;
import
org.genesys.blocks.security.model.AclAwareModel
;
...
...
@@ -45,6 +46,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
*/
@Entity
@Table
(
name
=
"descriptorlist"
)
@Audited
@Cacheable
@JsonIdentityInfo
(
generator
=
ObjectIdGenerators
.
PropertyGenerator
.
class
,
property
=
"uuid"
)
public
class
DescriptorList
extends
UuidModel
implements
Publishable
,
AclAwareModel
{
...
...
genesys-catalog-core/src/main/java/org/genesys/catalog/model/user/User.java
View file @
d0a6e9f0
...
...
@@ -19,6 +19,7 @@ import javax.persistence.Cacheable;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.security.model.BasicUser
;
/**
...
...
@@ -27,6 +28,7 @@ import org.genesys.blocks.security.model.BasicUser;
@Cacheable
@Entity
@Table
(
name
=
"user"
)
@Audited
public
class
User
extends
BasicUser
<
UserRole
>
{
/** The Constant serialVersionUID. */
...
...
genesys-catalog-core/src/main/java/org/genesys/catalog/service/worker/ISO3166VocabularyUpdater.java
View file @
d0a6e9f0
...
...
@@ -42,26 +42,23 @@ import org.springframework.stereotype.Component;
@Component
public
class
ISO3166VocabularyUpdater
{
/**
* ISO 3166-1 alpha-2 representation of names of countries and their
* subdivisions, contains two-letter country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
public
static
UUID
ISO3166_2ALPHA
=
UUID
.
fromString
(
"3e39a73e-d1ed-40b0-9944-ac5795128686"
);
/**
* ISO 3166-1 alpha-2 representation of names of countries and their
* subdivisions, contains three-letter country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
*/
public
static
UUID
ISO3166_3ALPHA
=
UUID
.
fromString
(
"39a3d6a2-20e6-4fab-8bfe-acb1f9fe774c"
);
/**
* ISO 3166-1 numeric representation of names of countries and their
* subdivisions, contains three-letter country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_numeric
*/
public
static
UUID
ISO3166_NUMERIC
=
UUID
.
fromString
(
"bd45f660-853f-4034-a434-ed50679579cc"
);
/**
* ISO 3166-1 alpha-2 representation of names of countries and their subdivisions, contains two-letter country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
public
static
UUID
ISO3166_2ALPHA
=
UUID
.
fromString
(
"3e39a73e-d1ed-40b0-9944-ac5795128686"
);
/**
* ISO 3166-1 alpha-2 representation of names of countries and their subdivisions, contains three-letter country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
*/
public
static
UUID
ISO3166_3ALPHA
=
UUID
.
fromString
(
"39a3d6a2-20e6-4fab-8bfe-acb1f9fe774c"
);
/**
* ISO 3166-1 numeric representation of names of countries and their subdivisions, contains three-digit country codes
* https://en.wikipedia.org/wiki/ISO_3166-1_numeric
*/
public
static
UUID
ISO3166_NUMERIC
=
UUID
.
fromString
(
"bd45f660-853f-4034-a434-ed50679579cc"
);
/** The Constant LOG. */
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
ISO3166VocabularyUpdater
.
class
);
...
...
genesys-catalog-core/src/main/java/org/genesys/common/model/Crop.java
View file @
d0a6e9f0
...
...
@@ -20,6 +20,7 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.model.UuidModel
;
import
org.genesys.blocks.security.model.AclAwareModel
;
...
...
@@ -29,6 +30,7 @@ import org.genesys.blocks.security.model.AclAwareModel;
@Entity
@Cacheable
@Table
(
name
=
"crop"
)
@Audited
public
class
Crop
extends
UuidModel
implements
AclAwareModel
{
/** The Constant serialVersionUID. */
...
...
genesys-catalog-parent/pom.xml
View file @
d0a6e9f0
...
...
@@ -36,7 +36,6 @@
<slf4j.version>
1.7.21
</slf4j.version>
<log4j.version>
1.2.17
</log4j.version>
<junit.version>
4.12
</junit.version>
<application.blocks.version>
1.3-SNAPSHOT
</application.blocks.version>
<aspectj.version>
1.7.2
</aspectj.version>
<jackson.version>
2.9.1-SNAPSHOT
</jackson.version>
...
...
genesys-catalog-server/src/main/java/org/genesys/catalog/server/config/AuditConfig.java
0 → 100644
View file @
d0a6e9f0
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys.catalog.server.config
;
import
org.genesys.blocks.auditlog.service.AuditTrailService
;
import
org.genesys.blocks.auditlog.service.ClassPKService
;
import
org.genesys.blocks.auditlog.service.impl.AuditTrailServiceImpl
;
import
org.genesys.blocks.auditlog.service.impl.ClassPKServiceImpl
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* Configuration of audit-related components and services.
*
* @author Matija Obreza
*/
@Configuration
public
class
AuditConfig
{
@Bean
public
ClassPKService
classPkService
()
{
return
new
ClassPKServiceImpl
();
}
@Bean
public
AuditTrailService
auditTrailService
()
{
return
new
AuditTrailServiceImpl
();
}
}
\ No newline at end of file
genesys-catalog-server/src/main/java/org/genesys/catalog/server/config/DatabaseConfig.java
View file @
d0a6e9f0
...
...
@@ -16,19 +16,18 @@
package
org.genesys.catalog.server.config
;
import
java.io.Serializable
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.Iterator
;
import
java.util.Properties
;
import
javax.persistence.EntityManagerFactory
;
import
org.apache.tomcat.jdbc.pool.DataSource
;
import
org.genesys.blocks.auditlog.component.AuditTrailInterceptor
;
import
org.genesys.blocks.model.BasicModel
;
import
org.genesys.blocks.security.SpringSecurityAuditorAware
;
import
org.hibernate.CallbackException
;
import
org.hibernate.EmptyInterceptor
;
import
org.hibernate.Interceptor
;
import
org.hibernate.Transaction
;
import
org.hibernate.jpa.HibernatePersistenceProvider
;
import
org.hibernate.type.Type
;
import
org.slf4j.Logger
;
...
...
@@ -52,7 +51,7 @@ import liquibase.integration.spring.SpringLiquibase;
@Configuration
@EnableJpaRepositories
(
basePackages
=
{
"org.genesys.blocks.auditlog.persistence"
,
"org.genesys.blocks.persistence"
,
"org.genesys.blocks.security.persistence"
,
"org.genesys.common.persistence"
,
"org.genesys.catalog.persistence"
,
"org.genesys.blocks.oauth.persistence"
,
"org.genesys.blocks.auditlog.persistence"
,
"org.genesys.common.persistence"
,
"org.genesys.catalog.persistence"
,
"org.genesys.blocks.oauth.persistence"
,
"org.genesys.filerepository.persistence"
},
repositoryImplementationPostfix
=
"CustomImpl"
,
entityManagerFactoryRef
=
"entityManagerFactory"
,
transactionManagerRef
=
"transactionManager"
)
@EnableTransactionManagement
@EnableJpaAuditing
(
auditorAwareRef
=
"auditorAware"
)
...
...
@@ -170,51 +169,42 @@ public class DatabaseConfig {
auditTrailInterceptor
().
onCollectionUpdate
(
collection
,
key
);
}
@Override
public
Boolean
isTransient
(
final
Object
entity
)
{
if
(
entity
instanceof
BasicModel
)
{
return
!((
BasicModel
)
entity
).
isPersisted
();
}
try
{
return
tryMethod
(
entity
,
"getVersion"
);
}
catch
(
final
NoSuchMethodException
e
)
{
try
{
return
tryMethod
(
entity
,
"getId"
);
}
catch
(
NoSuchMethodException
|
IllegalAccessException
|
InvocationTargetException
e1
)
{
throw
new
RuntimeException
(
e
.
getMessage
()
+
" on "
+
entity
.
getClass
()
+
" e="
+
entity
,
e
);
}
}
catch
(
final
Throwable
e
)
{
throw
new
RuntimeException
(
e
.
getMessage
()
+
" on "
+
entity
.
getClass
()
+
" e="
+
entity
,
e
);
}
}
public
Boolean
tryMethod
(
final
Object
entity
,
final
String
methodName
)
throws
NoSuchMethodException
,
IllegalAccessException
,
InvocationTargetException
{
final
Method
getter
=
entity
.
getClass
().
getMethod
(
methodName
);
if
(
getter
!=
null
)
{
final
Object
result
=
getter
.
invoke
(
entity
);
if
(
result
==
null
)
{
LOG
.
trace
(
entity
+
" is transient, has "
+
methodName
+
" == null"
);
return
true
;
}
else
if
(
result
instanceof
Number
)
{
final
Number
r
=
(
Number
)
result
;
if
(
r
.
longValue
()
<
0
)
{
LOG
.
trace
(
entity
+
" is transient, has "
+
methodName
+
" = "
+
result
+
" < 0"
);
return
true
;
}
else
{
// LOG.trace(entity + " is not transient, has " + methodName + " = " + result +
// " >= 0");
return
false
;
}
}
else
{
// LOG.trace(entity + " is not transient, has " + methodName + " = " + result);
return
false
;
}
}
else
{
LOG
.
trace
(
"No version method."
);
throw
new
RuntimeException
(
"No version method"
);
}
}
@Override
public
boolean
onSave
(
final
Object
entity
,
final
Serializable
id
,
final
Object
[]
state
,
final
String
[]
propertyNames
,
final
Type
[]
types
)
{
return
auditTrailInterceptor
().
onSave
(
entity
,
id
,
state
,
propertyNames
,
types
);
}
@Override
public
void
afterTransactionBegin
(
final
Transaction
tx
)
{
auditTrailInterceptor
().
afterTransactionBegin
(
tx
);
}
@Override
public
void
beforeTransactionCompletion
(
final
Transaction
tx
)
{
auditTrailInterceptor
().
beforeTransactionCompletion
(
tx
);
}
@Override
public
void
afterTransactionCompletion
(
final
Transaction
tx
)
{
auditTrailInterceptor
().
afterTransactionCompletion
(
tx
);
}
@SuppressWarnings
(
"rawtypes"
)
@Override
public
void
postFlush
(
final
Iterator
entities
)
{
auditTrailInterceptor
().
postFlush
(
entities
);
}
@SuppressWarnings
(
"rawtypes"
)
@Override
public
void
preFlush
(
final
Iterator
entities
)
{
auditTrailInterceptor
().
preFlush
(
entities
);
}
@Override
public
Boolean
isTransient
(
Object
entity
)
{
return
auditTrailInterceptor
().
isTransient
(
entity
);
}
});
bean
.
setJpaProperties
(
jpaProperties
);
...
...
genesys-catalog-server/src/test/java/org/genesys/catalog/server/controller/api/v0/DatasetControllerTest.java
View file @
d0a6e9f0
...
...
@@ -39,7 +39,6 @@ import org.springframework.http.MediaType;
import
org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders
;
import
org.springframework.security.test.context.support.WithMockUser
;
import
org.springframework.test.web.servlet.result.MockMvcResultHandlers
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* @author Andrey Lugovskoy.
...
...
@@ -66,7 +65,6 @@ public class DatasetControllerTest extends AbstractDatasetControllerTest {
@Test
@WithMockUser
(
username
=
"user"
,
password
=
"user"
,
roles
=
"ADMINISTRATOR"
)
@Transactional
public
void
publishDataset
()
throws
Exception
{
Dataset
dataset
=
setUpDataset
(
false
);
dataset
=
datasetService
.
createDataset
(
dataset
);
...
...
@@ -89,7 +87,6 @@ public class DatasetControllerTest extends AbstractDatasetControllerTest {
@Test
@WithMockUser
(
username
=
"user"
,
password
=
"user"
,
roles
=
"ADMINISTRATOR"
)
@Transactional
public
void
unpublishDataset
()
throws
Exception
{
Dataset
dataset
=
setUpDataset
(
false
);
dataset
=
datasetService
.
createDataset
(
dataset
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment