-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
5,208 additions
and
985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
language: java | ||
dist: trusty | ||
sudo: required | ||
jdk: | ||
- oraclejdk7 | ||
deploy: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...vice/src/main/java/com/mangosolutions/rcloud/rawgist/ContentNegotiationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 AT&T Intellectual Property, [http://www.att.com] | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*******************************************************************************/ | ||
package com.mangosolutions.rcloud.rawgist; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; | ||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(GistServiceProperties.class) | ||
public class ContentNegotiationConfiguration extends WebMvcConfigurerAdapter { | ||
|
||
private static final List<MediaType> DEFAULT_GITHUB_MEDIA_TYPES = Arrays.asList( | ||
MediaType.parseMediaType("application/vnd.github.beta+json"), | ||
MediaType.parseMediaType("application/vnd.github.beta"), | ||
MediaType.parseMediaType("application/vnd.github.v3+json"), | ||
MediaType.parseMediaType("application/vnd.github.v3") | ||
); | ||
|
||
@Autowired | ||
private GistServiceProperties serviceProperties; | ||
|
||
@Override | ||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { | ||
configurer.ignoreAcceptHeader(true); | ||
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8); | ||
} | ||
|
||
@Override | ||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
super.extendMessageConverters(converters); | ||
for (HttpMessageConverter<?> converter : converters) { | ||
if (isJsonConverter(converter)) { | ||
updateMediaTypes((AbstractJackson2HttpMessageConverter) converter); | ||
} | ||
} | ||
} | ||
|
||
private void updateMediaTypes(AbstractJackson2HttpMessageConverter converter) { | ||
Collection<MediaType> gistMediaTypes = getMediaTypes(converter); | ||
List<MediaType> mediaTypes = new ArrayList<>(gistMediaTypes); | ||
converter.setSupportedMediaTypes(mediaTypes); | ||
} | ||
|
||
private Collection<MediaType> getMediaTypes(AbstractJackson2HttpMessageConverter converter) { | ||
Set<MediaType> mediaTypes = new LinkedHashSet<>(converter.getSupportedMediaTypes()); | ||
for(String mediaType: serviceProperties.getMediatypes()) { | ||
mediaTypes.add(MediaType.parseMediaType(mediaType)); | ||
} | ||
mediaTypes.addAll(DEFAULT_GITHUB_MEDIA_TYPES); | ||
return mediaTypes; | ||
} | ||
|
||
private boolean isJsonConverter(HttpMessageConverter<?> converter) { | ||
if(AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converter.getClass())) { | ||
for (MediaType mediaType : converter.getSupportedMediaTypes()) { | ||
if (mediaType.equals(MediaType.APPLICATION_JSON)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...src/main/java/com/mangosolutions/rcloud/rawgist/RequestParameterAuthenticationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 AT&T Intellectual Property, [http://www.att.com] | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*******************************************************************************/ | ||
package com.mangosolutions.rcloud.rawgist; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; | ||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException; | ||
import org.springframework.util.Assert; | ||
|
||
public class RequestParameterAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter { | ||
|
||
private String principalRequestParameter = "session_token"; | ||
private String credentialsRequestParameter; | ||
private boolean exceptionIfHeaderMissing = true; | ||
|
||
/** | ||
* Read and returns the header named by {@code principalRequestHeader} from the | ||
* request. | ||
* | ||
* @throws PreAuthenticatedCredentialsNotFoundException if the header is missing and | ||
* {@code exceptionIfHeaderMissing} is set to {@code true}. | ||
*/ | ||
@Override | ||
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) { | ||
String principal = request.getParameter(principalRequestParameter); | ||
|
||
if (principal == null && exceptionIfHeaderMissing) { | ||
throw new PreAuthenticatedCredentialsNotFoundException(principalRequestParameter | ||
+ " parameter not found in request."); | ||
} | ||
|
||
return principal; | ||
} | ||
|
||
/** | ||
* Credentials aren't usually applicable, but if a {@code credentialsRequestHeader} is | ||
* set, this will be read and used as the credentials value. Otherwise a dummy value | ||
* will be used. | ||
*/ | ||
@Override | ||
protected Object getPreAuthenticatedCredentials(HttpServletRequest request) { | ||
if (credentialsRequestParameter != null) { | ||
return request.getParameter(credentialsRequestParameter); | ||
} | ||
|
||
return "N/A"; | ||
} | ||
|
||
public void setPrincipalRequestParameter(String principalRequestHeader) { | ||
Assert.hasText(principalRequestHeader, | ||
"principalRequestHeader must not be empty or null"); | ||
this.principalRequestParameter = principalRequestHeader; | ||
} | ||
|
||
public void setCredentialsRequestParameter(String credentialsRequestHeader) { | ||
Assert.hasText(credentialsRequestHeader, | ||
"credentialsRequestHeader must not be empty or null"); | ||
this.credentialsRequestParameter = credentialsRequestHeader; | ||
} | ||
|
||
/** | ||
* Defines whether an exception should be raised if the principal header is missing. | ||
* Defaults to {@code true}. | ||
* | ||
* @param exceptionIfHeaderMissing set to {@code false} to override the default | ||
* behaviour and allow the request to proceed if no header is found. | ||
*/ | ||
public void setExceptionIfHeaderMissing(boolean exceptionIfHeaderMissing) { | ||
this.exceptionIfHeaderMissing = exceptionIfHeaderMissing; | ||
} | ||
|
||
} |
Oops, something went wrong.