Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void setGroupRolesMap(Map<String, String> groupRolesMap) {

LdapContextFactory ldapContextFactory;

@Override
protected void onInit() {
super.onInit();
this.getLdapContextFactory();
Expand All @@ -120,6 +121,7 @@ public LdapContextFactory getLdapContextFactory() {
return this.ldapContextFactory;
}

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException {
try {
Expand All @@ -134,6 +136,8 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
}
}


@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
try {
AuthorizationInfo info = this.queryForAuthorizationInfo(principals,
Expand Down Expand Up @@ -168,6 +172,7 @@ private String getSystemPassword() {
* @return an {@link AuthenticationInfo} instance containing information retrieved from LDAP.
* @throws NamingException if any LDAP errors occur during the search.
*/
@Override
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token,
LdapContextFactory ldapContextFactory) throws NamingException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
Expand Down Expand Up @@ -228,6 +233,8 @@ protected AuthenticationInfo buildAuthenticationInfo(String username, char[] pas
* @return the AuthorizationInfo for the given Subject principal.
* @throws NamingException if an error occurs when searching the LDAP server.
*/

@Override
protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals,
LdapContextFactory ldapContextFactory) throws NamingException {
String username = (String) getAvailablePrincipal(principals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected User authenticateUser(String requestBody) {
* @param pwd
* @return
*/
protected String createLoginPayload(String login, char[] pwd) {
protected String createLoginPayload(String login, char ... pwd) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?

StringBuilder sb = new StringBuilder("{\"login\":\"");
return sb.append(login).append("\", \"password\":\"").append(pwd).append("\"}").toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private HashMap<String, String[]> parseMapping(String mappings)
String value = mapping.substring(mapping.indexOf('=') + 1);
String[] v = value.split(",");
String[] p = principals.split(",");
for (int i = 0; i < p.length; i++) {
table.put(p[i], v);
for (String s : p) {
table.put(s, v);
}
} while (t.hasMoreTokens());
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public String mapUserPrincipal(String principalName) {
@Override
public String[] mapGroupPrincipal(String principalName) {
String[] groups = null;
String[] wildCardGroups = null;
String[] wildCardGroups;

if (groupMappings != null) {
groups = groupMappings.get(principalName);
Expand All @@ -112,13 +112,15 @@ public String[] mapGroupPrincipal(String principalName) {

return groups;
}

/**
*
* @param groups
* @param wildCardGroups
* @param <T>
* @return
*/
public static <T> T[] concat(T[] groups, T[] wildCardGroups) {
public static <T> T[] concat(T[] groups, T ... wildCardGroups) {
T[] result = Arrays.copyOf(groups, groups.length + wildCardGroups.length);
System.arraycopy(wildCardGroups, 0, result, groups.length, wildCardGroups.length);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ private AuthenticationToken getToken(HttpServletRequest request)
return token;
}

private static AuthenticationToken getTokenFromCookies(Cookie[] cookies)
private static AuthenticationToken getTokenFromCookies(Cookie ... cookies)
throws AuthenticationException {
AuthenticationToken token = null;
String tokenStr = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2111,8 +2111,7 @@ public List<ParagraphInfo> getParagraphList(String user, String noteId)
// Convert Paragraph to ParagraphInfo
List<ParagraphInfo> paragraphInfos = new ArrayList();
List<Paragraph> paragraphs = note.getParagraphs();
for (Iterator<Paragraph> iter = paragraphs.iterator(); iter.hasNext();) {
Paragraph paragraph = iter.next();
for (Paragraph paragraph : paragraphs) {
ParagraphInfo paraInfo = new ParagraphInfo();
paraInfo.setNoteId(noteId);
paraInfo.setParagraphId(paragraph.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a list of imports and no wildcard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkstyle plugin should catchup this, at least in main code....

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -134,7 +132,7 @@ public static void init() throws Exception {
}

Thread.sleep(3000);
assertEquals(true, clusterIsStartup());
assertTrue(clusterIsStartup());

getClusterServerMeta();
}
Expand Down Expand Up @@ -282,7 +280,7 @@ public static void getClusterServerMeta() {
LOGGER.info(intpMeta.toString());

assertNotNull(srvMeta);
assertEquals(true, (srvMeta instanceof HashMap));
assertTrue((srvMeta instanceof HashMap));
HashMap hashMap = (HashMap) srvMeta;

assertEquals(hashMap.size(), 3);
Expand Down Expand Up @@ -406,8 +404,9 @@ public void testClusterAuthEvent() throws IOException {
notebookServer.getNotebook().saveNote(note, anonymous);

String noteId = note.getId();
String user1Id = "user1", user2Id = "user2";

String user1Id = "user1";
String user2Id = "user2";

// test user1 can get anonymous's note
List<ParagraphInfo> paragraphList0 = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.zeppelin.realm;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -55,8 +56,8 @@ public void testDoGetAuthenticationInfo() {
when(authToken.getCredentials()).thenReturn(pamPass);

AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken);

assertTrue(authInfo.getCredentials() != null);
assertNotNull(authInfo.getCredentials());
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public class CredentialsRestApiTest {
private AuthenticationService authenticationService;

@Before
public void setUp() throws IOException {
public void setUp() {
credentials = new Credentials();
authenticationService = new NoAuthenticationService();
credentialRestApi = new CredentialRestApi(credentials, authenticationService);
}

@Test
public void testInvalidRequest() throws IOException {
public void testInvalidRequest() {
String jsonInvalidRequestEntityNull =
"{\"entity\" : null, \"username\" : \"test\", " + "\"password\" : \"testpass\"}";
String jsonInvalidRequestNameNull =
Expand All @@ -73,19 +73,18 @@ public void testInvalidRequest() throws IOException {
assertEquals(Status.BAD_REQUEST, response.getStatusInfo().toEnum());
}

public Map<String, UserCredentials> testGetUserCredentials() throws IOException {
@Test
public Map<String, UserCredentials> testGetUserCredentials() {
Response response = credentialRestApi.getCredentials();
Map<String, Object> resp =
gson.fromJson(
response.getEntity().toString(), new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Object> body = (Map<String, Object>) resp.get("body");
Map<String, UserCredentials> credentialMap =
(Map<String, UserCredentials>) body.get("userCredentials");
return credentialMap;
return (Map<String, UserCredentials>) body.get("userCredentials");
}

@Test
public void testCredentialsAPIs() throws IOException {
public void testCredentialsAPIs() {
String requestData1 =
"{\"entity\" : \"entityname\", \"username\" : \"myuser\", \"password\" " + ": \"mypass\"}";
String entity = "entityname";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public void testSettingsCreateWithInvalidName() throws IOException {

}

@Test
public void testInterpreterRestart() throws IOException, InterruptedException {
Note note = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public void setNewDirectoryForLocalDirectory() throws IOException {
List<Map<String, Object>> listOfRepositories = getListOfReposotiry();
String localVfs = StringUtils.EMPTY;
String className = StringUtils.EMPTY;

for (int i = 0; i < listOfRepositories.size(); i++) {
if (listOfRepositories.get(i).get("name").equals("VFSNotebookRepo")) {
for (Map<String, Object> listOfRepository : listOfRepositories) {
if (listOfRepository.get("name").equals("VFSNotebookRepo")) {
localVfs =
(String) ((List<Map<String, Object>>) listOfRepositories.get(i).get("settings"))
.get(0).get("selected");
className = (String) listOfRepositories.get(i).get("className");
(String) ((List<Map<String, Object>>) listOfRepository.get("settings"))
.get(0).get("selected");
className = (String) listOfRepository.get("className");
break;
}
}
Expand All @@ -120,11 +120,11 @@ public void setNewDirectoryForLocalDirectory() throws IOException {
// Verify
listOfRepositories = getListOfReposotiry();
String updatedPath = StringUtils.EMPTY;
for (int i = 0; i < listOfRepositories.size(); i++) {
if (listOfRepositories.get(i).get("name").equals("VFSNotebookRepo")) {
for (Map<String, Object> listOfRepository : listOfRepositories) {
if (listOfRepository.get("name").equals("VFSNotebookRepo")) {
updatedPath =
(String) ((List<Map<String, Object>>) listOfRepositories.get(i).get("settings"))
.get(0).get("selected");
(String) ((List<Map<String, Object>>) listOfRepository.get("settings"))
.get(0).get("selected");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ private void testDeleteNotExistNote(String noteId) throws IOException {
@Test
public void testCloneNote() throws IOException, IllegalArgumentException {
LOG.info("testCloneNote");
Note note = null, newNote = null;
Note note = null;
Note newNote = null;
try {
// Create note to clone
note = TestUtils.getInstance(Notebook.class).createNote("note1_testCloneNote", anonymous);
Expand Down Expand Up @@ -948,13 +949,13 @@ public void testTitleSearch() throws IOException, InterruptedException {
ArrayList searchBody = (ArrayList) respSearchResult.get("body");

int numberOfTitleHits = 0;
for (int i = 0; i < searchBody.size(); i++) {
Map<String, String> searchResult = (Map<String, String>) searchBody.get(i);
for (Object o : searchBody) {
Map<String, String> searchResult = (Map<String, String>) o;
if (searchResult.get("header").contains("testTitleSearchOfParagraph")) {
numberOfTitleHits++;
}
}
assertEquals("Paragraph title hits must be at-least one", true, numberOfTitleHits >= 1);
assertTrue("Paragraph title hits must be at-least one", numberOfTitleHits >= 1);
searchNote.releaseConnection();
} finally {
//cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,13 @@ public void testGetParagraphList() throws IOException {
notebook.saveNote(note, anonymous);

String noteId = note.getId();
String user1Id = "user1", user2Id = "user2";

String user1Id = "user1";
String user2Id = "user2";

// test user1 can get anonymous's note
List<ParagraphInfo> paragraphList0 = null;
try {
paragraphList0 = notebookServer.getParagraphList(user1Id, noteId);
} catch (ServiceException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
Expand Down