Skip to content

Commit

Permalink
Merge pull request #80 from hmrc/API-4056
Browse files Browse the repository at this point in the history
Remove trusted app functionality
  • Loading branch information
lburgos authored Nov 26, 2019
2 parents fcea76c + 4fbe8d5 commit c3c807c
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import play.api.{Configuration, Environment}
import uk.gov.hmrc.play.config.ServicesConfig
import uk.gov.hmrc.thirdpartyapplication.connector._
import uk.gov.hmrc.thirdpartyapplication.controllers.{ApplicationControllerConfig, DocumentationConfig}
import uk.gov.hmrc.thirdpartyapplication.models.TrustedApplicationsConfig
import uk.gov.hmrc.thirdpartyapplication.scheduled._
import uk.gov.hmrc.thirdpartyapplication.services.{CredentialConfig, ApplicationNameValidationConfig}

Expand All @@ -51,7 +50,6 @@ class ConfigurationModule extends Module {
bind[AwsApiGatewayConfig].toProvider[AwsApiGatewayConfigProvider],
bind[ThirdPartyDelegatedAuthorityConfig].toProvider[ThirdPartyDelegatedAuthorityConfigProvider],
bind[ApplicationControllerConfig].toProvider[ApplicationControllerConfigProvider],
bind[TrustedApplicationsConfig].toProvider[TrustedApplicationsConfigProvider],
bind[CredentialConfig].toProvider[CredentialConfigProvider],
bind[ApplicationNameValidationConfig].toProvider[ApplicationNameValidationConfigConfigProvider]
)
Expand Down Expand Up @@ -257,18 +255,6 @@ class ApplicationControllerConfigProvider @Inject()(val runModeConfiguration: Co
}
}

@Singleton
class TrustedApplicationsConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment)
extends Provider[TrustedApplicationsConfig] with ServicesConfig {

override protected def mode = environment.mode

override def get() = {
val trustedApplications: Seq[String] = ConfigHelper.getConfig(s"$env.trustedApplications", runModeConfiguration.getStringSeq)
TrustedApplicationsConfig(trustedApplications)
}
}

@Singleton
class CredentialConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment)
extends Provider[CredentialConfig] with ServicesConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ case class ApiDefinition(serviceName: String,
name: String,
context: String,
versions: Seq[ApiVersion],
requiresTrust: Option[Boolean],
isTestSupport: Option[Boolean] = None)

case class ApiVersion(version: String,
Expand All @@ -51,7 +50,7 @@ object APIAccessType extends Enumeration {
}

case class ApiSubscription(name: String, serviceName: String, context: String, versions: Seq[VersionSubscription],
requiresTrust: Option[Boolean], isTestSupport: Boolean = false)
isTestSupport: Boolean = false)

object ApiSubscription {

Expand All @@ -60,7 +59,7 @@ object ApiSubscription {
VersionSubscription(v, subscribedApis.exists(s => s.context == apiDefinition.context && s.version == v.version))
}
ApiSubscription(apiDefinition.name, apiDefinition.serviceName, apiDefinition.context, versionSubscriptions,
apiDefinition.requiresTrust, apiDefinition.isTestSupport.getOrElse(false))
apiDefinition.isTestSupport.getOrElse(false))
}
}

Expand Down
12 changes: 5 additions & 7 deletions app/uk/gov/hmrc/thirdpartyapplication/models/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import java.security.MessageDigest
import java.util.UUID

import com.google.common.base.Charsets
import javax.inject.Inject
import org.apache.commons.codec.binary.Base64
import org.joda.time.DateTime
import play.api.libs.json._
Expand Down Expand Up @@ -100,14 +99,14 @@ case class ApplicationResponse(id: UUID,
environment: Option[Environment] = None,
state: ApplicationState = ApplicationState(name = TESTING),
rateLimitTier: RateLimitTier = BRONZE,
trusted: Boolean = false,
checkInformation: Option[CheckInformation] = None,
blocked: Boolean = false,
ipWhitelist: Set[String] = Set.empty)
ipWhitelist: Set[String] = Set.empty,
trusted: Boolean = false)

