Skip to content

Commit

Permalink
Merge pull request #7 from Opetushallitus/OK-365-raportointikali
Browse files Browse the repository at this point in the history
OK-365 raportointikäyttöliittymä
  • Loading branch information
marjakari authored Jan 30, 2024
2 parents b07493d + d5f1a09 commit 4e5cf95
Show file tree
Hide file tree
Showing 62 changed files with 9,242 additions and 184 deletions.
72 changes: 70 additions & 2 deletions cdk/lib/sovellus-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,49 @@ export class SovellusStack extends cdk.Stack {
autoDeleteObjects: true
});

const swaggerKeyPrefix = 'swagger';
const staticS3Deployment = new s3deploy.BucketDeployment(this, 'DeployWebsite', {
sources: [s3deploy.Source.asset('../static')],
destinationBucket: staticBucket,
destinationKeyPrefix: swaggerKeyPrefix,
});

/**
* Raportointikäyttöliittymä
*/
const lambdaAdapterLayer = lambda.LayerVersion.fromLayerVersionArn(
this,
'LambdaAdapterLayerX86',
`arn:aws:lambda:${this.region}:753240598075:layer:LambdaAdapterLayerX86:19`
);

const raportointiKayttoliittymaFunction = new lambda.Function(this, 'NextCdkFunction', {
functionName: `${props.environmentName}-viestinvalityspalvelu-raportointikayttoliittyma`,
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'run.sh',
memorySize: 1024,
timeout: Duration.seconds(60),
code: lambda.Code.fromAsset(path.join(
__dirname,
'../../viestinvalitys-raportointi/.next/', 'standalone')
),
architecture: lambda.Architecture.X86_64,
environment: {
'AWS_LAMBDA_EXEC_WRAPPER': '/opt/bootstrap',
'RUST_LOG': 'info',
'PORT': '8080',
},
layers: [lambdaAdapterLayer],
});

const raportointiKayttoliittymaFunctionUrl = raportointiKayttoliittymaFunction.addFunctionUrl({
authType: FunctionUrlAuthType.NONE,
});

const nextJsS3Deployment = new s3deploy.BucketDeployment(this, 'NextJsStaticDeployment', {
sources: [s3deploy.Source.asset('../viestinvalitys-raportointi/.next/static')],
destinationBucket: staticBucket,
destinationKeyPrefix: 'static/_next/static'
});

