Skip to content

Commit

Permalink
Changing default values in case of no authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
alainbodiguel committed Aug 4, 2020
1 parent 6571bd4 commit 5c08bdf
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.arlas.server.utils.ResponseFormatter;
import io.dropwizard.hibernate.UnitOfWork;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,6 +40,7 @@
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.util.*;
import java.util.stream.Collectors;


@Path("/persist")
Expand Down Expand Up @@ -450,20 +450,19 @@ public Response delete(
.build();
}

private String getKey(HttpHeaders headers, String keyHeader) {
String key = headers.getHeaderString(keyHeader);
if (StringUtils.isBlank(key)) {
key = this.anonymousValue;
}
private IdentityParam getIdentityParam(HttpHeaders headers) {
String userId = Optional.ofNullable(headers.getHeaderString(this.userHeader))
.orElse(this.anonymousValue);

return key;
}
String organization = Optional.ofNullable(headers.getHeaderString(this.organizationHeader))
.orElse(""); // in a context where resources are publicly available, no organisation is defined

private IdentityParam getIdentityParam(HttpHeaders headers) {
String userId = getKey(headers, this.userHeader);
String organization = getKey(headers, this.organizationHeader);
List<String> groups = Arrays.asList(getKey(headers, this.groupsHeader).trim().split("\\s*,+\\s*,*\\s*"));
LOGGER.info("User: " + userId + "/ Org: " + organization + "/ Groups: " + groups.toString());
List<String> groups = Arrays.stream(
Optional.ofNullable(headers.getHeaderString(this.groupsHeader)).orElse("group/public").split(","))
.map(g -> g.trim())
.collect(Collectors.toList());

LOGGER.info("User='" + userId + "' / Org='" + organization + "' / Groups='" + groups.toString() + "'");
return new IdentityParam(userId, organization, groups);
}
}

0 comments on commit 5c08bdf

Please sign in to comment.