-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from onc-healthit/develop
merge develop into master for release
- Loading branch information
Showing
29 changed files
with
1,204 additions
and
994 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
64 changes: 64 additions & 0 deletions
64
src/main/java/org/sitenv/service/ccda/smartscorecard/authorization/GenerateAccessToken.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,64 @@ | ||
package org.sitenv.service.ccda.smartscorecard.authorization; | ||
|
||
import java.util.Objects; | ||
|
||
import org.json.JSONObject; | ||
import org.sitenv.service.ccda.smartscorecard.model.ScorecardProperties; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Component | ||
public class GenerateAccessToken { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(GenerateAccessToken.class); | ||
|
||
@Autowired | ||
@Qualifier("scorecardProperties") | ||
ScorecardProperties scorecardProperties; | ||
|
||
public String getAccessToken() { | ||
String accessToken = null; | ||
try { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
|
||
String tokenEndpoint = scorecardProperties.getTokenEndpoint(); | ||
logger.info("tokenEndpoint: " + tokenEndpoint); | ||
String clientId = scorecardProperties.getClientId(); | ||
logger.info("clientId: " + clientId); | ||
String clientSecret = scorecardProperties.getClientSecret(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
|
||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); | ||
map.add("grant_type", "client_credentials"); | ||
map.add("client_secret", clientSecret); | ||
map.add("client_id", clientId); | ||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers); | ||
ResponseEntity<KeyCloakResponse> response = restTemplate.postForEntity(tokenEndpoint, request, | ||
KeyCloakResponse.class); | ||
|
||
JSONObject jsonObj = new JSONObject(Objects.requireNonNull(response.getBody())); | ||
accessToken = jsonObj.getString("access_token"); | ||
logger.info("getAccessToken accessToken status :::::::" + response.getStatusCode()); | ||
} catch (HttpClientErrorException clienterror) { | ||
logger.error("HttpClientErrorException :::::::" + clienterror.getMessage()); | ||
clienterror.printStackTrace(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return accessToken; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/sitenv/service/ccda/smartscorecard/authorization/KeyCloakResponse.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,33 @@ | ||
package org.sitenv.service.ccda.smartscorecard.authorization; | ||
|
||
public class KeyCloakResponse { | ||
|
||
private String access_token; | ||
private int expires_in; | ||
private String user; | ||
|
||
public String getAccess_token() { | ||
return access_token; | ||
} | ||
|
||
public void setAccess_token(String access_token) { | ||
this.access_token = access_token; | ||
} | ||
|
||
public int getExpires_in() { | ||
return expires_in; | ||
} | ||
|
||
public void setExpires_in(int expires_in) { | ||
this.expires_in = expires_in; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
} |
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
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.