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
if (isPrimitiveType(types[i].getReturnedClass())) {
// 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())) {
final EntityId prevEntity = (EntityId) state;
final String previousValue = prevEntity == null ? null : prevEntity.getId().toString();
......
......@@ -103,10 +103,10 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/
@Override
public Object get(ClassPK classPk, Long id) {
LOG.trace("Looking up {} id={}", classPk.getClassname(), id);
if (id == null || classPk == null || classPk.getClassname() == null) {
return null;
}
LOG.trace("Looking up {} id={}", classPk.getClassname(), id);
try {
return entityManager.find(Class.forName(classPk.getClassname()), id);
} catch (ClassNotFoundException e) {
......
......@@ -42,14 +42,6 @@ public class DateFilter {
// <
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.
*
......@@ -74,10 +66,6 @@ public class DateFilter {
and.and(date.isNotNull());
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;
}
......@@ -100,9 +88,6 @@ public class DateFilter {
if (lt != null) {
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,}", " ");
}
......
......@@ -192,6 +192,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final String resetSecret(OAuthClient oauthClient) {
assert oauthClient != null;
assert oauthClient.getId() != null;
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
String oldHash = oauthClient.getClientSecret();
......@@ -203,7 +206,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
} while (oldHash != null && oldHash.equals(newHash));
oauthClient.setClientSecret(newHash);
oauthClient = oauthClientRepository.save(oauthClient);
oauthClientRepository.save(oauthClient);
return clientSecret;
}
......@@ -211,6 +214,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final OAuthClient removeSecret(OAuthClient oauthClient) {
assert oauthClient != null;
assert oauthClient.getId() != null;
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (oauthClient.getAuthorizedGrantTypes().contains("client_credentials")) {
throw new RuntimeException("OAuth Client with client_credentials grant must have a secret");
......
......@@ -605,6 +605,7 @@ public class CustomAclServiceImpl implements CustomAclService {
if (objectIdentity == null) {
throw new NullPointerException("AclObjectIdentity must be provided, was null.");
}
assert objectIdentity.getId() != null;
if (sid == null) {
throw new NullPointerException("AclSid must be provided, was null.");
}
......
......@@ -50,11 +50,13 @@ import org.springframework.context.ApplicationContextAware;
public class CurrentApplicationContext implements ApplicationContextAware {
/** The application context. */
static ApplicationContext applicationContext = null;
static volatile ApplicationContext applicationContext = null;
public void setApplicationContext(ApplicationContext context) throws BeansException {
synchronized (CurrentApplicationContext.class) {
applicationContext = context;
}
}
/**
* Note that this is a static method which expose ApplicationContext.
......
......@@ -46,7 +46,8 @@ public class JsonSidConverter extends StdConverter<Object, String> {
if (value == null) {
return null;
} 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) {
return SID_PROVIDER == null ? value.toString() : SID_PROVIDER.getSidName((Long) value);
}
......
......@@ -47,7 +47,6 @@ import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
......@@ -157,12 +156,12 @@ public class ApplicationConfig {
@Override
public Collection<UserRole> getDefaultUserRoles() {
return Sets.newHashSet(UserRole.USER, UserRole.EVERYONE);
return Set.of(UserRole.USER, UserRole.EVERYONE);
}
@Override
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