Commit cb366764 authored by Matija Obreza's avatar Matija Obreza
Browse files

Bugs: Fixed simple bugs

parent df6cc789
...@@ -367,7 +367,7 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ ...@@ -367,7 +367,7 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
if (isPrimitiveType(types[i].getReturnedClass())) { if (isPrimitiveType(types[i].getReturnedClass())) {
// Notice cast to Long here! // Notice cast to Long here!
recordDelete(entity, (Long) id, propertyName, state == null ? null : state.toString(), null); recordDelete(entity, (Long) id, propertyName, state.toString(), null);
} else if (isEntity(types[i].getReturnedClass())) { } else if (isEntity(types[i].getReturnedClass())) {
final EntityId prevEntity = (EntityId) state; final EntityId prevEntity = (EntityId) state;
final String previousValue = prevEntity == null ? null : prevEntity.getId().toString(); final String previousValue = prevEntity == null ? null : prevEntity.getId().toString();
......
...@@ -103,10 +103,10 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository { ...@@ -103,10 +103,10 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/ */
@Override @Override
public Object get(ClassPK classPk, Long id) { public Object get(ClassPK classPk, Long id) {
LOG.trace("Looking up {} id={}", classPk.getClassname(), id);
if (id == null || classPk == null || classPk.getClassname() == null) { if (id == null || classPk == null || classPk.getClassname() == null) {
return null; return null;
} }
LOG.trace("Looking up {} id={}", classPk.getClassname(), id);
try { try {
return entityManager.find(Class.forName(classPk.getClassname()), id); return entityManager.find(Class.forName(classPk.getClassname()), id);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
......
...@@ -42,14 +42,6 @@ public class DateFilter { ...@@ -42,14 +42,6 @@ public class DateFilter {
// < // <
public Date lt; public Date lt;
/**
* Between is array of two values [a, b].
*
* @deprecated Use {@link #ge} and {@link #le}
*/
@Deprecated
public Date[] between;
/** /**
* Builds the query. * Builds the query.
* *
...@@ -74,10 +66,6 @@ public class DateFilter { ...@@ -74,10 +66,6 @@ public class DateFilter {
and.and(date.isNotNull()); and.and(date.isNotNull());
and.and(date.lt(lt)); and.and(date.lt(lt));
} }
if (between != null && between.length == 2) {
and.and(date.isNotNull());
and.and(date.between(between[0], between[1]));
}
return and; return and;
} }
...@@ -100,9 +88,6 @@ public class DateFilter { ...@@ -100,9 +88,6 @@ public class DateFilter {
if (lt != null) { if (lt != null) {
str.append(" date < ").append(lt).append(" "); str.append(" date < ").append(lt).append(" ");
} }
if (between != null) {
str.append(" date between ").append(between[0]).append(" and ").append(between[1]);
}
return str.toString().replaceAll("\\s{2,}", " "); return str.toString().replaceAll("\\s{2,}", " ");
} }
......
...@@ -25,18 +25,18 @@ import com.querydsl.core.types.Predicate; ...@@ -25,18 +25,18 @@ import com.querydsl.core.types.Predicate;
public class VersionedEntityFilter extends VersionedModelFilter<VersionedEntityFilter, VersionedEntity> { public class VersionedEntityFilter extends VersionedModelFilter<VersionedEntityFilter, VersionedEntity> {
public StringFilter name; public StringFilter name;
public List<Predicate> collectPredicates() { public List<Predicate> collectPredicates() {
return collectPredicates(QVersionedEntity.versionedEntity); return collectPredicates(QVersionedEntity.versionedEntity);
} }
public List<Predicate> collectPredicates(QVersionedEntity versionedEntity) { public List<Predicate> collectPredicates(QVersionedEntity versionedEntity) {
final List<Predicate> predicates = super.collectPredicates(versionedEntity, versionedEntity._super); final List<Predicate> predicates = super.collectPredicates(versionedEntity, versionedEntity._super);
if (name != null) { if (name != null) {
predicates.add(name.buildQuery(versionedEntity.name)); predicates.add(name.buildQuery(versionedEntity.name));
} }
return predicates; return predicates;
} }
} }
...@@ -192,6 +192,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService { ...@@ -192,6 +192,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional @Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final String resetSecret(OAuthClient oauthClient) { public final String resetSecret(OAuthClient oauthClient) {
assert oauthClient != null;
assert oauthClient.getId() != null;
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found.")); oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
String oldHash = oauthClient.getClientSecret(); String oldHash = oauthClient.getClientSecret();
...@@ -203,7 +206,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService { ...@@ -203,7 +206,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
} while (oldHash != null && oldHash.equals(newHash)); } while (oldHash != null && oldHash.equals(newHash));
oauthClient.setClientSecret(newHash); oauthClient.setClientSecret(newHash);
oauthClient = oauthClientRepository.save(oauthClient); oauthClientRepository.save(oauthClient);
return clientSecret; return clientSecret;
} }
...@@ -211,6 +214,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService { ...@@ -211,6 +214,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional @Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final OAuthClient removeSecret(OAuthClient oauthClient) { public final OAuthClient removeSecret(OAuthClient oauthClient) {
assert oauthClient != null;
assert oauthClient.getId() != null;
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found.")); oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (oauthClient.getAuthorizedGrantTypes().contains("client_credentials")) { if (oauthClient.getAuthorizedGrantTypes().contains("client_credentials")) {
throw new RuntimeException("OAuth Client with client_credentials grant must have a secret"); throw new RuntimeException("OAuth Client with client_credentials grant must have a secret");
......
...@@ -605,6 +605,7 @@ public class CustomAclServiceImpl implements CustomAclService { ...@@ -605,6 +605,7 @@ public class CustomAclServiceImpl implements CustomAclService {
if (objectIdentity == null) { if (objectIdentity == null) {
throw new NullPointerException("AclObjectIdentity must be provided, was null."); throw new NullPointerException("AclObjectIdentity must be provided, was null.");
} }
assert objectIdentity.getId() != null;
if (sid == null) { if (sid == null) {
throw new NullPointerException("AclSid must be provided, was null."); throw new NullPointerException("AclSid must be provided, was null.");
} }
......
...@@ -50,10 +50,12 @@ import org.springframework.context.ApplicationContextAware; ...@@ -50,10 +50,12 @@ import org.springframework.context.ApplicationContextAware;
public class CurrentApplicationContext implements ApplicationContextAware { public class CurrentApplicationContext implements ApplicationContextAware {
/** The application context. */ /** The application context. */
static ApplicationContext applicationContext = null; static volatile ApplicationContext applicationContext = null;
public void setApplicationContext(ApplicationContext context) throws BeansException { public void setApplicationContext(ApplicationContext context) throws BeansException {
applicationContext = context; synchronized (CurrentApplicationContext.class) {
applicationContext = context;
}
} }
/** /**
......
...@@ -46,7 +46,8 @@ public class JsonSidConverter extends StdConverter<Object, String> { ...@@ -46,7 +46,8 @@ public class JsonSidConverter extends StdConverter<Object, String> {
if (value == null) { if (value == null) {
return null; return null;
} else if (value instanceof AclSid) { } else if (value instanceof AclSid) {
return SID_PROVIDER == null ? value.toString() : SID_PROVIDER.getSidName(((AclSid) value).getId()); var sid = (AclSid) value;
return SID_PROVIDER == null || sid.getId() == null ? value.toString() : SID_PROVIDER.getSidName(sid.getId());
} else if (value instanceof Long) { } else if (value instanceof Long) {
return SID_PROVIDER == null ? value.toString() : SID_PROVIDER.getSidName((Long) value); return SID_PROVIDER == null ? value.toString() : SID_PROVIDER.getSidName((Long) value);
} }
......
...@@ -47,7 +47,6 @@ import org.springframework.security.oauth2.provider.token.TokenStore; ...@@ -47,7 +47,6 @@ import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
...@@ -157,12 +156,12 @@ public class ApplicationConfig { ...@@ -157,12 +156,12 @@ public class ApplicationConfig {
@Override @Override
public Collection<UserRole> getDefaultUserRoles() { public Collection<UserRole> getDefaultUserRoles() {
return Sets.newHashSet(UserRole.USER, UserRole.EVERYONE); return Set.of(UserRole.USER, UserRole.EVERYONE);
} }
@Override @Override
public List<UserRole> listAvailableRoles() { public List<UserRole> listAvailableRoles() {
return Lists.asList(UserRole.ADMINISTRATOR, UserRole.USER, null); return List.of(UserRole.ADMINISTRATOR, UserRole.USER);
} }
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment