Skip to content
Snippets Groups Projects
Commit 140bf425 authored by cramakri's avatar cramakri
Browse files

LMS-1153 Added collection versions of data set access predicate.

SVN: 15683
parent 48800996
No related branches found
No related tags found
No related merge requests found
...@@ -252,12 +252,28 @@ public final class PredicateExecutor ...@@ -252,12 +252,28 @@ public final class PredicateExecutor
Session sess = daoFactory.getSessionFactory().getCurrentSession(); Session sess = daoFactory.getSessionFactory().getCurrentSession();
Query query = sess.getNamedQuery(DataSetAccessPE.DATASET_ACCESS_QUERY_NAME); Query query = sess.getNamedQuery(DataSetAccessPE.DATASET_ACCESS_QUERY_NAME);
query = query.setReadOnly(true); query = query.setReadOnly(true);
List<DataSetAccessPE> results = query.setString(0, dataSetCode).list(); String[] codes =
{ dataSetCode };
List<DataSetAccessPE> results =
query.setParameterList(DataSetAccessPE.DATA_SET_CODES_PARAMETER_NAME, codes)
.list();
if (results.size() < 1) if (results.size() < 1)
return null; return null;
return results.get(0); return results.get(0);
} }
@SuppressWarnings("unchecked")
public List<DataSetAccessPE> tryGetDatasetCollectionAccessData(List<String> dataSetCodes)
{
Session sess = daoFactory.getSessionFactory().getCurrentSession();
Query query = sess.getNamedQuery(DataSetAccessPE.DATASET_ACCESS_QUERY_NAME);
query = query.setReadOnly(true);
List<DataSetAccessPE> results =
query.setParameterList(DataSetAccessPE.DATA_SET_CODES_PARAMETER_NAME,
dataSetCodes).list();
return results;
}
public GroupPE tryToGetGroup(SpaceOwnerKind kind, TechId techId) public GroupPE tryToGetGroup(SpaceOwnerKind kind, TechId techId)
{ {
switch (kind) switch (kind)
......
...@@ -48,10 +48,15 @@ public interface IAuthorizationDataProvider extends IDatabaseInstanceFinder ...@@ -48,10 +48,15 @@ public interface IAuthorizationDataProvider extends IDatabaseInstanceFinder
public ProjectPE tryToGetProject(String dataSetCode); public ProjectPE tryToGetProject(String dataSetCode);
/** /**
* Returns the information necessary to determine if a user is allowed to access this dataset. * Returns the information necessary to determine if a user is allowed to access this data set.
*/ */
public DataSetAccessPE tryGetDatasetAccessData(String dataSetCode); public DataSetAccessPE tryGetDatasetAccessData(String dataSetCode);
/**
* Returns the information necessary to determine if a user is allowed to access the data sets.
*/
public List<DataSetAccessPE> tryGetDatasetCollectionAccessData(List<String> dataSetCodes);
/** /**
* Returns the group of an entity with given <var>entityKind</var> and <var>techId</var> * Returns the group of an entity with given <var>entityKind</var> and <var>techId</var>
* *
......
/*
* Copyright 2009 ETH Zuerich, CISD
*
* 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 ch.systemsx.cisd.openbis.generic.shared.authorization.predicate;
import java.util.List;
import ch.systemsx.cisd.common.exceptions.Status;
import ch.systemsx.cisd.openbis.generic.shared.authorization.RoleWithIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetAccessPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
/**
* A {@link IPredicate} based on a list of data set codes.
*
* @author Franz-Josef Elmer
*/
public class DataSetCodeCollectionPredicate extends AbstractGroupPredicate<List<String>>
{
@Override
public String getCandidateDescription()
{
return "data set code";
}
@Override
Status doEvaluation(PersonPE person, List<RoleWithIdentifier> allowedRoles,
List<String> dataSetCodes)
{
assert initialized : "Predicate has not been initialized";
List<DataSetAccessPE> accessData =
authorizationDataProvider.tryGetDatasetCollectionAccessData(dataSetCodes);
if (accessData == null)
{
return Status.OK;
}
if (accessData.size() < dataSetCodes.size())
{
return Status.createError("Could not get access data for all datasets");
}
for (DataSetAccessPE accessDatum : accessData)
{
String dbInstanceUUID = accessDatum.getDatabaseInstanceUuid();
String dbInstanceCode = accessDatum.getDatabaseInstanceCode();
String groupCode = accessDatum.getGroupCode();
Status result =
evaluate(person, allowedRoles, dbInstanceUUID, dbInstanceCode, groupCode);
if (result != Status.OK)
{
return result;
}
}
return Status.OK;
}
}
...@@ -43,7 +43,7 @@ import javax.persistence.SqlResultSetMapping; ...@@ -43,7 +43,7 @@ import javax.persistence.SqlResultSetMapping;
+ " g, " + " g, "
+ TableNames.DATABASE_INSTANCES_TABLE + TableNames.DATABASE_INSTANCES_TABLE
+ " dbi " + " dbi "
+ "where ds.code=? and e.id = ds.expe_id and p.id = e.proj_id and g.id = p.grou_id and dbi.id = g.dbin_id", resultSetMapping = "implicit") + "where ds.code in (:codes) and e.id = ds.expe_id and p.id = e.proj_id and g.id = p.grou_id and dbi.id = g.dbin_id", resultSetMapping = "implicit")
public class DataSetAccessPE public class DataSetAccessPE
{ {
private String dataSetId; private String dataSetId;
...@@ -58,6 +58,8 @@ public class DataSetAccessPE ...@@ -58,6 +58,8 @@ public class DataSetAccessPE
public final static String DATASET_ACCESS_QUERY_NAME = "dataset_access"; public final static String DATASET_ACCESS_QUERY_NAME = "dataset_access";
public final static String DATA_SET_CODES_PARAMETER_NAME = "codes";
/** /**
* A factory method that should only be used for testing. * A factory method that should only be used for testing.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment