-
Notifications
You must be signed in to change notification settings - Fork 122
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
127 changed files
with
4,120 additions
and
23,113 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
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
56 changes: 56 additions & 0 deletions
56
...erver/src/main/java/org/openmhealth/shim/CaseStandardizingOAuth2RequestAuthenticator.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,56 @@ | ||
/* | ||
* Copyright 2017 Open mHealth | ||
* | ||
* Licensed 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.openmhealth.shim; | ||
|
||
import org.springframework.http.client.ClientHttpRequest; | ||
import org.springframework.security.oauth2.client.DefaultOAuth2RequestAuthenticator; | ||
import org.springframework.security.oauth2.client.OAuth2ClientContext; | ||
import org.springframework.security.oauth2.client.OAuth2RequestAuthenticator; | ||
import org.springframework.security.oauth2.client.http.AccessTokenRequiredException; | ||
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; | ||
import org.springframework.security.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.util.StringUtils; | ||
|
||
|
||
/** | ||
* A customization of {@link DefaultOAuth2RequestAuthenticator} that standardizes the case of the Authorization header | ||
* token type to "Bearer". This is necessary because the default implementation doesn't work for Moves, which serves up | ||
* a "bearer" token but only accepts "Bearer" authorization headers. | ||
* | ||
* @author Dave Syer | ||
* @author Emerson Farrugia | ||
*/ | ||
public class CaseStandardizingOAuth2RequestAuthenticator implements OAuth2RequestAuthenticator { | ||
|
||
@Override | ||
public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, | ||
ClientHttpRequest request) { | ||
|
||
OAuth2AccessToken accessToken = clientContext.getAccessToken(); | ||
if (accessToken == null) { | ||
throw new AccessTokenRequiredException(resource); | ||
} | ||
|
||
String tokenType = accessToken.getTokenType(); | ||
|
||
if (!StringUtils.hasText(tokenType) || tokenType.equalsIgnoreCase(OAuth2AccessToken.BEARER_TYPE)) { | ||
tokenType = OAuth2AccessToken.BEARER_TYPE; // we'll assume basic bearer token type if none is specified. | ||
} | ||
|
||
request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue())); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
shim-server/src/main/java/org/openmhealth/shim/OptionalStreamSupport.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,35 @@ | ||
/* | ||
* Copyright 2017 Open mHealth | ||
* | ||
* Licensed 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.openmhealth.shim; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
|
||
/** | ||
* A set of utility methods to help with {@link Optional} {@link Stream} objects. | ||
* | ||
* @author Emerson Farrugia | ||
*/ | ||
public class OptionalStreamSupport { | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public static <O> Stream<O> asStream(Optional<O> optional) { | ||
|
||
return optional.map(Stream::of).orElseGet(Stream::empty); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...r/src/main/java/org/openmhealth/shim/fitbit/mapper/FitbitSleepMeasureDataPointMapper.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
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
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
Oops, something went wrong.