const cloudfrontOAI = new cloudfront.OriginAccessIdentity(
Expand Down Expand Up @@ -423,16 +463,44 @@ export class SovellusStack extends cdk.Stack {
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
}],
},
'/raportointi/*': {
'/raportointi/login': {
origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
originRequestPolicy,
},
'/raportointi/login/*': {
origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
originRequestPolicy,
},
'/raportointi': {
origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiKayttoliittymaFunctionUrl.url)), {}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
originRequestPolicy,
},
'/raportointi/v1/*': {
origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
originRequestPolicy,
},
'/raportointi/*': {
origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiKayttoliittymaFunctionUrl.url)), {}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
originRequestPolicy,
},
'/static/*': {
origin: new cloudfront_origins.S3Origin(staticBucket, {
originAccessIdentity: cloudfrontOAI
originAccessIdentity: cloudfrontOAI,
}),
cachePolicy: noCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
Expand Down
103 changes: 102 additions & 1 deletion integraatio/src/test/scala/fi/oph/viestinvalitys/LocalUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ package fi.oph.viestinvalitys

import fi.oph.viestinvalitys.vastaanotto.resource.LahetysAPIConstants
import fi.oph.viestinvalitys.migraatio.LambdaHandler
import fi.oph.viestinvalitys.util.{AwsUtil, ConfigurationUtil}
import fi.oph.viestinvalitys.util.{AwsUtil, ConfigurationUtil, DbUtil}
import org.apache.commons.io.IOUtils
import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.services.s3.model.{CreateBucketRequest, ListObjectsRequest, PutObjectRequest}
import software.amazon.awssdk.services.ses.model.{ConfigurationSet, CreateConfigurationSetEventDestinationRequest, CreateConfigurationSetRequest, EventDestination, EventType, SNSDestination, VerifyDomainIdentityRequest}
import software.amazon.awssdk.services.sns.model.{CreateTopicRequest, SubscribeRequest}
import software.amazon.awssdk.services.sqs.model.{CreateQueueRequest, ListQueuesRequest}
import com.amazonaws.services.lambda.runtime.{ClientContext, CognitoIdentity, Context, LambdaLogger}
import fi.oph.viestinvalitys.business.{KantaOperaatiot, Kieli, Kontakti, Prioriteetti, SisallonTyyppi}
import fi.oph.viestinvalitys.vastaanotto.security.SecurityConstants

import java.util.UUID
import scala.Range
import scala.beans.BeanProperty
import scala.collection.immutable.Range

case class TestAwsContext(
@BeanProperty awsRequestId: String,
Expand Down Expand Up @@ -154,6 +158,103 @@ object LocalUtil {

// ajetaan migraatiolambdan koodi
new LambdaHandler().handleRequest(null, new TestAwsContext("migraatio"))

// alustetaan data
val kantaOperaatiot = new KantaOperaatiot(DbUtil.database)
val lahetyksia = kantaOperaatiot.getLahetykset(Option.empty, Option.apply(20), Set(SecurityConstants.SECURITY_ROOLI_KATSELU_FULL))
if(lahetyksia.isEmpty || lahetyksia.length < 3) {
// lähetyksiä joissa räätälöity viesti useilla vastaanottajilla
Range(0, 25).map(counter => {
val lahetys = kantaOperaatiot.tallennaLahetys(
"Testiotsikko "+counter,
"omistaja",
"hakemuspalvelu",
Option.apply("0.1.2.3"),
Kontakti(Option.apply("Testi Virkailija"+counter), "[email protected]"+counter),
Option.apply("[email protected]"),
Prioriteetti.NORMAALI,
365
)
// viestit lähetystunnuksella
Range(0, 25).map(viestinro => {
kantaOperaatiot.tallennaViesti("Viestin testiotsikko " + viestinro,
"Viestin sisältö " + viestinro,
SisallonTyyppi.TEXT,
Set(Kieli.FI),
Map.empty,
Option.empty,
Option.empty,
Option.empty,
Seq(Kontakti(Option.apply("Vastaanottaja " + viestinro), "vastaanottaja" + viestinro + "@example.com")),
Seq.empty,
Option.empty,
Option.apply(lahetys.tunniste),
Option.empty,
Option.apply(365),
Set(SecurityConstants.SECURITY_ROOLI_KATSELU_FULL),
Map("avain" -> Seq("arvo")),
"omistaja")
})
})
// lähetys jossa samalla viestillä useita vastaanottajia
val lahetys2 = kantaOperaatiot.tallennaLahetys(
"Testiotsikko2",
"omistaja",
"hakemuspalvelu",
Option.apply("0.1.2.3"),
Kontakti(Option.apply("Joku Virkailija"), "[email protected]"),
Option.apply("[email protected]"),
Prioriteetti.NORMAALI,
365
)
kantaOperaatiot.tallennaViesti("Massaviestin testiotsikko",
"Massaviestin sisältö",
SisallonTyyppi.TEXT,
Set(Kieli.FI),
Map.empty, // maskit
Option.empty, // läh. oid
Option.empty, // lähettäjä
Option.empty, // replyto
Range(0, 20).map(suffix => Kontakti(Option.apply("Vastaanottaja" + suffix), "vastaanottaja" + suffix + "@example.com")),
Seq.empty,
Option.empty,
Option.apply(lahetys2.tunniste),
Option.apply(Prioriteetti.NORMAALI),
Option.apply(365),
Set(SecurityConstants.SECURITY_ROOLI_KATSELU_FULL),
Map("avain" -> Seq("arvo")),
"omistaja")
// tyhjä lähetys
val lahetys3 = kantaOperaatiot.tallennaLahetys(
"Orpo lähetys",
"omistaja",
"osoitepalvelu",
Option.apply("0.1.2.3"),
Kontakti(Option.apply("Testi Virkailija"), "[email protected]"),
Option.apply("[email protected]"),
Prioriteetti.NORMAALI,
365
)
// viesti ilman lähetystunnusta
kantaOperaatiot.tallennaViesti("Tärkeää asiaa",
"Tärkeä sisältö",
SisallonTyyppi.TEXT,
Set(Kieli.FI),
Map.empty,
Option.apply("0.1.2.3"),
Option.apply(Kontakti(Option.apply("Testi Virkailija"), "[email protected]")),
Option.apply("[email protected]"),
Range(0, 3).map(suffix => Kontakti(Option.apply("Vastaanottaja" + suffix), "vastaanottaja" + suffix + "@example.com")),
Seq.empty,
Option.apply("testipalvelu"),
Option.empty,
Option.apply(Prioriteetti.NORMAALI),
Option.apply(365),
Set(SecurityConstants.SECURITY_ROOLI_KATSELU_FULL),
Map("avain" -> Seq("arvo")),
"omistaja")
}

}

class LocalUtil {}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SecurityConfiguration {
@Bean
def serviceProperties(@Value("${cas-service.service}") service: String, @Value("${cas-service.sendRenew}") sendRenew: Boolean): ServiceProperties = {
val serviceProperties = new ServiceProperties()
serviceProperties.setService(service + RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/j_spring_cas_security_check")
serviceProperties.setService(service + RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/login/j_spring_cas_security_check")
serviceProperties.setSendRenew(sendRenew)
serviceProperties.setAuthenticateAllArtifacts(true)
serviceProperties
Expand Down Expand Up @@ -74,7 +74,7 @@ class SecurityConfiguration {
def casAuthenticationFilter(authenticationManager: AuthenticationManager, serviceProperties: ServiceProperties): CasAuthenticationFilter = {
val casAuthenticationFilter = new OpintopolkuCasAuthenticationFilter(serviceProperties)
casAuthenticationFilter.setAuthenticationManager(authenticationManager)
casAuthenticationFilter.setFilterProcessesUrl(RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/j_spring_cas_security_check")
casAuthenticationFilter.setFilterProcessesUrl(RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/login/j_spring_cas_security_check")
casAuthenticationFilter
}

Expand Down
Loading

0 comments on commit 4e5cf95

Please sign in to comment.