Skip to content

Commit

Permalink
OLMIS-6879: Added corrections to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
saleksandra committed Jul 7, 2020
1 parent 725fa46 commit 98bd16a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/org/openlmis/auth/ApiSupersetClientInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.openlmis.auth;

import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.openlmis.auth.domain.Client;
import org.openlmis.auth.repository.ClientRepository;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -40,6 +42,12 @@ public class ApiSupersetClientInitializer implements CommandLineRunner {
@Value("${auth.server.clientId.superset.redirectUri}")
private String supersetClientRedirectUri;

private static final String AUTHORIZED_GRANT_TYPES = "authorization_code";
private static final String AUTHORITIES = "TRUSTED_CLIENT";
private static final String SCOPE = "read,write";
private static final String RESOURCE_IDS = "hapifhir,notification,diagnostics,cce,auth,"
+ "requisition,referencedata,report,stockmanagement,fulfillment,reference-ui";

/**
* This method is part of CommandLineRunner and is called automatically by Spring.
* @param args Main method arguments.
Expand All @@ -58,20 +66,18 @@ private void createClient() {
client.get().setClientSecret(supersetClientSecret);
clientRepository.saveAndFlush(client.get());
} else if (!client.isPresent()) {
clientRepository.saveAndFlush(new Client(supersetClientId, supersetClientSecret,
"TRUSTED_CLIENT", supersetClientRedirectUri, "authorization_code", "read,write",
"hapifhir,notification,diagnostics,cce,auth,requisition,referencedata,report,"
+ "stockmanagement,fulfillment,reference-ui"));
clientRepository.saveAndFlush(new Client(supersetClientId, supersetClientSecret, AUTHORITIES,
supersetClientRedirectUri, AUTHORIZED_GRANT_TYPES, SCOPE, RESOURCE_IDS));
}
}

private boolean clientSholudBeUpdated(Client client) {
return !client.getClientSecret().equals(supersetClientSecret)
|| !client.getRegisteredRedirectUris().equals(supersetClientRedirectUri);
return !StringUtils.equals(client.getClientSecret(), supersetClientSecret)
|| !StringUtils.equals(client.getRegisteredRedirectUris(), supersetClientRedirectUri);
}

private boolean hasDefinedProperties() {
return supersetClientId != null && !supersetClientId.isEmpty()
&& supersetClientSecret != null && !supersetClientSecret.isEmpty();
return StringUtils.isNotBlank(supersetClientId)
&& StringUtils.isNotBlank(supersetClientSecret);
}
}

0 comments on commit 98bd16a

Please sign in to comment.