Repository: falcon Updated Branches: refs/heads/master 9a43bb643 -> e3893a859
FALCON-1316 Add supporting REST API calls for new UI. Contributed by Balu Vellanki. Project: http://git-wip-us.apache.org/repos/asf/falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/falcon/commit/e3893a85 Tree: http://git-wip-us.apache.org/repos/asf/falcon/tree/e3893a85 Diff: http://git-wip-us.apache.org/repos/asf/falcon/diff/e3893a85 Branch: refs/heads/master Commit: e3893a859b9edfcc7ad3f156d77ad70bbe0a359d Parents: 9a43bb6 Author: Sowmya Ramesh <[email protected]> Authored: Thu Oct 8 15:25:15 2015 -0700 Committer: Sowmya Ramesh <[email protected]> Committed: Thu Oct 8 15:25:15 2015 -0700 ---------------------------------------------------------------------- CHANGES.txt | 2 + .../security/DefaultAuthorizationProvider.java | 2 +- .../falcon/resource/admin/AdminResource.java | 45 ++++- .../resource/admin/AdminResourceTest.java | 67 +++++++ .../resource/admin/MockHttpServletResponse.java | 190 +++++++++++++++++++ 5 files changed, 303 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/falcon/blob/e3893a85/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 0d03d8a..8ac9fb8 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,8 @@ Trunk (Unreleased) FALCON-1401 MetadataMappingService fails to add an edge for a process instance(Pallavi Rao) NEW FEATURES + FALCON-1316 Add supporting REST API calls for new UI(Balu Vellanki via Sowmya Ramesh) + FALCON-1473 Feed SLA Miss Alerts through REST API(Ajay Yadava) FALCON-965 Open up life cycle stage implementation within Falcon for extension(Ajay Yadava) http://git-wip-us.apache.org/repos/asf/falcon/blob/e3893a85/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java b/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java index 449be80..887164e 100644 --- a/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java +++ b/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java @@ -166,7 +166,7 @@ public class DefaultAuthorizationProvider implements AuthorizationProvider { } if ("admin".equals(resource)) { - if (!"version".equals(action)) { + if (!("version".equals(action) || "clearuser".equals(action) || "getuser".equals(action))) { authorizeAdminResource(authenticatedUGI, action); } } else if ("entities".equals(resource) || "instance".equals(resource)) { http://git-wip-us.apache.org/repos/asf/falcon/blob/e3893a85/prism/src/main/java/org/apache/falcon/resource/admin/AdminResource.java ---------------------------------------------------------------------- diff --git a/prism/src/main/java/org/apache/falcon/resource/admin/AdminResource.java b/prism/src/main/java/org/apache/falcon/resource/admin/AdminResource.java index c83886f..ace21cb 100644 --- a/prism/src/main/java/org/apache/falcon/resource/admin/AdminResource.java +++ b/prism/src/main/java/org/apache/falcon/resource/admin/AdminResource.java @@ -19,16 +19,21 @@ package org.apache.falcon.resource.admin; import org.apache.commons.lang3.StringUtils; +import org.apache.falcon.security.CurrentUser; +import org.apache.falcon.security.SecurityUtil; import org.apache.falcon.util.BuildProperties; import org.apache.falcon.util.DeploymentProperties; import org.apache.falcon.util.RuntimeProperties; import org.apache.falcon.util.StartupProperties; import org.apache.hadoop.util.VersionInfo; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -97,6 +102,11 @@ public class AdminResource { property.value = VersionInfo.getVersion() + "-r" + VersionInfo.getRevision(); props.add(property); + property = new Property(); + property.key = "authentication"; + property.value = StartupProperties.get().getProperty("falcon.authentication.type", "simple"); + props.add(property); + version = new PropertyList(); version.properties = props; } @@ -144,7 +154,7 @@ public class AdminResource { @XmlRootElement(name = "property") @XmlAccessorType(XmlAccessType.FIELD) @edu.umd.cs.findbugs.annotations.SuppressWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) - private static class Property { + protected static class Property { public String key; public String value; } @@ -154,8 +164,39 @@ public class AdminResource { @XmlRootElement(name = "properties") @XmlAccessorType(XmlAccessType.FIELD) @edu.umd.cs.findbugs.annotations.SuppressWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) - private static class PropertyList { + protected static class PropertyList { public List<Property> properties; } //RESUME CHECKSTYLE CHECK VisibilityModifierCheck + + @GET + @Path("clearuser") + @Produces(MediaType.TEXT_PLAIN) + public String clearUser(@Context HttpServletResponse response) { + if (!SecurityUtil.isSecurityEnabled()) { + Cookie cookie = new Cookie("hadoop.auth", null); + cookie.setPath("/"); + cookie.setMaxAge(0); + cookie.setSecure(false); + response.addCookie(cookie); + } // Else, Do not checkin User, security is handled via Kerberos. + return "ok"; + } + + @GET + @Path("getuser") + @Produces(MediaType.TEXT_PLAIN) + public String getAuthenticatedUser() { + String user; + try { + if (SecurityUtil.isSecurityEnabled()) { + user = CurrentUser.getAuthenticatedUser(); + } else { + user = CurrentUser.getUser(); + } + } catch (IllegalStateException ile) { + user = ""; + } + return user; + } } http://git-wip-us.apache.org/repos/asf/falcon/blob/e3893a85/prism/src/test/java/org/apache/falcon/resource/admin/AdminResourceTest.java ---------------------------------------------------------------------- diff --git a/prism/src/test/java/org/apache/falcon/resource/admin/AdminResourceTest.java b/prism/src/test/java/org/apache/falcon/resource/admin/AdminResourceTest.java new file mode 100644 index 0000000..ea093c7 --- /dev/null +++ b/prism/src/test/java/org/apache/falcon/resource/admin/AdminResourceTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.falcon.resource.admin; + +import org.apache.falcon.security.CurrentUser; +import org.apache.falcon.util.StartupProperties; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.servlet.http.HttpServletResponse; + +/** + * Unit test for AdminResource. + */ +public class AdminResourceTest { + public static final String FALCON_USER = "falcon-user"; + + @BeforeClass + public void setUp() throws Exception { + CurrentUser.authenticate(FALCON_USER); + } + + @Test + public void testAdminVersion() throws Exception { + AdminResource resource = new AdminResource(); + AdminResource.PropertyList propertyList = resource.getVersion(); + for(AdminResource.Property property : propertyList.properties) { + if (property.key.equalsIgnoreCase("authentication")) { + Assert.assertEquals(property.value, "simple"); + } + } + + StartupProperties.get().setProperty("falcon.authentication.type", "kerberos"); + resource = new AdminResource(); + propertyList = resource.getVersion(); + for(AdminResource.Property property : propertyList.properties) { + if (property.key.equalsIgnoreCase("authentication")) { + Assert.assertEquals(property.value, "kerberos"); + } + } + } + + @Test + public void testUserHandling() throws Exception { + AdminResource resource = new AdminResource(); + Assert.assertEquals(FALCON_USER, resource.getAuthenticatedUser()); + HttpServletResponse response = new MockHttpServletResponse(); + Assert.assertEquals("ok", resource.clearUser(response)); + } + +} http://git-wip-us.apache.org/repos/asf/falcon/blob/e3893a85/prism/src/test/java/org/apache/falcon/resource/admin/MockHttpServletResponse.java ---------------------------------------------------------------------- diff --git a/prism/src/test/java/org/apache/falcon/resource/admin/MockHttpServletResponse.java b/prism/src/test/java/org/apache/falcon/resource/admin/MockHttpServletResponse.java new file mode 100644 index 0000000..c087394 --- /dev/null +++ b/prism/src/test/java/org/apache/falcon/resource/admin/MockHttpServletResponse.java @@ -0,0 +1,190 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.falcon.resource.admin; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +/** + * Mock class for HttpServletResponse. + */ +public class MockHttpServletResponse implements HttpServletResponse { + @Override + public void addCookie(Cookie cookie) { + + } + + @Override + public boolean containsHeader(String s) { + return false; + } + + @Override + public String encodeURL(String s) { + return null; + } + + @Override + public String encodeRedirectURL(String s) { + return null; + } + + @Override + public String encodeUrl(String s) { + return null; + } + + @Override + public String encodeRedirectUrl(String s) { + return null; + } + + @Override + public void sendError(int i, String s) throws IOException { + + } + + @Override + public void sendError(int i) throws IOException { + + } + + @Override + public void sendRedirect(String s) throws IOException { + + } + + @Override + public void setDateHeader(String s, long l) { + + } + + @Override + public void addDateHeader(String s, long l) { + + } + + @Override + public void setHeader(String s, String s1) { + + } + + @Override + public void addHeader(String s, String s1) { + + } + + @Override + public void setIntHeader(String s, int i) { + + } + + @Override + public void addIntHeader(String s, int i) { + + } + + @Override + public void setStatus(int i) { + + } + + @Override + public void setStatus(int i, String s) { + + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + @Override + public PrintWriter getWriter() throws IOException { + return null; + } + + @Override + public void setCharacterEncoding(String s) { + + } + + @Override + public void setContentLength(int i) { + + } + + @Override + public void setContentType(String s) { + + } + + @Override + public void setBufferSize(int i) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public void setLocale(Locale locale) { + + } + + @Override + public Locale getLocale() { + return null; + } +}
