use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class StreamCatalogService method handleCustomProcessorJar.
private void handleCustomProcessorJar(InputStream jarFile, CustomProcessorInfo customProcessorInfo, boolean verify) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
java.io.File tmpFile;
try (DigestInputStream dis = new DigestInputStream(jarFile, md)) {
tmpFile = FileUtil.writeInputStreamToTempFile(dis, ".jar");
}
customProcessorInfo.setDigest(Hex.encodeHexString(md.digest()));
LOG.debug("Digest: {}", customProcessorInfo.getDigest());
if (verify && !verifyCustomProcessorImplFromJar(tmpFile, customProcessorInfo)) {
String message = "Custom Processor jar file is missing customProcessorImpl class " + customProcessorInfo.getCustomProcessorImpl();
LOG.debug(message);
throw new RuntimeException(message);
}
Collection<CustomProcessorInfo> customProcessorInfos = this.listCustomProcessorsFromBundleWithFilter(Collections.singletonList(new QueryParam(CustomProcessorInfo.DIGEST, customProcessorInfo.getDigest())));
if (!customProcessorInfos.isEmpty()) {
customProcessorInfo.setJarFileName(customProcessorInfos.iterator().next().getJarFileName());
} else {
customProcessorInfo.setJarFileName(String.format("custom-processor-%s.jar", UUID.randomUUID().toString()));
try (InputStream inputStream = new FileInputStream(tmpFile)) {
uploadFileToStorage(inputStream, customProcessorInfo.getJarFileName());
}
}
}
use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class StreamCatalogService method removeTopologyDependencies.
private void removeTopologyDependencies(Long topologyId, Long versionId) throws Exception {
List<QueryParam> topologyIdVersionIdQueryParams = WSUtils.buildTopologyIdAndVersionIdAwareQueryParams(topologyId, versionId, null);
// remove topology test histories
Collection<TopologyTestRunHistory> runHistories = listTopologyTestRunHistory(topologyId, versionId);
runHistories.forEach(history -> removeTopologyTestRunHistory(history.getId()));
// remove topology test run case
Collection<TopologyTestRunCase> runCases = listTopologyTestRunCase(topologyIdVersionIdQueryParams);
for (TopologyTestRunCase runCase : runCases) {
Collection<TopologyTestRunCaseSource> runCaseSources = listTopologyTestRunCaseSource(runCase.getId());
Collection<TopologyTestRunCaseSink> runCaseSinks = listTopologyTestRunCaseSink(runCase.getId());
// remove topology test run case source
for (TopologyTestRunCaseSource runCaseSource : runCaseSources) {
removeTopologyTestRunCaseSource(runCaseSource.getId());
}
// remove topology test run case sink
for (TopologyTestRunCaseSink runCaseSink : runCaseSinks) {
removeTopologyTestRunCaseSink(runCaseSink.getId());
}
removeTestRunCase(topologyId, runCase.getId());
}
// remove edges
Collection<TopologyEdge> edges = listTopologyEdges(topologyIdVersionIdQueryParams);
for (TopologyEdge edge : edges) {
removeTopologyEdge(topologyId, edge.getId(), versionId);
}
// remove rules
Collection<TopologyRule> topologyRules = listRules(topologyIdVersionIdQueryParams);
for (TopologyRule topologyRule : topologyRules) {
removeRule(topologyId, topologyRule.getId(), versionId);
}
// remove windowed rules
Collection<TopologyWindow> topologyWindows = listWindows(topologyIdVersionIdQueryParams);
for (TopologyWindow topologyWindow : topologyWindows) {
removeWindow(topologyId, topologyWindow.getId(), versionId);
}
// remove branch rules
Collection<TopologyBranchRule> topologyBranchRules = listBranchRules(topologyIdVersionIdQueryParams);
for (TopologyBranchRule topologyBranchRule : topologyBranchRules) {
removeBranchRule(topologyId, topologyBranchRule.getId(), versionId);
}
// remove sinks
Collection<TopologySink> sinks = listTopologySinks(topologyIdVersionIdQueryParams);
for (TopologySink sink : sinks) {
removeTopologySink(topologyId, sink.getId(), versionId, false);
}
// remove processors
Collection<TopologyProcessor> processors = listTopologyProcessors(topologyIdVersionIdQueryParams);
for (TopologyProcessor processor : processors) {
removeTopologyProcessor(topologyId, processor.getId(), versionId, false);
}
// remove sources
Collection<TopologySource> sources = listTopologySources(topologyIdVersionIdQueryParams);
for (TopologySource source : sources) {
removeTopologySource(topologyId, source.getId(), versionId, false);
}
// remove output streams
Collection<TopologyStream> topologyStreams = listStreamInfos(topologyIdVersionIdQueryParams);
for (TopologyStream topologyStream : topologyStreams) {
removeStreamInfo(topologyId, topologyStream.getId(), versionId);
}
// remove topology editor metadata
removeTopologyEditorMetadata(topologyId, versionId);
}
use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class SecurityCatalogService method checkUserPermissions.
public boolean checkUserPermissions(String objectNamespace, Long objectId, Long userId, EnumSet<Permission> required) {
User user = getUser(userId);
if (user == null) {
return false;
}
EnumSet<Permission> remaining = EnumSet.copyOf(required);
// try direct user acl entry first
List<QueryParam> qps = QueryParam.params(AclEntry.OBJECT_NAMESPACE, objectNamespace, AclEntry.OBJECT_ID, String.valueOf(objectId), AclEntry.SID_TYPE, USER.toString(), AclEntry.SID_ID, String.valueOf(userId));
Collection<AclEntry> acls = listAcls(qps);
if (acls.size() > 1) {
throw new IllegalStateException("More than one ACL entry for " + qps);
} else if (acls.size() == 1) {
AclEntry aclEntry = acls.iterator().next();
remaining.removeAll(aclEntry.getPermissions());
}
// try role based permissions next
if (!remaining.isEmpty() && user.getRoles() != null) {
qps = QueryParam.params(AclEntry.OBJECT_NAMESPACE, objectNamespace, AclEntry.OBJECT_ID, String.valueOf(objectId), AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
acls = listAcls(qps);
Set<Role> userRoles = getAllUserRoles(user);
Iterator<AclEntry> it = acls.iterator();
while (!remaining.isEmpty() && it.hasNext()) {
AclEntry roleEntry = it.next();
if (userRoles.contains(getRole(roleEntry.getSidId()))) {
remaining.removeAll(roleEntry.getPermissions());
}
}
}
return remaining.isEmpty();
}
use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class SecurityCatalogServiceTest method checkUserPermissions.
@Test
public void checkUserPermissions() throws Exception {
SecurityCatalogService catalogService = new SecurityCatalogService(null);
AclEntry userAclEntry = new AclEntry();
userAclEntry.setSidType(AclEntry.SidType.USER);
userAclEntry.setSidId(1L);
userAclEntry.setObjectId(1L);
userAclEntry.setObjectNamespace("topology");
userAclEntry.setPermissions(EnumSet.of(Permission.WRITE));
AclEntry roleAclEntry = new AclEntry();
roleAclEntry.setSidType(AclEntry.SidType.ROLE);
roleAclEntry.setSidId(1L);
roleAclEntry.setObjectId(1L);
roleAclEntry.setObjectNamespace("topology");
roleAclEntry.setPermissions(EnumSet.of(Permission.READ));
Role role = new Role();
role.setId(1L);
role.setName("ROLE_FOO");
List<QueryParam> qps1 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, USER.toString(), AclEntry.SID_ID, "1");
List<QueryParam> qps2 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
User user = new User();
user.setRoles(Sets.newHashSet("ROLE_FOO"));
new Expectations(catalogService) {
{
catalogService.getUser(anyLong);
result = user;
catalogService.listAcls(qps1);
result = Arrays.asList(userAclEntry);
catalogService.getAllUserRoles(user);
result = Sets.newHashSet(role);
catalogService.listAcls(qps2);
result = Arrays.asList(roleAclEntry);
catalogService.getRole(1L);
result = role;
}
};
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.READ)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.READ)));
assertFalse(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.DELETE)));
}
use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class NotifierInfoCatalogResourceTest method testListNotifiers.
@Test
public void testListNotifiers() {
final Notifier notifier = new Notifier();
final QueryParam expectedQp = new QueryParam("notifierName", "email_notifier_1");
multiValuedMap.putSingle("notifierName", "email_notifier_1");
new Expectations() {
{
mockUriInfo.getQueryParameters();
times = 1;
result = multiValuedMap;
mockCatalogService.listNotifierInfos(Arrays.asList(expectedQp));
times = 1;
result = Arrays.asList(notifier);
}
};
CollectionResponse collectionResponse = (CollectionResponse) resource.listNotifiers(mockUriInfo, securityContext).getEntity();
assertEquals(1, collectionResponse.getEntities().size());
assertEquals(notifier, collectionResponse.getEntities().iterator().next());
}
Aggregations