Skip to content

Commit

Permalink
Issue #861
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Oct 13, 2024
1 parent a943d66 commit 04bb41c
Show file tree
Hide file tree
Showing 48 changed files with 375 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ public Response addItemToCollection(@PathParam("pid") String collectionPid,@Quer
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addItemsToCollection(@PathParam("pid") String collectionPid, @QueryParam("indexation") String indexation, String itemsPidsJsonArrayStr) { //primo JSONArray itemsPids jako parametr nefunguje
System.out.println(itemsPidsJsonArrayStr);
try {
//parse JSON Array on input
JSONArray itemsPid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ public Response getProcessByProcessUuid(@PathParam("process_uuid") String proces
throw new ForbiddenException("user '%s' is not allowed to manage processes (missing action '%s', '%s')", user.getLoginname(), SecuredActions.A_PROCESS_EDIT.name(), SecuredActions.A_PROCESS_READ.name()); //403
}



JSONObject result = processInBatchToJson(processInBatch);
return Response.ok().entity(result.toString()).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,19 @@ public Response exportLogs(@QueryParam("dateFrom") String dateFrom, @QueryParam(
JSONArray docsArray = responseObj.getJSONArray("docs");
for (int i = 0; i < docsArray.length(); i++) {
JSONObject doc = docsArray.getJSONObject(i);

String userSessionAttributes = doc.getString("user_session_attributes");
JSONObject changedObj = AnonymizationSupport.annonymizeObject(keys, userSessionAttributes);
doc.put("user_session_attributes", changedObj.toString());

//doc.put("user_session_attributes", changedObj.toString());
doc.remove("user_session_attributes");
Set keySet = changedObj.keySet();
for (Object key : keySet) {
if (!doc.has(key.toString())) {
doc.put(key.toString(), changedObj.get(key.toString()));
}
}


for (String key : keys) {
if (doc.has(key)) {
Object object = doc.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
package cz.incad.kramerius.rest.apiNew.client.v70.res;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -30,13 +35,30 @@

import org.apache.commons.io.IOUtils;

import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.SolrAccess;
import cz.incad.kramerius.rest.apiNew.admin.v70.FoxmlBuilder;
import cz.incad.kramerius.security.RightsResolver;
import cz.incad.kramerius.security.SecuredActions;
import cz.incad.kramerius.security.SpecialObjects;
import cz.incad.kramerius.security.User;

@Path("/client/v7.0/embedded/files")
public class EmbeddedFilesResource {



public static final String OPENAPI_PREFIX = "openapi";

private static final Map<String, String> mimeTypeMap = new HashMap<>();

@javax.inject.Inject
Provider<User> userProvider;


@Inject
RightsResolver rightsResolver;


static {
mimeTypeMap.put("js", "application/javascript");
mimeTypeMap.put("html", "text/html");
Expand All @@ -53,26 +75,45 @@ public class EmbeddedFilesResource {
@Produces(MediaType.APPLICATION_JSON)
public Response getEmbbededFile(@PathParam("path") String path) {
try {
URL resource = this.getClass().getClassLoader().getResource("/"+OPENAPI_PREFIX + File.separator + path);
if (resource != null) {
String content = IOUtils.toString(resource.openStream(), "UTF-8");
String file = resource.getFile();
if (file.contains(".")) {
String postfix = file.substring(file.lastIndexOf('.')+1);
if (mimeTypeMap.containsKey(postfix)) {
return Response.ok().entity(content).type(mimeTypeMap.get(postfix)+ "; charset=UTF-8").build();
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
}
if (path.contains("admin/")) {
if (permit(userProvider.get())) {
return findEmbeddedFile(path);
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
return Response.status(403).build();
}
} else {
return Response.status(Response.Status.NOT_FOUND).build();
return findEmbeddedFile(path);
}
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

boolean permit(User user) {
if (user != null)
return this.rightsResolver.isActionAllowed(user, SecuredActions.A_ADMIN_API_SPECIFICATION_READ.getFormalName(), SpecialObjects.REPOSITORY.getPid(), null , ObjectPidsPath.REPOSITORY_PATH).flag();
else
return false;
}

private Response findEmbeddedFile(String path) throws IOException {
URL resource = this.getClass().getClassLoader().getResource("/"+OPENAPI_PREFIX + File.separator + path);
if (resource != null) {
String content = IOUtils.toString(resource.openStream(), "UTF-8");
String file = resource.getFile();
if (file.contains(".")) {
String postfix = file.substring(file.lastIndexOf('.')+1);
if (mimeTypeMap.containsKey(postfix)) {
return Response.ok().entity(content).type(mimeTypeMap.get(postfix)+ "; charset=UTF-8").build();
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
}
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
}
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
}

}
11 changes: 5 additions & 6 deletions rest/src/main/resources/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ paths:
content:
application/json:
schema:
$ref: './schemas/client/InfoResponse.yaml'
type: string
example: |
{
"image": {
Expand Down Expand Up @@ -352,7 +352,7 @@ paths:
content:
application/json:
schema:
$ref: './schemas/client/InfoResponse.yaml'
type: string
example: |
{"type":"tiles"}
'400':
Expand Down Expand Up @@ -383,7 +383,7 @@ paths:
content:
application/json:
schema:
$ref: './schemas/client/InfoResponse.yaml'
type: string
example: |
{
"licenses":[
Expand Down Expand Up @@ -418,7 +418,7 @@ paths:
content:
application/json:
schema:
$ref: './schemas/client/InfoResponse.yaml'
type: string
example: |
{
"children": {
Expand Down Expand Up @@ -483,7 +483,7 @@ paths:
content:
application/json:
schema:
$ref: './schemas/client/InfoResponse.yaml'
type: string
example: |
{
"image": {
Expand Down Expand Up @@ -571,7 +571,6 @@ paths:
content:
application/xml:
schema:
#$ref: './schemas/client/MetadataResponse.yaml#/components/schemas/MetadataResponse'
type: string
examples:
dc:
Expand Down
133 changes: 0 additions & 133 deletions rest/src/main/resources/openapi/schemas/client/InfoResponse.yaml

This file was deleted.

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes.
Loading

0 comments on commit 04bb41c

Please sign in to comment.