-
Notifications
You must be signed in to change notification settings - Fork 271
KNOX-2412 - Add Logout Link to Home Page for Select Authentication Pr… #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get why do we need the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
|
|
||
| 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/") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps changing this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/**?**" }; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.