use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RoleRepresenter method fromJSON.
// private static void addLinks(Role model, JsonWriter jsonWriter) {
// jsonWriter.addDocLink(Routes.Roles.DOC);
// jsonWriter.self(Routes.Roles.name(model.getName().toString()));
// jsonWriter.find(Routes.Roles.find());
// }
// public static Map toJSON(Role role, RequestContext requestContext) {
// if (role == null) return null;
//
// JsonWriter jsonWriter = new JsonWriter(requestContext);
//
// addLinks(role, jsonWriter);
//
// jsonWriter.add("name", role.getName().toString());
// jsonWriter.add("type", getRoleType(role));
// if (role.hasErrors()) {
// jsonWriter.add("errors", new ErrorGetter(Collections.singletonMap("authConfigId", "auth_config_id"))
// .apply(role, requestContext));
// }
// if (role instanceof RoleConfig) {
// jsonWriter.add("attributes", GoCDRoleConfigRepresenter.toJSON((RoleConfig) role, requestContext));
// } else if (role instanceof PluginRoleConfig) {
// jsonWriter.add("attributes", PluginRoleConfigRepresenter.toJSON((PluginRoleConfig) role, requestContext));
// }
// return jsonWriter.getAsMap();
// }
public static Role fromJSON(JsonReader jsonReader) {
Role model;
String type = jsonReader.optString("type").orElse("");
if ("gocd".equals(type)) {
model = GoCDRoleConfigRepresenter.fromJSON(jsonReader.readJsonObject("attributes"));
} else if ("plugin".equals(type)) {
model = PluginRoleConfigRepresenter.fromJSON(jsonReader.readJsonObject("attributes"));
} else {
throw new JsonParseException("Invalid role type '%s'. It has to be one of 'gocd' or 'plugin'");
}
model.setName(new CaseInsensitiveString(jsonReader.optString("name").orElse(null)));
return model;
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV3 method update.
public String update(Request req, Response res) {
Role roleFromServer = roleConfigService.findRole(req.params(":role_name"));
Role roleFromRequest = buildEntityFromRequestBody(req);
if (isRenameAttempt(roleFromServer, roleFromRequest)) {
throw haltBecauseRenameOfEntityIsNotSupported("roles");
}
if (isPutRequestStale(req, roleFromServer)) {
throw haltBecauseEtagDoesNotMatch("role", roleFromServer.getName());
}
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.update(SessionUtils.currentUsername(), etagFor(roleFromServer), roleFromRequest, result);
return handleCreateOrUpdateResponse(req, res, roleFromRequest, result);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RolesControllerV3 method destroy.
public String destroy(Request req, Response res) throws IOException {
Role role = fetchEntityFromConfig(req.params("role_name"));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.delete(SessionUtils.currentUsername(), role, result);
return renderHTTPOperationResult(result, req, res);
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class RoleConfigUpdateCommand method isRequestFresh.
private boolean isRequestFresh(CruiseConfig cruiseConfig) {
Role existingRole = findExistingRole(cruiseConfig);
if (existingRole == null) {
result.notFound(EntityType.Role.notFoundMessage(role.getName()), notFound());
return false;
}
boolean freshRequest = hashingService.hashForEntity(existingRole).equals(digest);
if (!freshRequest) {
result.stale(EntityType.Role.staleConfig(existingRole.getName()));
}
return freshRequest;
}
use of com.thoughtworks.go.config.Role in project gocd by gocd.
the class AbstractAuthenticationHelper method doesUserHasPermissions.
public boolean doesUserHasPermissions(Username username, SupportedAction action, SupportedEntity entity, String resource, String resourceToOperateWithin) {
// admin user has access to everything
if (securityService.isUserAdmin(username)) {
return true;
}
List<Role> roles = goConfigService.rolesForUser(username.getUsername());
boolean hasPermission = false;
for (Role role : roles) {
if (role.hasExplicitDenyPermissionsFor(action, entity.getEntityType(), resource, resourceToOperateWithin)) {
return false;
}
if (role.hasPermissionsFor(action, entity.getEntityType(), resource, resourceToOperateWithin)) {
hasPermission = true;
}
}
return hasPermission;
}
Aggregations