Commit eb00c5d5 authored by Valentin Suhnjov's avatar Valentin Suhnjov

RIHAKB-130. Remove AuthInfo parameter from SecureApiGenericDAO

parent 26a6479e
......@@ -2,7 +2,6 @@ package ee.eesti.riha.rest.dao;
import java.util.List;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.util.FilterComponent;
import ee.eesti.riha.rest.error.RihaRestException;
......@@ -14,31 +13,29 @@ import ee.eesti.riha.rest.error.RihaRestException;
*/
public interface SecureApiGenericDAO<T, K> {
List<T> find(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents, String sort,
AuthInfo authInfo)
List<T> find(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents, String sort)
throws RihaRestException;
T find(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException;
T find(Class<T> clazz, Integer id) throws RihaRestException;
List<T> findByMainResourceId(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException;
List<T> findByMainResourceId(Class<T> clazz, Integer id) throws RihaRestException;
Integer findCount(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents, String sort,
AuthInfo authInfo)
Integer findCount(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents, String sort)
throws RihaRestException;
Integer findCount(Class<T> clazz, AuthInfo authInfo) throws RihaRestException;
Integer findCount(Class<T> clazz) throws RihaRestException;
List<K> create(T object, AuthInfo authInfo) throws RihaRestException;
List<K> create(T object) throws RihaRestException;
List<K> create(List<T> object, AuthInfo authInfo) throws RihaRestException;
List<K> create(List<T> object) throws RihaRestException;
int update(T object, Integer id, AuthInfo authInfo) throws RihaRestException;
int update(T object, Integer id) throws RihaRestException;
int update(List<T> object, String idFieldName, AuthInfo authInfo) throws NoSuchFieldException, SecurityException,
int update(List<T> object, String idFieldName) throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, RihaRestException;
int delete(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException;
int delete(Class<T> clazz, Integer id) throws RihaRestException;
int delete(String tableName, String key, Object[] values, AuthInfo authInfo) throws RihaRestException;
int delete(String tableName, String key, Object[] values) throws RihaRestException;
}
......@@ -11,10 +11,8 @@ import org.springframework.stereotype.Component;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.util.FilterComponent;
import ee.eesti.riha.rest.error.RihaRestException;
import ee.eesti.riha.rest.logic.AuthInfoCreator;
import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.logic.TableEntryCreateLogic;
import ee.eesti.riha.rest.logic.Validator;
......@@ -28,9 +26,6 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
@Autowired
private ApiGenericDAO<T, K> genericDAO;
@Autowired
private AuthInfoCreator authInfoCreator;
private static final Logger LOG = LoggerFactory.getLogger(SecureApiGenericDAOImpl.class);
// LOGIC
......@@ -46,14 +41,14 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
@Override
public List<T> find(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents,
String sort, AuthInfo authInfo) throws RihaRestException {
String sort) throws RihaRestException {
System.out.println("FIND MANY");
return genericDAO.find(clazz, limit, offset, filterComponents, sort);
}
@Override
public T find(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException {
public T find(Class<T> clazz, Integer id) throws RihaRestException {
T item = genericDAO.find(clazz, id);
if (item == null) {
......@@ -64,7 +59,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public List<T> findByMainResourceId(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException {
public List<T> findByMainResourceId(Class<T> clazz, Integer id) throws RihaRestException {
// main_resource is already checked on higher level that it may be read (ServicLogic.getResourceById)
......@@ -74,7 +69,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
@Override
// TODO Milleks limit, offset ja sort siin?
public Integer findCount(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents,
String sort, AuthInfo authInfo) throws RihaRestException {
String sort) throws RihaRestException {
if (limit != null && limit == 0) {
// special case for count
......@@ -85,13 +80,13 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public Integer findCount(Class<T> clazz, AuthInfo authInfo) throws RihaRestException {
public Integer findCount(Class<T> clazz) throws RihaRestException {
return genericDAO.findCount(clazz);
}
@Override
public List<K> create(T object, AuthInfo authInfo) throws RihaRestException {
public List<K> create(T object) throws RihaRestException {
System.out.println("CREATE " + JsonHelper.GSON.toJson(object));
Validator.documentMustHaveReference(object);
......@@ -100,7 +95,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public List<K> create(List<T> objects, AuthInfo authInfo) throws RihaRestException {
public List<K> create(List<T> objects) throws RihaRestException {
for (T object : objects) {
Validator.documentMustHaveReference(object);
......@@ -110,7 +105,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public int update(T object, Integer id, AuthInfo authInfo) throws RihaRestException {
public int update(T object, Integer id) throws RihaRestException {
System.out.println("CLASS " + object.getClass());
T old = genericDAO.find((Class<T>) object.getClass(), id);
......@@ -125,7 +120,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public int update(List<T> objects, String idFieldName, AuthInfo authInfo) throws NoSuchFieldException,
public int update(List<T> objects, String idFieldName) throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException, RihaRestException {
for (T object : objects) {
......@@ -142,7 +137,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public int delete(Class<T> clazz, Integer id, AuthInfo authInfo) throws RihaRestException {
public int delete(Class<T> clazz, Integer id) throws RihaRestException {
T old = genericDAO.find(clazz, id);
try {
......@@ -156,7 +151,7 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
}
@Override
public int delete(String tableName, String key, Object[] values, AuthInfo authInfo) throws RihaRestException {
public int delete(String tableName, String key, Object[] values) throws RihaRestException {
Class<T> clazz = Finals.getClassRepresentingTable(tableName);
......
......@@ -107,7 +107,7 @@ public class ChangeLogic<T, K> {
try {
addEscapedQuotesToJsonArray(filterComponents);
// all = genericDAO.find(classRepresentingTable, limit, offset, filterComponents, sort);
all = secureDAO.find(classRepresentingTable, limit, offset, filterComponents, sort, authInfo);
all = secureDAO.find(classRepresentingTable, limit, offset, filterComponents, sort);
replaceContentWithFileUrl(all, authInfo, appConfigURL.getRestApiBaseUrl());
all = filterByFields(all, fields);
......@@ -238,7 +238,7 @@ public class ChangeLogic<T, K> {
throws RihaRestException {
// List<T> entityList = genericDAO.findByMainResourceId(classRepresentingTable, id);
List<T> entityList = secureDAO.findByMainResourceId(classRepresentingTable, id, authInfo);
List<T> entityList = secureDAO.findByMainResourceId(classRepresentingTable, id);
entityList = tableEntryReadLogic.getAdjustedObjsBasedOnExpectedJson(entityList, null);
// INFO: file content inclusion
......@@ -261,7 +261,7 @@ public class ChangeLogic<T, K> {
throws RihaRestException {
// T entity = genericDAO.find(classRepresentingTable, id);
T entity = secureDAO.find(classRepresentingTable, id, authInfo);
T entity = secureDAO.find(classRepresentingTable, id);
Validator.noSuchIdInGivenTable(entity, id);
replaceContentWithFileUrl(entity, id, authInfo, appConfigURL.getRestApiBaseUrl());
......@@ -345,14 +345,14 @@ public class ChangeLogic<T, K> {
LOG.info("COMPARE " + queryHolder.getLimit() + " == Finals -1");
if (queryHolder.getLimit() == Finals.COUNT_ALL_LIMIT) {
// count = genericDAO.findCount(classRepresentingTable);
count = secureDAO.findCount(classRepresentingTable, authInfo);
count = secureDAO.findCount(classRepresentingTable);
} else {
// needed for ?& operator
addEscapedQuotesToJsonArray((List<FilterComponent>) queryHolder.getFilter());
// count = genericDAO.findCount(classRepresentingTable, queryHolder.getLimit(), queryHolder.getOffset(),
// (List<FilterComponent>) queryHolder.getFilter(), queryHolder.getSort());
count = secureDAO.findCount(classRepresentingTable, queryHolder.getLimit(), queryHolder.getOffset(),
(List<FilterComponent>) queryHolder.getFilter(), queryHolder.getSort(), authInfo);
(List<FilterComponent>) queryHolder.getFilter(), queryHolder.getSort());
}
} else {
// find by id
......@@ -411,7 +411,7 @@ public class ChangeLogic<T, K> {
FileHelper.writeDocumentContentToFile(item);
// List<K> createdKey = genericDAO.create(item);
Validator.infosystemMustHaveFields(item, kindRepository);
List<K> createdKey = secureDAO.create(item, (AuthInfo) user);
List<K> createdKey = secureDAO.create(item);
createdKeys.add(createdKey.get(0));
} catch (Exception e) {
// if unsuccessful, then store error
......@@ -451,7 +451,7 @@ public class ChangeLogic<T, K> {
Validator.infosystemMustHaveFields(item, kindRepository);
// createdKeys = genericDAO.create(item);
createdKeys = secureDAO.create(item, (AuthInfo) user);
createdKeys = secureDAO.create(item);
} catch (RihaRestException e) {
throw e;
......@@ -522,7 +522,7 @@ public class ChangeLogic<T, K> {
idFieldName = Finals.KIND_ID;
}
// numOfChanged = genericDAO.update(itemList, idFieldName);
numOfChanged = secureDAO.update(itemList, idFieldName, (AuthInfo) user);
numOfChanged = secureDAO.update(itemList, idFieldName);
// throws exception if numOfChanged has error code as result
Validator.fieldMustExistInDatabase(numOfChanged, idFieldName);
......@@ -547,7 +547,7 @@ public class ChangeLogic<T, K> {
FileHelper.writeDocumentContentToFile(item);
// numOfChanged = genericDAO.update(item, id);
numOfChanged = secureDAO.update(item, id, (AuthInfo) user);
numOfChanged = secureDAO.update(item, id);
} else {
RihaRestError error = new RihaRestError();
......@@ -732,7 +732,7 @@ public class ChangeLogic<T, K> {
int numOfDeleted = 0;
try {
// numOfDeleted = genericDAO.delete(tableName, key, values);
numOfDeleted = secureDAO.delete(tableName, key, values, authInfo);
numOfDeleted = secureDAO.delete(tableName, key, values);
Validator.fieldMustExistInDatabase(numOfDeleted, key);
} catch (SQLGrammarException e) {
......@@ -777,7 +777,7 @@ public class ChangeLogic<T, K> {
Class<T> clazz = Finals.getClassRepresentingTable(tableName);
// int numOfDeleted = genericDAO.delete(clazz, id);
int numOfDeleted = secureDAO.delete(clazz, id, authInfo);
int numOfDeleted = secureDAO.delete(clazz, id);
if ((Class<T>) Finals.getClassRepresentingTable(tableName) == Document.class) {
LOG.info("IS DOCUMENT");
......
......@@ -136,7 +136,7 @@ public class NewVersionLogic<T, K> {
classRepresentingTable, user);
// genericDAO.create(itemTemp);
List<Integer> archivedKeys = (List<Integer>) secureDAO.create(itemTemp, (AuthInfo) user);
List<Integer> archivedKeys = (List<Integer>) secureDAO.create(itemTemp);
// doCreate(tempJson.toString(), classRepresentingTable, user);
// temp = doGet(classRepresentingTable, id, null, null);
......@@ -255,7 +255,7 @@ public class NewVersionLogic<T, K> {
T itemTemp = (T) tableEntryCreateLogic.fromJsonContentToObjKeepExisting(docJson.toString(),
clazz, user);
// save archived item to database
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp, user);
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp);
docIdMap.put(id, createdKeys.get(0));
}
......@@ -305,7 +305,7 @@ public class NewVersionLogic<T, K> {
Document doc = JsonHelper.GSON.fromJson(updateJson, Document.class);
doc.setJson_content(updateJson);
secureDAO.update((T) doc, archivedDocId, user);
secureDAO.update((T) doc, archivedDocId);
LOG.info("update successful? time to copy files");
try {
LOG.info("Copying file in new version current to archived");
......@@ -352,7 +352,7 @@ public class NewVersionLogic<T, K> {
T itemTemp = (T) tableEntryCreateLogic.fromJsonContentToObjKeepExisting(dataJson.toString(),
clazz, user);
// save archived item to database
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp, user);
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp);
}
// get unmodified connected Data_objects
......
......@@ -7,33 +7,22 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.exception.ConstraintViolationException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.gson.JsonArray;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.util.FilterComponent;
import ee.eesti.riha.rest.error.ErrorCodes;
import ee.eesti.riha.rest.error.RihaRestError;
import ee.eesti.riha.rest.error.RihaRestException;
import ee.eesti.riha.rest.integration.TestFinals;
import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.logic.util.JsonHelper;
import ee.eesti.riha.rest.model.Document;
import ee.eesti.riha.rest.model.Main_resource;
import ee.eesti.riha.rest.model.readonly.Asutus;
import ee.eesti.riha.rest.model.readonly.Kind;
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -107,7 +96,7 @@ public class TestSecureApiGenericDAO<T, K> {
// use limit, otherwise too slow to show all elements ~200MB
main_resources = (List<Main_resource>) secureGenericDAO.find(
(Class<T>) Main_resource.class, limit, null, null,
null, authInfo);
null);
assertNotNull(main_resources);
assertFalse(main_resources.isEmpty());
......@@ -124,7 +113,7 @@ public class TestSecureApiGenericDAO<T, K> {
// use limit, otherwise too slow to show all elements ~200MB
documents = (List<Document>) secureGenericDAO.find(
(Class<T>) Document.class, limit, null, null,
null, authInfo);
null);
assertNotNull(documents);
assertFalse(documents.isEmpty());
......@@ -137,7 +126,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createTestMain_resource();
mr.setOwner("ORG");
additionalMrTestEntries.add(mr);
List<K> keys = secureGenericDAO.create((T) mr, superAuthInfo);
List<K> keys = secureGenericDAO.create((T) mr);
System.out.println(keys);
assertNotNull(keys);
assertFalse(keys.isEmpty());
......@@ -149,7 +138,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createTestMain_resource();
mr.setOwner("ORG");
additionalMrTestEntries.add(mr);
List<K> keys = secureGenericDAO.create((List<T>)Arrays.asList(mr), superAuthInfo);
List<K> keys = secureGenericDAO.create((List<T>)Arrays.asList(mr));
System.out.println(keys);
assertNotNull(keys);
assertFalse(keys.isEmpty());
......@@ -161,7 +150,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createTestMain_resource();
mr.setOwner("ORG");
additionalMrTestEntries.add(mr);
List<K> keys = secureGenericDAO.create((List<T>)Arrays.asList(mr), authInfo);
List<K> keys = secureGenericDAO.create((List<T>)Arrays.asList(mr));
System.out.println(keys);
}
......@@ -173,7 +162,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createSimpleTestMain_resource(old);
int updated = secureGenericDAO.update((T) mr, old.callGetId(), superAuthInfo);
int updated = secureGenericDAO.update((T) mr, old.callGetId());
System.out.println(updated);
assertTrue(updated > 0);
assertEquals(1, updated);
......@@ -187,7 +176,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createSimpleTestMain_resource(old);
int updated = secureGenericDAO.update((List<T>)Arrays.asList(mr), "name", superAuthInfo);
int updated = secureGenericDAO.update((List<T>)Arrays.asList(mr), "name");
System.out.println(updated);
assertTrue(updated > 0);
assertEquals(1, updated);
......@@ -201,7 +190,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource mr = createSimpleTestMain_resource(old);
int updated = secureGenericDAO.update((List<T>)Arrays.asList(mr), "name", authInfo);
int updated = secureGenericDAO.update((List<T>)Arrays.asList(mr), "name");
System.out.println(updated);
}
......@@ -213,7 +202,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource old = mrAsPrimeTestEntry;
System.out.println(JsonHelper.GSON.toJson(old));
int delete = secureGenericDAO.delete((Class<T>) Main_resource.class, old.callGetId(), superAuthInfo);
int delete = secureGenericDAO.delete((Class<T>) Main_resource.class, old.callGetId());
System.out.println(delete);
assertTrue(delete > 0);
assertEquals(1, delete);
......@@ -225,7 +214,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource old = mrAsPrimeTestEntry;
System.out.println(JsonHelper.GSON.toJson(old));
int delete = secureGenericDAO.delete(Main_resource.class.getSimpleName(), "name", new String[]{EXAMPLE_NAME}, superAuthInfo);
int delete = secureGenericDAO.delete(Main_resource.class.getSimpleName(), "name", new String[]{EXAMPLE_NAME});
System.out.println(delete);
assertTrue(delete > 0);
assertEquals(1, delete);
......@@ -237,7 +226,7 @@ public class TestSecureApiGenericDAO<T, K> {
Main_resource old = mrAsPrimeTestEntry;
System.out.println(JsonHelper.GSON.toJson(old));
int delete = secureGenericDAO.delete(Main_resource.class.getSimpleName(), "name", new String[]{EXAMPLE_NAME}, authInfo);
int delete = secureGenericDAO.delete(Main_resource.class.getSimpleName(), "name", new String[]{EXAMPLE_NAME});
System.out.println(delete);
}
......
......@@ -2,7 +2,6 @@ package ee.eesti.riha.rest.stress;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -39,7 +38,7 @@ public class TestCount {
// fetch
Integer count = secureDao.findCount(Main_resource.class, LIMIT, null,
null, null, authInfo);
null, null);
// assume we get LIMIT amount of results
assertEquals(LIMIT, count);
......
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