use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class TriggerProcessExecutor method assertRoles.
private void assertRoles(String eventName) {
if (Roles.isAdmin()) {
return;
}
// optional feature: require a specific user role to access the external events endpoint
Map<String, String> requiredRoles = eventsCfg.getRequiredRoles();
if (requiredRoles == null || requiredRoles.isEmpty()) {
return;
}
Subject s = SecurityUtils.getSubject();
requiredRoles.forEach((k, v) -> {
if (eventName.matches(k) && !s.hasRole(v)) {
throw new ConcordApplicationException("'" + v + "' role is required", Response.Status.FORBIDDEN);
}
});
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ConsoleService method whoami.
@GET
@Path("/whoami")
@Produces(MediaType.APPLICATION_JSON)
public UserResponse whoami() {
UserPrincipal p = UserPrincipal.getCurrent();
if (p == null) {
throw new ConcordApplicationException("Can't determine current user: pricipal not found", Status.INTERNAL_SERVER_ERROR);
}
UserEntry u = p.getUser();
if (u == null) {
throw new ConcordApplicationException("Can't determine current user: user entry not found", Status.INTERNAL_SERVER_ERROR);
}
String displayName = u.getDisplayName();
if (displayName == null) {
LdapPrincipal l = LdapPrincipal.getCurrent();
if (l != null) {
displayName = l.getDisplayName();
}
}
if (displayName == null) {
displayName = p.getUsername();
}
UserEntry user = userManager.get(p.getId()).orElseThrow(() -> new ConcordApplicationException("Unknown user: " + p.getId()));
return new UserResponse(p.getRealm(), user.getName(), user.getDomain(), displayName, user.getOrgs());
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ConsoleService method testRepository.
@POST
@Path("/repository/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean testRepository(RepositoryTestRequest req) {
OrganizationEntry org = orgManager.assertAccess(null, req.getOrgName(), false);
ProjectEntry project = projectAccessManager.assertAccess(org.getId(), null, req.getProjectName(), ResourceAccessLevel.READER, false);
try {
String secretName = secretDao.getName(req.getSecretId());
repositoryManager.testConnection(project.getOrgId(), project.getId(), req.getUrl(), req.getBranch(), req.getCommitId(), req.getPath(), secretName);
return true;
} catch (InvalidRepositoryPathException e) {
Map<String, String> m = new HashMap<>();
m.put("message", "Repository validation error");
m.put("level", "WARN");
m.put("details", e.getMessage());
throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(m).build());
} catch (Exception e) {
String msg;
Throwable t = e;
while (true) {
msg = t.getMessage();
t = t.getCause();
if (t == null) {
break;
}
}
if (msg == null) {
msg = "Repository test error";
}
throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).entity(msg).build());
}
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class JsonStoreDataManager method assertStorageDataPolicy.
private void assertStorageDataPolicy(UUID orgId, UUID storeId, long currentItemSize, String jsonData) {
PolicyEngine policy = policyManager.get(orgId, null, UserPrincipal.assertCurrent().getUser().getId());
if (policy == null) {
return;
}
CheckResult<JsonStoreRule.StoreDataRule, Long> result;
try {
result = policy.getJsonStoragePolicy().checkStorageData(() -> storeDataDao.getSize(storeId) - currentItemSize + jsonData.length());
} catch (Exception e) {
throw new RuntimeException(e);
}
if (!result.getDeny().isEmpty()) {
throw new ConcordApplicationException("Found JSON store policy violations: " + buildErrorMessage(result.getDeny()));
}
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class JsonStoreManager method assertStoragePolicy.
private void assertStoragePolicy(UUID orgId) {
PolicyEngine policy = policyManager.get(orgId, null, UserPrincipal.assertCurrent().getUser().getId());
if (policy == null) {
return;
}
CheckResult<JsonStoreRule.StoreRule, Integer> result;
try {
result = policy.getJsonStoragePolicy().checkStorage(() -> storeDao.count(orgId));
} catch (Exception e) {
throw new RuntimeException(e);
}
if (!result.getDeny().isEmpty()) {
throw new ConcordApplicationException("Found JSON store policy violations: " + buildErrorMessage(result.getDeny()));
}
}
Aggregations