object ApplicationResponse {

def apply(data: ApplicationData, trusted: Boolean) : ApplicationResponse = {
def apply(data: ApplicationData) : ApplicationResponse = {
val redirectUris = data.access match {
case a: Standard => a.redirectUris
case _ => Seq()
Expand Down Expand Up @@ -138,7 +137,6 @@ object ApplicationResponse {
Some(Environment.PRODUCTION),
data.state,
data.rateLimitTier.getOrElse(BRONZE),
trusted,
data.checkInformation,
data.blocked,
data.ipWhitelist)
Expand Down Expand Up @@ -287,10 +285,10 @@ case class ApplicationState(name: State = TESTING, requestedByEmailAddress: Opti

}

class ApplicationResponseCreator @Inject()(trustedApplications: TrustedApplications) {
class ApplicationResponseCreator {

def createApplicationResponse(applicationData: ApplicationData, totpSecrets: Option[TotpSecrets]) = {
CreateApplicationResponse(ApplicationResponse(applicationData, trustedApplications.isTrusted(applicationData)), totpSecrets)
CreateApplicationResponse(ApplicationResponse(applicationData), totpSecrets)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ object JsonFormatters {
(JsPath \ "name").read[String] and
(JsPath \ "context").read[String] and
(JsPath \ "versions").read[Seq[ApiVersion]] and
(JsPath \ "requiresTrust").readNullable[Boolean] and
(JsPath \ "isTestSupport").readNullable[Boolean]
) (ApiDefinition.apply _)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class ApplicationService @Inject()(applicationRepository: ApplicationRepository,
apiGatewayStore: ApiGatewayStore,
applicationResponseCreator: ApplicationResponseCreator,
credentialGenerator: CredentialGenerator,
trustedApplications: TrustedApplications,
apiSubscriptionFieldsConnector: ApiSubscriptionFieldsConnector,
thirdPartyDelegatedAuthorityConnector: ThirdPartyDelegatedAuthorityConnector,
nameValidationConfig: ApplicationNameValidationConfig) {
Expand All @@ -83,14 +82,14 @@ class ApplicationService @Inject()(applicationRepository: ApplicationRepository,
}

def update[T <: ApplicationRequest](id: UUID, application: T)(implicit hc: HeaderCarrier): Future[ApplicationResponse] = {
updateApp(id)(application) map (app => ApplicationResponse(data = app, trusted = trustedApplications.isTrusted(app)))
updateApp(id)(application) map (app => ApplicationResponse(data = app))
}

def updateCheck(id: UUID, checkInformation: CheckInformation): Future[ApplicationResponse] = {
for {
existing <- fetchApp(id)
savedApp <- applicationRepository.save(existing.copy(checkInformation = Some(checkInformation)))
} yield ApplicationResponse(data = savedApp, trusted = trustedApplications.isTrusted(savedApp))
} yield ApplicationResponse(data = savedApp)
}

def addCollaborator(applicationId: UUID, request: AddCollaboratorRequest)(implicit hc: HeaderCarrier) = {
Expand Down Expand Up @@ -273,61 +272,61 @@ class ApplicationService @Inject()(applicationRepository: ApplicationRepository,

def fetchByClientId(clientId: String): Future[Option[ApplicationResponse]] = {
applicationRepository.fetchByClientId(clientId) map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def recordApplicationUsage(applicationId: UUID): Future[ApplicationResponse] =
applicationRepository.recordApplicationUsage(applicationId)
.map(application =>
ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
ApplicationResponse(data = application))

def fetchByServerToken(serverToken: String): Future[Option[ApplicationResponse]] = {
applicationRepository.fetchByServerToken(serverToken) map {
_.map(application =>
ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
ApplicationResponse(data = application))
}
}

def fetchAllForCollaborator(emailAddress: String): Future[Seq[ApplicationResponse]] = {
applicationRepository.fetchAllForEmailAddress(emailAddress).map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetchAllForCollaboratorAndEnvironment(emailAddress: String, environment: String): Future[Seq[ApplicationResponse]] = {
applicationRepository.fetchAllForEmailAddressAndEnvironment(emailAddress, environment).map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetchAll(): Future[Seq[ApplicationResponse]] = {
applicationRepository.findAll().map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetchAllBySubscription(apiContext: String): Future[Seq[ApplicationResponse]] = {
applicationRepository.fetchAllForContext(apiContext) map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetchAllBySubscription(apiIdentifier: APIIdentifier): Future[Seq[ApplicationResponse]] = {
applicationRepository.fetchAllForApiIdentifier(apiIdentifier) map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetchAllWithNoSubscriptions(): Future[Seq[ApplicationResponse]] = {
applicationRepository.fetchAllWithNoSubscriptions() map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

def fetch(applicationId: UUID): Future[Option[ApplicationResponse]] = {
applicationRepository.fetch(applicationId) map {
_.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application)))
_.map(application => ApplicationResponse(data = application))
}
}

Expand All @@ -339,7 +338,7 @@ class ApplicationService @Inject()(applicationRepository: ApplicationRepository,
total = data.totals.foldLeft(0)(_ + _.total),
matching = data.matching.foldLeft(0)(_ + _.total),
applications =
data.applications.map(application => ApplicationResponse(data = application, trusted = trustedApplications.isTrusted(application))))
data.applications.map(application => ApplicationResponse(data = application)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import scala.concurrent.Future
@Singleton
class CredentialService @Inject()(applicationRepository: ApplicationRepository,
auditService: AuditService,
trustedApplications: TrustedApplications,
applicationResponseCreator: ApplicationResponseCreator,
config: CredentialConfig) {

val clientSecretLimit = config.clientSecretLimit

def fetch(applicationId: UUID): Future[Option[ApplicationResponse]] = {
applicationRepository.fetch(applicationId) map (_.map(
app => ApplicationResponse(data = app, trusted = trustedApplications.isTrusted(app))))
app => ApplicationResponse(data = app)))
}

def fetchCredentials(applicationId: UUID): Future[Option[EnvironmentTokenResponse]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class GatekeeperService @Inject()(applicationRepository: ApplicationRepository,
apiSubscriptionFieldsConnector: ApiSubscriptionFieldsConnector,
apiGatewayStore: ApiGatewayStore,
applicationResponseCreator: ApplicationResponseCreator,
trustedApplications: TrustedApplications,
thirdPartyDelegatedAuthorityConnector: ThirdPartyDelegatedAuthorityConnector,
applicationService: ApplicationService) {

Expand Down Expand Up @@ -75,7 +74,7 @@ class GatekeeperService @Inject()(applicationRepository: ApplicationRepository,
app <- fetchApp(id)
history <- stateHistoryRepository.fetchByApplicationId(id)
} yield {
ApplicationWithHistory(ApplicationResponse(data = app, trusted = trustedApplications.isTrusted(app)),
ApplicationWithHistory(ApplicationResponse(data = app),
history.map(StateHistoryResponse.from))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import uk.gov.hmrc.thirdpartyapplication.connector.ApiDefinitionConnector
import uk.gov.hmrc.thirdpartyapplication.models.ApiStatus.ALPHA
import uk.gov.hmrc.thirdpartyapplication.models.JsonFormatters._
import uk.gov.hmrc.thirdpartyapplication.models.db.ApplicationData
import uk.gov.hmrc.thirdpartyapplication.models.{TrustedApplicationsConfig, _}
import uk.gov.hmrc.thirdpartyapplication.models.{_}
import uk.gov.hmrc.thirdpartyapplication.repository.{ApplicationRepository, SubscriptionRepository}
import uk.gov.hmrc.thirdpartyapplication.services.AuditAction._

Expand All @@ -39,23 +39,20 @@ class SubscriptionService @Inject()(applicationRepository: ApplicationRepository
subscriptionRepository: SubscriptionRepository,
apiDefinitionConnector: ApiDefinitionConnector,
auditService: AuditService,
apiGatewayStore: ApiGatewayStore,
trustedAppConfig: TrustedApplicationsConfig) {
apiGatewayStore: ApiGatewayStore) {

val IgnoredContexts: Seq[String] = Seq("sso-in/sso", "web-session/sso-api")

def searchCollaborators(context:String, version:String, partialEmailMatch: Option[String]):Future[Seq[String]] = {
subscriptionRepository.searchCollaborators(context, version, partialEmailMatch)
}

val trustedApplications = trustedAppConfig.trustedApplications

def fetchAllSubscriptions(): Future[List[SubscriptionData]] = subscriptionRepository.findAll()

def fetchAllSubscriptionsForApplication(applicationId: UUID)(implicit hc: HeaderCarrier): Future[Seq[ApiSubscription]] = {
def fetchApis: Future[Seq[ApiDefinition]] = apiDefinitionConnector.fetchAllAPIs(applicationId) map {
_.filter(api => trustedApplications.contains(applicationId.toString) || !api.requiresTrust.getOrElse(false))
.map(api => api.copy(versions = api.versions.filterNot(_.status == ALPHA)))
_.map(api => api.copy(versions = api.versions.filterNot(_.status == ALPHA)))
.filterNot(_.versions.isEmpty)
}

Expand Down
2 changes: 0 additions & 2 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ validateForDuplicateAppNames = true
Dev {
skipWso2 = true
devHubBaseUrl = "http://localhost:9685"
trustedApplications = []

mongodb {
uri = "mongodb://localhost:27017/third-party-application?rm.monitorRefreshMS=4000&rm.failover=default"
Expand Down Expand Up @@ -246,7 +245,6 @@ Dev {
Test {
skipWso2 = true
devHubBaseUrl = "http://localhost:9685"
trustedApplications = [162017dc-607b-4405-8208-a28308672f76, 162017dc-607b-4405-8208-a28308672f77]

mongodb {
uri = "mongodb://localhost:27017/third-party-application-test?rm.monitorRefreshMS=4000&rm.failover=default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class ThirdPartyApplicationComponentSpec extends BaseFeatureSpec {

Then("The API subscription is returned")
val result = Json.parse(response.body).as[Seq[ApiSubscription]]
result shouldBe Seq(ApiSubscription(apiName, serviceName, context, Seq(VersionSubscription(anApiDefinition.versions.head, subscribed = true)), None))
result shouldBe Seq(ApiSubscription(apiName, serviceName, context, Seq(VersionSubscription(anApiDefinition.versions.head, subscribed = true))))
}

scenario("Fetch All API Subscriptions") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ class ApplicationControllerSpec extends UnitSpec with ScalaFutures with MockitoS
}

private def anAPISubscription() = {
new ApiSubscription("name", "service-name", "some-context", Seq(VersionSubscription(ApiVersion("1.0", ApiStatus.STABLE, None), subscribed = true)), None)
new ApiSubscription("name", "service-name", "some-context", Seq(VersionSubscription(ApiVersion("1.0", ApiStatus.STABLE, None), subscribed = true)))
}

private def aSubcriptionData() = {
Expand Down
Loading

0 comments on commit c3c807c

Please sign in to comment.