Skip to content
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

Skipped org validation for service accounts. #195

Merged
merged 2 commits into from
May 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public OAuth2TokenValidatorResult validate(Jwt jwt) {

String org = jwt.getClaim(SecurityUtil.CLAIM_ORGANIZATION);

if (StringUtils.isNotEmpty(org)) {
// Service accounts won't have an Organization so don't validate
if (SecurityUtil.isServiceAccount(jwt) || StringUtils.isNotEmpty(org)) {
return OAuth2TokenValidatorResult.success();
} else {
// Audit the failure. Only users with defined Organization should be considered as authorized and able to access MSP Direct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ protected void configure(HttpSecurity http) throws Exception {
.mvcMatchers(HttpMethod.POST, "/msp-contracts/update-contract-address").hasRole("UpdateContractAddress")
.mvcMatchers(HttpMethod.POST, "/msp-contracts/inquire-contract").hasAnyRole("ContractInquiry", "GetContractAddress") //inquire-contract endpoint will require this multi role as it is used by both R40 and R37 transactions
.mvcMatchers(HttpMethod.POST, "/patient-registration/get-patient-registration").hasRole("PatientRegistration")
.mvcMatchers(HttpMethod.GET, "/payee-mapping/").hasAnyRole("PatientRegistration", "ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.GET, "/payee-mapping/{id}").hasAnyRole("PatientRegistration", "ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.POST, "/payee-mapping").hasRole("ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.PUT, "/payee-mapping/").hasRole("ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.DELETE, "/payee-mapping/").hasRole("ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.PUT, "/payee-mapping/{id}").hasRole("ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.DELETE, "/payee-mapping/{id}").hasRole("ManageMSPPayeeNumber")
.mvcMatchers(HttpMethod.GET, "/user/**").fullyAuthenticated()
.mvcMatchers("/*").denyAll()
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +29,7 @@ public class SecurityUtil {
public static final String CLAIM_USERNAME = "preferred_username";
private static final String CLAIM_SUB = "sub"; // the Subject claim identifies the principal that is the subject of the JWT
public static final String CLAIM_ORGANIZATION = "org_details";
public static final String CLAIM_CLIENT_ID = "clientId";

private static final String ORGANIZATION_ID = "id";

Expand All @@ -37,6 +39,8 @@ public class SecurityUtil {

private static final String UNKNOWN_ROLE = "UNKNOWN";

private static final String SERVICE_SUFFIX = "-SERVICE";

private static String KEYCLOAK_CLIENT;

private static SecurityProperties securityProperties;
Expand Down Expand Up @@ -167,5 +171,17 @@ public static List<String> loadPermissions(Jwt jwt, Map<String, List<String>> ro

return permissions;
}

/**
* Checks if the jwt is generated for a service account.
* @param jwt
* @return
*/
public static Boolean isServiceAccount(Jwt jwt) {
// This is just a rough check to see if the client is a service account
// It's good enough to detect any current MSP Direct API clients
return StringUtils.endsWith(jwt.getClaim(SecurityUtil.CLAIM_CLIENT_ID), SERVICE_SUFFIX);

}

}