You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2015/12/05 20:56:31 UTC
ambari git commit: AMBARI-14228. Ambari Files View ignores alternate
HDFS authorization mechanisms (DIPAYAN BHOWMICK via srimanth)
Repository: ambari
Updated Branches:
refs/heads/branch-2.2 58412e0fb -> 6d82d24f7
AMBARI-14228. Ambari Files View ignores alternate HDFS authorization mechanisms (DIPAYAN BHOWMICK via srimanth)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6d82d24f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6d82d24f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6d82d24f
Branch: refs/heads/branch-2.2
Commit: 6d82d24f76739db371c13e742a3437e0a601ff64
Parents: 58412e0
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Sat Dec 5 11:55:57 2015 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Sat Dec 5 11:55:57 2015 -0800
----------------------------------------------------------------------
.../view/filebrowser/DownloadService.java | 21 ++++++++--
.../files/src/main/resources/ui/app/adapter.js | 7 ++--
.../ui/app/components/toggleContext.js | 6 +--
.../resources/ui/app/components/uploader.js | 9 +----
.../main/resources/ui/app/controllers/file.js | 42 ++++++++++----------
.../main/resources/ui/app/controllers/files.js | 10 ++---
.../ui/app/controllers/previewModal.js | 10 +++--
.../src/main/resources/ui/app/routes/file.js | 7 +++-
.../ui/app/templates/components/contextMenu.hbs | 8 ++--
.../main/resources/ui/app/templates/files.hbs | 8 ++--
.../resources/ui/app/templates/util/fileRow.hbs | 12 ++----
.../main/resources/ui/app/views/modalPreview.js | 2 +-
.../view/filebrowser/FilebrowserTest.java | 2 +-
13 files changed, 74 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
index 274d0d9..749174a 100644
--- a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
+++ b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
@@ -69,6 +69,8 @@ public class DownloadService extends HdfsService {
* Download entire file
* @param path path to file
* @param download download as octet strem or as file mime type
+ * @param checkperm used to check if the file can be downloaded. Takes precedence when both download and checkperm
+ * is set.
* @param headers http headers
* @param ui uri info
* @return response with file
@@ -77,20 +79,28 @@ public class DownloadService extends HdfsService {
@Path("/browse")
@Produces(MediaType.TEXT_PLAIN)
public Response browse(@QueryParam("path") String path, @QueryParam("download") boolean download,
+ @QueryParam("checkperm") boolean checkperm,
@Context HttpHeaders headers, @Context UriInfo ui) {
try {
HdfsApi api = getApi(context);
FileStatus status = api.getFileStatus(path);
FSDataInputStream fs = api.open(path);
+ if(checkperm) {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("allowed", true);
+ return Response.ok(jsonObject)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .build();
+ }
ResponseBuilder result = Response.ok(fs);
if (download) {
result.header("Content-Disposition",
- "inline; filename=\"" + status.getPath().getName() + "\"").type(MediaType.APPLICATION_OCTET_STREAM);
+ "inline; filename=\"" + status.getPath().getName() + "\"").type(MediaType.APPLICATION_OCTET_STREAM);
} else {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(status.getPath().getName());
result.header("Content-Disposition",
- "filename=\"" + status.getPath().getName() + "\"").type(mimeType);
+ "filename=\"" + status.getPath().getName() + "\"").type(mimeType);
}
return result.build();
} catch (WebApplicationException ex) {
@@ -228,7 +238,12 @@ public class DownloadService extends HdfsService {
FSDataInputStream in = null;
for (String path : request.entries) {
try {
- in = getApi(context).open(path);
+ try {
+ in = getApi(context).open(path);
+ } catch (AccessControlException ex) {
+ logger.error("Error in opening file {}. Ignoring concat of this files : {}", path.substring(1), ex.getMessage());
+ continue;
+ }
byte[] chunk = new byte[1024];
while (in.read(chunk) != -1) {
output.write(chunk);
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/adapter.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/adapter.js b/contrib/views/files/src/main/resources/ui/app/adapter.js
index 74cb988..d1d1d2c 100644
--- a/contrib/views/files/src/main/resources/ui/app/adapter.js
+++ b/contrib/views/files/src/main/resources/ui/app/adapter.js
@@ -289,14 +289,15 @@ App.ApplicationStore = DS.Store.extend({
* @param {Boolean} downloadArg
* @return {Promise}
*/
- linkFor:function (files, option, downloadArg) {
+ linkFor:function (files, option, downloadArg, checkperm) {
var resolver = Ember.RSVP.defer('promiseLabel');
var query, adapter = this.adapterFor(this.modelFor('file')),
- download = downloadArg || true;
+ download = downloadArg || true,
+ checkPermission = checkperm || false;
option = option || "browse";
if (option == 'browse') {
- query = { "path": (files.get('firstObject.path') || files.get('id')), "download": download };
+ query = { "path": (files.get('firstObject.path') || files.get('id')), "download": download, "checkperm": checkPermission };
resolver.resolve(adapter.downloadUrl('browse',query));
return resolver.promise;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/components/toggleContext.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/components/toggleContext.js b/contrib/views/files/src/main/resources/ui/app/components/toggleContext.js
index 74c62de..10f1b52 100644
--- a/contrib/views/files/src/main/resources/ui/app/components/toggleContext.js
+++ b/contrib/views/files/src/main/resources/ui/app/components/toggleContext.js
@@ -55,11 +55,7 @@ App.ToggleContextComponent = Em.Component.extend({
},
openOnClick:function (e) {
if($(e.target).is('td') || $(e.target).hasClass('allow-open')){
- if (this.get('targetObject.content.readAccess')) {
- this.get('targetObject').send('open');
- } else {
- _shake(this.$().parents('.file-row').find('.file-name span').first());
- }
+ this.get('targetObject').send('open');
}
},
willClearRender:function () {
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/components/uploader.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/components/uploader.js b/contrib/views/files/src/main/resources/ui/app/components/uploader.js
index 57a1a50..f6e61c4 100644
--- a/contrib/views/files/src/main/resources/ui/app/components/uploader.js
+++ b/contrib/views/files/src/main/resources/ui/app/components/uploader.js
@@ -48,14 +48,7 @@ App.FileUploaderComponent = Ember.Component.extend({
},
actions:{
upload:function () {
- if (this.get('dirStatus.writeAccess')) {
- this.uploadFile();
- } else {
- this.set('isError',true);
- Em.run.later(this,function () {
- this.set('isError',false);
- },500);
- }
+ this.uploadFile();
},
clear:function () {
this.set('fileInput.files',null);
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/controllers/file.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/controllers/file.js b/contrib/views/files/src/main/resources/ui/app/controllers/file.js
index b5054e4..88fa5fb 100644
--- a/contrib/views/files/src/main/resources/ui/app/controllers/file.js
+++ b/contrib/views/files/src/main/resources/ui/app/controllers/file.js
@@ -21,19 +21,11 @@ var App = require('app');
App.FileController = Ember.ObjectController.extend({
needs:['files'],
actions:{
- confirmPreview:function (option) {
- if (this.get('content.readAccess')) {
- this.store.linkFor([this.get('content')],option).then(function (link) {
- window.location.href = link;
- },Em.run.bind(this,this.sendAlert));
- }
+ confirmPreview:function (file) {
+ this.downloadFile(file, "browse");
},
download:function (option) {
- if (this.get('content.readAccess')) {
- this.store.linkFor([this.get('content')],option).then(function (link) {
- window.location.href = link;
- },Em.run.bind(this,this.sendAlert));
- }
+ this.downloadFile(this.get('content'), option);
},
preview:function (option) {
this.send('showPreviewModal',this.get('content'));
@@ -59,9 +51,6 @@ App.FileController = Ember.ObjectController.extend({
this.set('isRenaming',true);
},
open:function (file) {
- if (!this.get('content.readAccess')) {
- return false;
- }
if (this.get('content.isDirectory')) {
return this.transitionToRoute('files',{queryParams: {path: this.get('content.id')}});
} else{
@@ -70,13 +59,9 @@ App.FileController = Ember.ObjectController.extend({
}
},
deleteFile:function (deleteForever) {
- if (this.get('dirInfo.writeAccess')) {
- this.store
- .remove(this.get('content'),!deleteForever)
- .then(null,Em.run.bind(this,this.deleteErrorCallback,this.get('content')));
- } else {
- this.send('showAlert',{message:'Permission denied'});
- }
+ this.store
+ .remove(this.get('content'),!deleteForever)
+ .then(null,Em.run.bind(this,this.deleteErrorCallback,this.get('content')));
}
},
selected:false,
@@ -113,5 +98,20 @@ App.FileController = Ember.ObjectController.extend({
sendAlert:function (error) {
this.send('showAlert',error);
+ },
+ downloadFile: function(files, option) {
+ var _this = this;
+ this.store.linkFor([files], option, false, true).then(function(link) {
+ var that = _this;
+ Ember.$.get(link).done(function(data) {
+ if(data.allowed) {
+ that.store.linkFor([files],option).then(function (link) {
+ window.location.href = link;
+ },Em.run.bind(that,that.sendAlert));
+ }
+ }).fail(function(jqXHR, textStatus, errorThrown) {
+ that.send('showAlert', jqXHR);
+ });
+ }, Em.run.bind(this,this.sendAlert));
}
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/controllers/files.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/controllers/files.js b/contrib/views/files/src/main/resources/ui/app/controllers/files.js
index 7fb55bd..1315f31 100644
--- a/contrib/views/files/src/main/resources/ui/app/controllers/files.js
+++ b/contrib/views/files/src/main/resources/ui/app/controllers/files.js
@@ -77,13 +77,9 @@ App.FilesController = Ember.ArrayController.extend({
var self = this,
selected = this.get('selectedFiles'),
moveToTrash = !deleteForever;
- if (this.get('content.meta.writeAccess')) {
- selected.forEach(function (file) {
- self.store.remove(file,moveToTrash).then(null,bind(self,self.deleteErrorCallback,file));
- });
- } else {
- this.throwAlert({message:'Permission denied'});
- }
+ selected.forEach(function (file) {
+ self.store.remove(file,moveToTrash).then(null,bind(self,self.deleteErrorCallback,file));
+ });
},
download:function (option) {
var files = this.get('selectedFiles').filterBy('readAccess',true);
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/controllers/previewModal.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/controllers/previewModal.js b/contrib/views/files/src/main/resources/ui/app/controllers/previewModal.js
index a2d0c9e..35973b2 100644
--- a/contrib/views/files/src/main/resources/ui/app/controllers/previewModal.js
+++ b/contrib/views/files/src/main/resources/ui/app/controllers/previewModal.js
@@ -19,12 +19,13 @@
var App = require('app');
App.PreviewModalController = Em.ObjectController.extend({
- needs:['files'],
+ needs:['files', 'file'],
offset: 3000 ,
startIndex:0,
file:Em.computed.alias('content'),
filePageText:'',
- pagecontent: Ember.computed('file','startIndex', 'endIndex', function() {
+ reload: false,
+ pagecontent: Ember.computed('file', 'startIndex', 'endIndex', 'reload', function() {
var file = this.get('file');
var filepath = file.get('path');
var filePageText = this.get('filePageText');
@@ -54,6 +55,9 @@ App.PreviewModalController = Em.ObjectController.extend({
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( "Preview Fail pagecontent : " + errorThrown );
+ self.send('removePreviewModal');
+ self.send('showAlert', jqXhr);
+ self.set('reload', !self.get('reload'));
}
});
@@ -77,7 +81,7 @@ App.PreviewModalController = Em.ObjectController.extend({
next: function(){
console.log('Next');
this.set('startIndex', this.get('startIndex') + this.get('offset'));
- return self.get('filePageText');
+ return this.get('filePageText');
},
prev: function(){
console.log('Prev');
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/routes/file.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/routes/file.js b/contrib/views/files/src/main/resources/ui/app/routes/file.js
index 207b57a..b64a7b1 100644
--- a/contrib/views/files/src/main/resources/ui/app/routes/file.js
+++ b/contrib/views/files/src/main/resources/ui/app/routes/file.js
@@ -34,6 +34,7 @@ App.FilesRoute = Em.Route.extend({
this.router.one('didTransition', target, 'hideSpinner');
},
error:function (error,transition,e) {
+ this.controllerFor('files').set('isLoadingFiles', false);
if (this.router._lookupActiveView('files')) {
this.send('showAlert',error);
} else {
@@ -68,8 +69,10 @@ App.FilesRoute = Em.Route.extend({
},
showPreviewModal :function (content) {
- this.controllerFor('previewModal').set('content',content);
- this.controllerFor('previewModal').set('startIndex',0);
+ var controller = this.controllerFor('previewModal');
+ controller.set('reload', true);
+ controller.set('content',content);
+ controller.set('startIndex',0);
this.render('modal.preview',{
into:'files',
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/templates/components/contextMenu.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/templates/components/contextMenu.hbs b/contrib/views/files/src/main/resources/ui/app/templates/components/contextMenu.hbs
index 83e8869..2cd6303 100644
--- a/contrib/views/files/src/main/resources/ui/app/templates/components/contextMenu.hbs
+++ b/contrib/views/files/src/main/resources/ui/app/templates/components/contextMenu.hbs
@@ -20,9 +20,9 @@
<div id="context-menu">
<ul class="dropdown-menu dropdown-context compressed-context" role="menu">
{{#if view.target.content.isDirectory}}
- <li {{bind-attr class="view.target.content.readAccess::disabled"}}><a tabindex="-1" href="#" {{action 'open'}}>Open folder</a></li>
+ <li><a tabindex="-1" href="#" {{action 'open'}}>Open folder</a></li>
{{else}}
- <li {{bind-attr class="view.target.content.readAccess::disabled"}}><a tabindex="-1" href="#" {{action 'download'}}>Download</a></li>
+ <li><a tabindex="-1" href="#" {{action 'download'}}>Download</a></li>
{{/if}}
<li><a tabindex="-1" href="#" {{action 'moveFile' 'cut' view.target.content}}>Move</a></li>
<li><a tabindex="-1" href="#" {{action 'showChmod'}} >Permissions</a></li>
@@ -34,8 +34,8 @@
<i class="fa fa-chevron-right pull-right fa-right"></i>
</a>
<ul class="dropdown-menu">
- {{confirm-delete confirm="removeFile" deleteForever=true access=target.dirInfo.writeAccess}}
- {{confirm-delete confirm="moveToTrash" deleteForever=false access=target.dirInfo.writeAccess}}
+ {{confirm-delete confirm="removeFile" deleteForever=true access=true}}
+ {{confirm-delete confirm="moveToTrash" deleteForever=false access=true}}
</ul>
</li>
</ul>
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/templates/files.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/templates/files.hbs b/contrib/views/files/src/main/resources/ui/app/templates/files.hbs
index 3d4af71..6d0f25b 100644
--- a/contrib/views/files/src/main/resources/ui/app/templates/files.hbs
+++ b/contrib/views/files/src/main/resources/ui/app/templates/files.hbs
@@ -29,13 +29,13 @@
</div>
<div {{bind-attr class="isUploading:hide: :pull-right :uploadwrap" }}>
- <button type="button" {{action 'upload' 'open'}} {{bind-attr class=":btn :btn-default :btn-sm :pull-right content.meta.writeAccess::disabled"}}>
+ <button type="button" {{action 'upload' 'open'}} {{bind-attr class=":btn :btn-default :btn-sm :pull-right"}}>
<i class="fa fa-upload"></i> Upload
</button>
</div>
{{!-- MKDIR --}}
- {{mkdir-input create="mkdir" path=path canCreate=content.meta.writeAccess}}
+ {{mkdir-input create="mkdir" path=path canCreate=true}}
</div>
</div>
@@ -115,8 +115,8 @@
<i class="fa fa-chevron-left fa-gr fa-fw"></i> Delete
</a>
<ul class="dropdown-menu left-submenu">
- {{confirm-delete confirm="deleteFile" deleteForever=true selector='bulkDropdown' access=content.meta.writeAccess}}
- {{confirm-delete confirm="deleteFile" deleteForever=false selector='bulkDropdown' access=content.meta.writeAccess}}
+ {{confirm-delete confirm="deleteFile" deleteForever=true selector='bulkDropdown' access=true}}
+ {{confirm-delete confirm="deleteFile" deleteForever=false selector='bulkDropdown' access=true}}
</ul>
</li>
</ul>
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs b/contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs
index 1dc9ff4..8cd0cbb 100644
--- a/contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs
+++ b/contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs
@@ -26,7 +26,7 @@
<td>
{{#rename-input fileBinding='content' confirm='rename' isRenaming=isRenaming}}
<div class="file-name allow-open">
- {{#file-shaker action="open" isValid=content.readAccess}}
+ {{#file-shaker action="open" isValid=true}}
<span>
<a>
<strong>
@@ -56,20 +56,16 @@
{{#unless isMoving}}
<ul class="list-inline file-actions text-right">
<li>
- {{#if content.readAccess}}
{{#if content.isDirectory}}
- <a href="#" {{action 'download' 'zip'}} data-toggle="tooltip" data-placement="bottom" title="Download zip"><i class="fa fa-archive fa-fw fa-lg"></i></a>
+ <a href="#" {{action 'download' 'zip'}} target="_blank" data-toggle="tooltip" data-placement="bottom" title="Download zip"><i class="fa fa-archive fa-fw fa-lg"></i></a>
{{else}}
- <a href="#" {{action 'download' 'browse'}} data-toggle="tooltip" data-placement="bottom" title="Download"><i class="fa fa-download fa-fw fa-lg"></i></a>
+ <a href="#" {{action 'download' 'browse'}} target="_blank" data-toggle="tooltip" data-placement="bottom" title="Download"><i class="fa fa-download fa-fw fa-lg"></i></a>
{{/if}}
- {{/if}}
</li>
<li>
<a href="#" {{action 'moveFile' 'cut' this.content}} data-toggle="tooltip" data-placement="bottom" title="Move"><i class="fa fa-level-down fa-rotate-270 fa-fw fa-lg"></i></a>
</li>
- {{#if dirInfo.writeAccess}}
- <li>{{popover-delete confirm="deleteFile"}}</li>
- {{/if}}
+ <li>{{popover-delete confirm="deleteFile"}}</li>
</ul>
{{/unless}}
</td>
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/main/resources/ui/app/views/modalPreview.js
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/ui/app/views/modalPreview.js b/contrib/views/files/src/main/resources/ui/app/views/modalPreview.js
index 927e267..49d7fce 100644
--- a/contrib/views/files/src/main/resources/ui/app/views/modalPreview.js
+++ b/contrib/views/files/src/main/resources/ui/app/views/modalPreview.js
@@ -21,7 +21,7 @@ var App = require('app');
App.ModalPreviewView = Em.View.extend({
actions:{
confirm:function (file) {
- this.get('controller.controllers.files').send('confirmPreview', this.get('controller.file'));
+ this.get('controller.controllers.file').send('confirmPreview', this.get('controller.file'));
this.$('.preview').modal('hide');
},
close:function () {
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d82d24f/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
index 00cd368..da804d1 100644
--- a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
+++ b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
@@ -143,7 +143,7 @@ public class FilebrowserTest{
JSONObject responseObject = (JSONObject) listdir.getEntity();
JSONArray statuses = (JSONArray) responseObject.get("files");
System.out.println(statuses.size());
- Response response2 = fileBrowserService.download().browse("/tmp/testUpload.tmp", false, httpHeaders, uriInfo);
+ Response response2 = fileBrowserService.download().browse("/tmp/testUpload.tmp", false, false, httpHeaders, uriInfo);
Assert.assertEquals(200, response2.getStatus());
}