Search in sources :

Example 41 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookTest method testGetAllNotesWithDifferentPermissions.

@Test
public void testGetAllNotesWithDifferentPermissions() throws IOException {
    HashSet<String> user1 = Sets.newHashSet("user1");
    HashSet<String> user2 = Sets.newHashSet("user1");
    List<Note> notes1 = notebook.getAllNotes(user1);
    List<Note> notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 0);
    assertEquals(notes2.size(), 0);
    //creates note and sets user1 owner
    Note note = notebook.createNote(new AuthenticationInfo("user1"));
    // note is public since readers and writers empty
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 1);
    assertEquals(notes2.size(), 1);
    notebook.getNotebookAuthorization().setReaders(note.getId(), Sets.newHashSet("user1"));
    //note is public since writers empty
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 1);
    assertEquals(notes2.size(), 1);
    notebook.getNotebookAuthorization().setWriters(note.getId(), Sets.newHashSet("user1"));
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 1);
    assertEquals(notes2.size(), 1);
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 42 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookTest method testCloneNote.

@Test
public void testCloneNote() throws IOException, CloneNotSupportedException, InterruptedException, InterpreterException, SchedulerException, RepositoryException {
    Note note = notebook.createNote(anonymous);
    interpreterSettingManager.setInterpreters("user", note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
    final Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p.setText("hello world");
    note.runAll();
    while (p.isTerminated() == false || p.getResult() == null) Thread.yield();
    p.setStatus(Status.RUNNING);
    Note cloneNote = notebook.cloneNote(note.getId(), "clone note", anonymous);
    Paragraph cp = cloneNote.paragraphs.get(0);
    assertEquals(cp.getStatus(), Status.READY);
    // Keep same ParagraphId
    assertEquals(cp.getId(), p.getId());
    assertEquals(cp.text, p.text);
    assertEquals(cp.getResult().message().get(0).getData(), p.getResult().message().get(0).getData());
    // Verify clone note with subject
    AuthenticationInfo subject = new AuthenticationInfo("user1");
    Note cloneNote2 = notebook.cloneNote(note.getId(), "clone note2", subject);
    assertNotNull(notebook.getNotebookAuthorization().getOwners(cloneNote2.getId()));
    assertEquals(1, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId()).size());
    Set<String> owners = new HashSet<>();
    owners.add("user1");
    assertEquals(owners, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId()));
    notebook.removeNote(note.getId(), anonymous);
    notebook.removeNote(cloneNote.getId(), anonymous);
    notebook.removeNote(cloneNote2.getId(), anonymous);
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 43 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookTest method testAuthorizationRoles.

@Test
public void testAuthorizationRoles() throws IOException {
    String user1 = "user1";
    String user2 = "user2";
    Set<String> roles = Sets.newHashSet("admin");
    // set admin roles for both user1 and user2
    notebookAuthorization.setRoles(user1, roles);
    notebookAuthorization.setRoles(user2, roles);
    Note note = notebook.createNote(new AuthenticationInfo(user1));
    // check that user1 is owner, reader and writer
    assertEquals(notebookAuthorization.isOwner(note.getId(), Sets.newHashSet(user1)), true);
    assertEquals(notebookAuthorization.isReader(note.getId(), Sets.newHashSet(user1)), true);
    assertEquals(notebookAuthorization.isWriter(note.getId(), Sets.newHashSet(user1)), true);
    // since user1 and user2 both have admin role, user2 will be reader and writer as well
    assertEquals(notebookAuthorization.isOwner(note.getId(), Sets.newHashSet(user2)), false);
    assertEquals(notebookAuthorization.isReader(note.getId(), Sets.newHashSet(user2)), true);
    assertEquals(notebookAuthorization.isWriter(note.getId(), Sets.newHashSet(user2)), true);
    // check that user1 has note listed in his workbench
    Set<String> user1AndRoles = notebookAuthorization.getRoles(user1);
    user1AndRoles.add(user1);
    List<Note> user1Notes = notebook.getAllNotes(user1AndRoles);
    assertEquals(user1Notes.size(), 1);
    assertEquals(user1Notes.get(0).getId(), note.getId());
    // check that user2 has note listed in his workbech because of admin role
    Set<String> user2AndRoles = notebookAuthorization.getRoles(user2);
    user2AndRoles.add(user2);
    List<Note> user2Notes = notebook.getAllNotes(user2AndRoles);
    assertEquals(user2Notes.size(), 1);
    assertEquals(user2Notes.get(0).getId(), note.getId());
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 44 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class LuceneSearchTest method startUp.

@Before
public void startUp() {
    noteSearchService = new LuceneSearch();
    anonymous = new AuthenticationInfo("anonymous");
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Before(org.junit.Before)

Example 45 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class SparkInterpreterTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    intpGroup = new InterpreterGroup();
    intpGroup.put("note", new LinkedList<Interpreter>());
    repl = new SparkInterpreter(getSparkTestProperties(tmpDir));
    repl.setInterpreterGroup(intpGroup);
    intpGroup.get("note").add(repl);
    repl.open();
    final RemoteEventClientWrapper remoteEventClientWrapper = new RemoteEventClientWrapper() {

        @Override
        public void onParaInfosReceived(String noteId, String paragraphId, Map<String, String> infos) {
            if (infos != null) {
                paraIdToInfosMap.put(paragraphId, infos);
            }
        }

        @Override
        public void onMetaInfosReceived(Map<String, String> infos) {
        }
    };
    context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), new InterpreterOutput(null)) {

        @Override
        public RemoteEventClientWrapper getClient() {
            return remoteEventClientWrapper;
        }
    };
    // The first para interpretdr will set the Eventclient wrapper
    //SparkInterpreter.interpret(String, InterpreterContext) ->
    //SparkInterpreter.populateSparkWebUrl(InterpreterContext) ->
    //ZeppelinContext.setEventClient(RemoteEventClientWrapper)
    //running a dummy to ensure that we dont have any race conditions among tests
    repl.interpret("sc", context);
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) RemoteEventClientWrapper(org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) GUI(org.apache.zeppelin.display.GUI) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)88 HashMap (java.util.HashMap)27 Note (org.apache.zeppelin.notebook.Note)27 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)19 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)19 GUI (org.apache.zeppelin.display.GUI)19 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)17 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)16 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 Path (javax.ws.rs.Path)14 Message (org.apache.zeppelin.notebook.socket.Message)14 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)14 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 Before (org.junit.Before)12 Map (java.util.Map)11 File (java.io.File)10 AngularObject (org.apache.zeppelin.display.AngularObject)9 POST (javax.ws.rs.POST)6