Skip to content
Merged
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
7 changes: 7 additions & 0 deletions gateway-release/home/conf/gateway-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ limitations under the License.
<description>The interval (in seconds) for polling Ambari for cluster configuration changes.</description>
</property>

<!-- @since 1.5.0 homepage logout -->
<property>
<name>knox.homepage.logout.enabled</name>
<value>true</value>
<description>Enable/disable logout from the Knox Homepage.</description>
</property>

<!-- Knox Admin related config -->
<property>
<name>gateway.knox.admin.groups</name>
Expand Down
6 changes: 6 additions & 0 deletions gateway-release/home/conf/topologies/homepage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<enabled>true</enabled>
</provider>
</gateway>
<service>
<role>KNOXSSOUT</role>
</service>
<service>
<role>KNOX-SESSION</role>
</service>
<service>
<role>KNOX-METADATA</role>
</service>
Expand Down
2 changes: 1 addition & 1 deletion gateway-release/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
</dependency>
<dependency>
<groupId>org.apache.knox</groupId>
<artifactId>gateway-service-metadata</artifactId>
<artifactId>gateway-service-session</artifactId>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not add the new service as a separate dependency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't know what you mean here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure why the patch only shows up like this but the original gateway-service-metadata is still in there. I had originally copy and pasted it but forgot to change the name then went back and changed it. The merged file looks fine.

</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
private static final String KNOX_HOMEPAGE_PINNED_TOPOLOGIES = "knox.homepage.pinned.topologies";
private static final String KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES = "knox.homepage.hidden.topologies";
private static final Set<String> KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES_DEFAULT = new HashSet<>(Arrays.asList("admin", "manager", "knoxsso", "metadata", "homepage"));
private static final String KNOX_HOMEPAGE_LOGOUT_ENABLED = "knox.homepage.logout.enabled";

public GatewayConfigImpl() {
init();
Expand Down Expand Up @@ -1174,4 +1175,9 @@ public String getServiceParameter(String service, String parameter) {
return get(GATEWAY_SERVICE_PREFIX + service + "." + parameter, "");
}

@Override
public boolean homePageLogoutEnabled() {
return getBoolean(KNOX_HOMEPAGE_LOGOUT_ENABLED, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WebSSOutResource {
private static final String SSO_COOKIE_NAME = "knoxsso.cookie.name";
private static final String DEFAULT_SSO_COOKIE_NAME = "hadoop-jwt";

static final String RESOURCE_PATH = "/api/v1/webssout";
static final String RESOURCE_PATH = "knoxssout/api/v1/webssout";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't get why do we need the knoxssout. This change makes the SSOUT API inconsistent with the rest of the APIs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not all of the other APIs do that. It was done that way for APIs that were initially intended to be deployed to a single dedicated topology. Like the admin.xml.


private String cookieName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected String[] getPackages() {

@Override
protected String[] getPatterns() {
return new String[]{ "api/**?**" };
return new String[]{ "knoxssout/api/**?**" };
}

}
74 changes: 74 additions & 0 deletions gateway-service-session/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.knox</groupId>
<artifactId>gateway</artifactId>
<version>1.5.0-SNAPSHOT</version>
</parent>

<artifactId>gateway-service-session</artifactId>
<name>gateway-service-session</name>

<dependencies>
<dependency>
<groupId>org.apache.knox</groupId>
<artifactId>gateway-i18n</artifactId>
</dependency>
<dependency>
<groupId>org.apache.knox</groupId>
<artifactId>gateway-provider-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.apache.knox</groupId>
<artifactId>gateway-spi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.knox</groupId>
<artifactId>gateway-util-common</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.knox.gateway.service.session;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "sessioninfo")
public class SessionInformation {
@XmlElement
private String user;

@XmlElement
private String logoutUrl;

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public String getLogoutUrl() {
return logoutUrl;
}

public void setLogoutUrl(String logoutUrl) {
this.logoutUrl = logoutUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.knox.gateway.service.session;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.JAXBContextProperties;

@Provider
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class SessionInformationMarshaller implements MessageBodyWriter<SessionInformation>{
private static Marshaller xmlMarshaller;
private static Marshaller jsonMarshaller;

@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return SessionInformation.class == type;
}

@Override
public long getSize(SessionInformation t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}

@Override
public void writeTo(SessionInformation instance, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
try {
getMarshaller(mediaType).marshal(instance, entityStream);
} catch (JAXBException e) {
throw new IOException(e);
}
}

private Marshaller getMarshaller(MediaType mediaType) throws JAXBException {
return MediaType.APPLICATION_JSON_TYPE.getSubtype().equals(mediaType.getSubtype()) ? getJsonMarshaller() : getXmlMarshaller();
}

private synchronized Marshaller getXmlMarshaller() throws JAXBException {
if (xmlMarshaller == null) {
final Map<String, Object> properties = new HashMap<>(1);
properties.put(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
xmlMarshaller = JAXBContextFactory.createContext(new Class[] { SessionInformation.class }, properties).createMarshaller();
xmlMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}
return xmlMarshaller;
}

private synchronized Marshaller getJsonMarshaller() throws JAXBException {
if (jsonMarshaller == null) {
final Map<String, Object> properties = new HashMap<>(1);
properties.put(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
jsonMarshaller = JAXBContextFactory.createContext(new Class[] { SessionInformation.class }, properties).createMarshaller();
jsonMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}
return jsonMarshaller;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.knox.gateway.service.session;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;

import javax.inject.Singleton;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.i18n.messages.MessagesFactory;
import org.apache.knox.gateway.security.SubjectUtils;

@Singleton
@Path("session/api/v1/")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps changing this to api/v1/session to be consistent with another API endpoints?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't believe so - this is the session API, for now there is a sessioninfo but we could potentially add other things to it. It can be added to any topology and addressed via the session context path.

public class SessionResource {
private static final SessionServiceMessages LOG = MessagesFactory.get(SessionServiceMessages.class);

@Context
HttpServletRequest request;

@Context
ServletContext context;

@GET
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Path("sessioninfo")
public SessionInformation getSessionInformation() {
final SessionInformation sessionInfo = new SessionInformation();
sessionInfo.setUser(SubjectUtils.getCurrentEffectivePrincipalName());
final GatewayConfig config = (GatewayConfig) context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
if (config != null && config.homePageLogoutEnabled()) {
String logoutUrl = getBaseGatewayUrl(config) + "/homepage/knoxssout/api/v1/webssout";
LOG.homePageLogoutEnabled(logoutUrl);
sessionInfo.setLogoutUrl(logoutUrl);
}

return sessionInfo;
}

private String getBaseGatewayUrl(GatewayConfig config) {
return request.getRequestURL().substring(0, request.getRequestURL().length() - request.getRequestURI().length()) + "/" + config.getGatewayPath();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.knox.gateway.service.session;

import org.apache.knox.gateway.jersey.JerseyServiceDeploymentContributorBase;

public class SessionServiceDeploymentContributor extends JerseyServiceDeploymentContributorBase {

@Override
public String getRole() {
return "KNOX-SESSION";
}

@Override
public String getName() {
return "knox-session";
}

@Override
protected String[] getPackages() {
return new String[] { "org.apache.knox.gateway.service.session" };
}

@Override
protected String[] getPatterns() {
return new String[] { "session/api/**?**" };
}

}
Loading