/**
 * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 *
 * This software is the property of WSO2 Inc. and its suppliers, if any.
 * Dissemination of any information or reproduction of any material contained
 * herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 * You may not alter or remove any copyright or other notice from copies of this content."
 */

export const tomcatSAMLAgentMavenDependencyCode = () => {

    return `<dependency>
    <groupId>io.asgardeo.tomcat.saml.agent</groupId>
    <artifactId>io.asgardeo.tomcat.saml.agent</artifactId>
    <version>0.1.21</version>
</dependency>`;
};

export const wso2InternalRepoPointingCode = () => {

    return `<repositories>
    <repository>
        <id>wso2.releases</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </repository>
</repositories>`;
};

export const tomcatSAMLAgentSamplePropertiesCode = (config: any) => {

    if (!config) {
        return null;
    }

    return `#Enable SAML Single Sign On Login
EnableSAML2SSOLogin=true

#Url to do send SAML2 SSO AuthnRequest
SAML2SSOURL=samlsso

#URIs to skip SSOAgentFilter; comma separated values
SkipURIs=

IndexPage=/sample-app/index.html

#A unique identifier for this SAML 2.0 Service Provider application
SAML2.SPEntityId=sample-app

#The URL of the SAML 2.0 Assertion Consumer
SAML2.AssertionConsumerURL=http://localhost.com:8080/sample-app/home.jsp

#A unique identifier for this SAML 2.0 Service Provider application
SAML2.IdPEntityId=localhost

#The URL of the SAML 2.0 Identity Provider
SAML2.IdPURL=${ config.serverOrigin }/samlsso

#Specify if SingleLogout is enabled/disabled
SAML2.EnableSLO=true

#This is the URL that is used for SLO
SAML2.SLOURL=logout

#Specify if SAMLResponse element is signed
SAML2.EnableResponseSigning=true

#Specify if SAMLAssertion element is signed
SAML2.EnableAssertionSigning=true

#Specify if SAMLAssertion element is encrypted
SAML2.EnableAssertionEncryption=false

#Specify if AuthnRequests and LogoutRequests should be signed
SAML2.EnableRequestSigning=true

#Specify if SAML request is a passive
SAML2.IsPassiveAuthn=false

#Password of the KeyStore
KeyStorePassword=wso2carbon

#Alias of the IdP's public certificate
IdPPublicCertAlias=wso2carbon

#Alias of the SP's private key 
PrivateKeyAlias=wso2carbon

#Private key password to retrieve the private key used to sign 
#AuthnRequest and LogoutRequest messages
PrivateKeyPassword=wso2carbon`;
};

export const tomcatSAMLAgentSampleWebXMLCode = () => {

    return `<?xml version="1.0" encoding="UTF-8"?>
<web-app id="io.asgardeo.tomcat.saml.agent.sample"
        version="2.5"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>io.asgardeo.tomcat.saml.agent.sample</display-name>
    <filter>
        <filter-name>SAML2SSOAgentFilter</filter-name>
        <filter-class>io.asgardeo.tomcat.saml.agent.SAML2SSOAgentFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>SAML2SSOAgentFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SAML2SSOAgentFilter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SAML2SSOAgentFilter</filter-name>
        <url-pattern>/samlsso</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SAML2SSOAgentFilter</filter-name>
        <url-pattern>/logout</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>io.asgardeo.tomcat.saml.agent.SSOAgentContextEventListener</listener-class>
    </listener>
    <context-param>
        <param-name>property-file</param-name>
        <param-value>sample-app.properties</param-value>
    </context-param>
    <context-param>
        <param-name>certificate-file</param-name>
        <param-value>wso2carbon.jks</param-value>
    </context-param>
</web-app>
`;
};

export const tomcatSAMLAgentLoginButtonCode = () => {

    return `<form action="home.jsp" method="post">
      <div class="element-padding">
          <input style="height: 30px; width: 60px" type="submit" value="log in">
      </div>
  </form>`;
};

export const tomcatSAMLAgentLoginButtonAuthRequestCode = () => {

    return `<form action="samlsso?SAML2.HTTPBinding=HTTP-POST" method="post">
      <div class="element-padding">
          <input style="height: 30px; width: 60px" type="submit" value="log in">
      </div>
  </form>`;
};

export const tomcatSAMLAgentLogoutCode = () => {

    return `<a href="logout?SAML2.HTTPBinding=HTTP-POST">Logout</a>`;
};

export const tomcatSAMLAgentDockerEnvCode = (config: any) => {

    return `SAML2_SP_ENTITY_ID=${ config.samlIssuer }
IDP_PUBLIC_CERT=${ config.certificate?.replace(/\n/g, "\\\n")}
SAML2_IDP_URL=${ config.ssoUrl }
SAML2_IDP_ENTITY_ID=${ config.issuer }
SAML2_ENABLE_ASSERTION_SIGNING=false`;
};

export const tomcatSAMLAgentDockerRunCode = () => {
    return "docker container run --rm --name tomcat-saml-agent-sample -itdp 8080:8080 asgardeo/" +
        "tomcat-saml-agent-sample";
};
