├── .circleci ├── config.yml └── marist.env ├── .codecov.yml ├── .editorconfig ├── .github └── workflows │ └── greetings.yml ├── .gitignore ├── .licence └── Apache-or-EPL-License-Header.txt ├── LICENSE ├── README.md ├── build.gradle ├── coverity └── scan.groovy ├── dco_signoffs └── Dan Kelosky-sample-spring-boot-api-service.txt ├── docs ├── building.md ├── releasing.md └── zos-native-code.md ├── gradle.properties ├── gradle ├── bootstrap │ ├── bootstrap-gradlew.bat │ └── bootstrap-gradlew.sh ├── generate-pom.gradle ├── sonar.gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jarpatcher ├── .gitignore ├── build.gradle ├── gradle.properties ├── lombok.config ├── settings.gradle └── src │ ├── main │ └── java │ │ └── jarpatcher │ │ └── JarPatcher.java │ └── test │ └── java │ └── jarpatcher │ ├── ArchiveDefinition.java │ ├── JarPatcherTests.java │ └── TestFile.java ├── package.json ├── scripts ├── build-sample.sh ├── coverity-scan.sh ├── lock-port.sh ├── package-sample.sh ├── publish-sample.sh ├── run-integration-tests-kotlin-zos.sh ├── run-integration-tests-kotlin.sh ├── run-integration-tests-zos.sh ├── run-integration-tests.sh ├── so-test.sh ├── unlock-port.sh ├── zos-cleanup.sh └── zosbuild.sh ├── settings.gradle ├── zowe-api-dev ├── .gitignore ├── README.md ├── bin │ ├── run │ └── run.cmd ├── package-lock.json ├── package.json ├── scripts │ └── updateLicense.js ├── src │ ├── commands │ │ ├── config.ts │ │ ├── deploy.ts │ │ ├── init.ts │ │ ├── start.ts │ │ ├── status.ts │ │ ├── stop.ts │ │ ├── zfs.ts │ │ └── zosbuild.ts │ ├── config.ts │ ├── files.ts │ ├── index.ts │ ├── jes.ts │ └── zowe.ts ├── test │ ├── commands │ │ └── hello.test.ts │ ├── mocha.opts │ └── tsconfig.json ├── tsconfig.json └── tslint.json ├── zowe-api.json ├── zowe-rest-api-commons-spring ├── .gitignore ├── README.md ├── build.gradle ├── docs │ └── zos-native-code.md ├── gradle.properties ├── gradle │ └── publishing.gradle ├── lombok.config ├── package-lock.json ├── src │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── zowe │ │ │ │ └── commons │ │ │ │ ├── AccentStrippingPatternLayerEncoder.java │ │ │ │ ├── UseridFilter.java │ │ │ │ ├── apidoc │ │ │ │ ├── ApiDocConstants.java │ │ │ │ ├── BasePathProvider.java │ │ │ │ └── BasePathTransformationFilter.java │ │ │ │ ├── apiml │ │ │ │ ├── ApiMediationServiceConfigBean.java │ │ │ │ ├── ApimlIntegrationFailureDetector.java │ │ │ │ ├── CatalogUiTile.java │ │ │ │ ├── RegisterToApiLayer.java │ │ │ │ └── SslConfigBean.java │ │ │ │ ├── error │ │ │ │ ├── CommonsErrorService.java │ │ │ │ ├── DuplicateMessageException.java │ │ │ │ ├── ErrorMessage.java │ │ │ │ ├── ErrorMessageStorage.java │ │ │ │ ├── ErrorMessages.java │ │ │ │ ├── ErrorService.java │ │ │ │ ├── ErrorServiceImpl.java │ │ │ │ └── MessageLoadException.java │ │ │ │ ├── rest │ │ │ │ └── response │ │ │ │ │ ├── ApiMessage.java │ │ │ │ │ ├── BasicApiMessage.java │ │ │ │ │ ├── BasicMessage.java │ │ │ │ │ ├── Message.java │ │ │ │ │ └── MessageType.java │ │ │ │ ├── spring │ │ │ │ ├── CustomRestExceptionHandler.java │ │ │ │ ├── DefaultMessageSource.java │ │ │ │ ├── EnableEurekaLoggingTimerTask.java │ │ │ │ ├── RestAuthenticationEntryPoint.java │ │ │ │ ├── ServiceStartupEventHandler.java │ │ │ │ ├── SpringContext.java │ │ │ │ ├── WebConfig.java │ │ │ │ └── security │ │ │ │ │ ├── CsrfController.java │ │ │ │ │ ├── HttpsWebServerConfig.java │ │ │ │ │ ├── MethodSecurityConfig.java │ │ │ │ │ ├── SafMethodSecurityExpressionHandler.java │ │ │ │ │ ├── SafMethodSecurityExpressionRoot.java │ │ │ │ │ └── SafSecurityConfigurationProperties.java │ │ │ │ └── zos │ │ │ │ ├── CommonsNativeLibraries.java │ │ │ │ ├── LibExtractor.java │ │ │ │ ├── LibLoader.java │ │ │ │ ├── NativeLibraries.java │ │ │ │ ├── ZosUtils.java │ │ │ │ └── security │ │ │ │ ├── authentication │ │ │ │ ├── ZosAuthenticationException.java │ │ │ │ └── ZosAuthenticationProvider.java │ │ │ │ ├── jni │ │ │ │ └── Secur.java │ │ │ │ ├── platform │ │ │ │ ├── MockPlatformAccessControl.java │ │ │ │ ├── MockPlatformUser.java │ │ │ │ ├── PlatformAccessControl.java │ │ │ │ ├── PlatformAckErrno.java │ │ │ │ ├── PlatformClassFactory.java │ │ │ │ ├── PlatformErrno2.java │ │ │ │ ├── PlatformErrorType.java │ │ │ │ ├── PlatformPwdErrno.java │ │ │ │ ├── PlatformReturned.java │ │ │ │ ├── PlatformThread.java │ │ │ │ ├── PlatformTlsErrno.java │ │ │ │ ├── PlatformUser.java │ │ │ │ ├── SafConstants.java │ │ │ │ ├── SafPlatformAccessControl.java │ │ │ │ ├── SafPlatformClassFactory.java │ │ │ │ ├── SafPlatformError.java │ │ │ │ ├── SafPlatformThread.java │ │ │ │ ├── SafPlatformUser.java │ │ │ │ └── SafUtils.java │ │ │ │ ├── service │ │ │ │ ├── AccessControlError.java │ │ │ │ ├── AccessControlService.java │ │ │ │ ├── DummyPlatformSecurityService.java │ │ │ │ ├── PlatformSecurityService.java │ │ │ │ ├── SecurityRequestFailed.java │ │ │ │ └── ZosJniPlatformSecurityService.java │ │ │ │ └── thread │ │ │ │ ├── CallInThreadLevelSecurityEnvironmentByDaemon.java │ │ │ │ ├── PlatformThreadLevelSecurity.java │ │ │ │ ├── PlatformThreadLevelSecurityByDaemon.java │ │ │ │ └── RunInThreadLevelSecurityEnvironmentByDaemon.java │ │ └── resources │ │ │ ├── META-INF │ │ │ └── additional-spring-configuration-metadata.json │ │ │ ├── commons-messages.yml │ │ │ ├── commons-messages_cs.properties │ │ │ └── lib │ │ │ └── README.md │ └── test │ │ ├── java │ │ └── org │ │ │ └── zowe │ │ │ └── commons │ │ │ ├── AccentStrippingPatternLayerEncoderTests.java │ │ │ ├── apidoc │ │ │ └── BasePathTransformationFilterTest.java │ │ │ ├── apiml │ │ │ ├── ApimlIntegrationFailureDetectorTests.java │ │ │ └── RegisterToApiLayerTests.java │ │ │ ├── error │ │ │ ├── CommonsErrorServiceTests.java │ │ │ ├── ErrorMessageStorageTest.java │ │ │ └── ErrorServiceImplTest.java │ │ │ ├── rest │ │ │ └── response │ │ │ │ ├── BasicApiMessageTest.java │ │ │ │ └── BasicMessageTest.java │ │ │ ├── spring │ │ │ ├── CustomRestExceptionHandlerTests.java │ │ │ ├── DefaultMessageSourceTests.java │ │ │ ├── EnableEurekaLoggingTimerTaskTests.java │ │ │ ├── RestAuthenticationEntryPointTests.java │ │ │ ├── SpringContextTests.java │ │ │ └── security │ │ │ │ └── HttpsWebServerConfigTests.java │ │ │ └── zos │ │ │ └── security │ │ │ ├── authentication │ │ │ └── ZosAuthenticationProviderTests.java │ │ │ ├── platform │ │ │ ├── BadMockPlatformClassFactory.java │ │ │ ├── MockPlatformClassFactory.java │ │ │ ├── PlatformErnnoTests.java │ │ │ ├── SafPlatformAccessControlTests.java │ │ │ └── SafPlatformUserTests.java │ │ │ ├── service │ │ │ └── DummyPlatformSecurityServiceTest.java │ │ │ └── thread │ │ │ └── PlatformThreadLevelSecurityByDaemonTest.java │ │ └── resources │ │ ├── test-duplicate-messages.yml │ │ ├── test-messages.yml │ │ ├── test-messages_cs.properties │ │ ├── test-saf-invalid.yml │ │ └── test-saf.yml ├── zossrc │ ├── jnitools.c │ ├── jnitools.h │ ├── makefile │ ├── secur.c │ └── secur.h └── zowe-api.json ├── zowe-rest-api-sample-kotlin-spring ├── .gitignore ├── .licence │ └── Apache-or-EPL-License-Header.txt ├── README.md ├── build.gradle.kts ├── config │ ├── local │ │ ├── keystore.p12 │ │ ├── local.yml │ │ └── truststore.p12 │ └── zos │ │ └── zos.yml.hbs ├── gradle.properties ├── gradle │ ├── bootstrap │ │ ├── bootstrap-gradlew.bat │ │ └── bootstrap-gradlew.sh │ └── wrapper │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts ├── src │ ├── integrationTest │ │ └── kotlin │ │ │ └── org │ │ │ └── zowe │ │ │ └── sample │ │ │ └── kotlin │ │ │ └── apiservice │ │ │ ├── greeting │ │ │ └── GreetingControllerIntegrationTests.kt │ │ │ └── test │ │ │ ├── IntegrationTest.kt │ │ │ └── ServiceUnderTest.kt │ ├── main │ │ ├── jcl │ │ │ └── template.jcl │ │ ├── kotlin │ │ │ └── org │ │ │ │ └── zowe │ │ │ │ └── sample │ │ │ │ └── kotlin │ │ │ │ └── apiservice │ │ │ │ ├── ZoweKotlinApiServiceApplication.kt │ │ │ │ ├── config │ │ │ │ ├── ApplicationConfig.kt │ │ │ │ └── WebSecurityConfig.kt │ │ │ │ └── greeting │ │ │ │ ├── Greeting.kt │ │ │ │ └── GreetingController.kt │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── messages.properties │ │ │ ├── messages_cs.properties │ │ │ ├── messages_en.properties │ │ │ └── messages_es.properties │ └── test │ │ └── kotlin │ │ └── org │ │ └── zowe │ │ └── sample │ │ └── kotlin │ │ └── apiservice │ │ └── greeting │ │ └── GreetingControllerTest.kt └── zowe-api.json └── zowe-rest-api-sample-spring ├── .editorconfig ├── .gitignore ├── .licence └── Apache-or-EPL-License-Header.txt ├── README.md ├── build.gradle ├── config ├── local │ ├── application.yml │ ├── keystore.p12 │ └── truststore.p12 └── zos │ └── application.yml.hbs ├── docs ├── adding-new-controller.md ├── api-client-authentication.md ├── building-new-apis.md ├── changing-service-configuration.md ├── config.md ├── devtool.md ├── error-handling.md ├── https-setup.md ├── i18n.md ├── images │ ├── greeting-api.png │ ├── hello-endpoint-swaggerui.png │ ├── java-started-service.png │ ├── landing-page.png │ ├── sign-in.png │ ├── swagger.png │ └── vscode-yaml-help.png ├── java-debugging.md ├── logging.md ├── testing.md ├── versioning.md ├── web-security.md ├── zos-deployment.md ├── zos-native-os-linkage.md ├── zos-security.md └── zowe-integrate-with-apiml.md ├── gradle.properties ├── gradle ├── bootstrap │ ├── bootstrap-gradlew.bat │ └── bootstrap-gradlew.sh └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lombok.config ├── settings.gradle ├── src ├── integrationTest │ └── java │ │ └── org │ │ └── zowe │ │ └── sample │ │ └── apiservice │ │ ├── greeting │ │ └── GreetingControllerIntegrationTests.java │ │ ├── security │ │ └── SecurityContextControllerIntegrationTests.java │ │ ├── test │ │ ├── IntegrationTests.java │ │ └── ServiceUnderTest.java │ │ └── wto │ │ └── WtoControllerIntegrationTests.java ├── main │ ├── java │ │ └── org │ │ │ └── zowe │ │ │ └── sample │ │ │ └── apiservice │ │ │ ├── AppNativeLibraries.java │ │ │ ├── LibsExtractor.java │ │ │ ├── ZoweApiServiceApplication.java │ │ │ ├── apidoc │ │ │ └── SwaggerConfig.java │ │ │ ├── config │ │ │ ├── ApplicationConfig.java │ │ │ └── WebSecurityConfig.java │ │ │ ├── greeting │ │ │ ├── EmptyNameError.java │ │ │ ├── Greeting.java │ │ │ ├── GreetingController.java │ │ │ ├── GreetingControllerExceptionHandler.java │ │ │ └── GreetingSettings.java │ │ │ ├── security │ │ │ └── SecurityContextController.java │ │ │ └── wto │ │ │ ├── OffZosWto.java │ │ │ ├── Wto.java │ │ │ ├── WtoController.java │ │ │ ├── WtoResponse.java │ │ │ └── ZosWto.java │ ├── jcl │ │ └── template.jcl │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ ├── application.yml │ │ ├── lib │ │ └── README.md │ │ ├── logback-spring.xml │ │ ├── messages.properties │ │ ├── messages.yml │ │ ├── messages_cs.properties │ │ ├── messages_es.properties │ │ └── test-saf.yml └── test │ └── java │ └── org │ └── zowe │ └── sample │ └── apiservice │ ├── TestUtils.java │ ├── ZoweApiServiceApplicationTests.java │ ├── greeting │ └── GreetingControllerTests.java │ ├── security │ └── SecurityContextControllerTests.java │ └── wto │ └── WtoControllerTests.java ├── zossrc ├── makefile ├── wto.h ├── wtoexec.c ├── wtoexec.h ├── wtojni.cpp └── wtojni.h └── zowe-api.json /.circleci/marist.env: -------------------------------------------------------------------------------- 1 | export ZOWE_CLI_PROFILE_NAME="marist" 2 | export TEST_PROFILE="zos" 3 | export ZOS_HOST="zzow01.zowe.marist.cloud" 4 | export ZOS_ZOSMF_PORT="10443" 5 | export ZOS_SSH_PORT="22" 6 | export ZOS_ACCOUNT_NUMBER="1" 7 | export ZOS_TARGET_DIR="/zaas1/sdkbld1/sdk" 8 | export ZOS_HLQ="ZOWEP.APISDK" 9 | export ZOS_ZFSADM_PARAM="-volume ZOWE02" 10 | export ZOS_JAVA_HOME="/usr/lpp/java/J8.0_64" 11 | export ZOS_JAVA_LOADLIB="JVB800.SIEALNKE" 12 | export TEST_PORT=10181 13 | export TEST_WAIT_MINUTES=10 14 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | range: 50..100 3 | status: 4 | patch: 5 | default: 6 | target: 70 7 | project: 8 | default: 9 | target: 70 10 | 11 | ignore: 12 | - "**/PlatformErrno2.java" 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | max_line_length = 120 11 | 12 | [*.md] 13 | max_line_length = off 14 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: 'Thank you for opening your first issue!' 13 | pr-message: 'Thank you for opening your first pull request!' 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | /bin/ 4 | gradle/wrapper/gradle-wrapper.jar 5 | .DS_Store 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /out/ 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | 33 | deploy/scripts/out 34 | deploy/templates/jcl/out 35 | deploy/config/local.ts 36 | node_modules 37 | *.so 38 | user-zowe-api.json 39 | lastJob.json 40 | zowe-api-dev/zowedev-zowe-api-dev-*.tgz 41 | zowe-rest-api-sample-spring/build.gradle-orig 42 | zowe-rest-api-commons-spring/.version 43 | /package-lock.json 44 | key.tar 45 | .key 46 | .lock-session 47 | unlock.out 48 | zowe-rest-api-sample-spring/config/ca*/ 49 | /*.jar 50 | zowe-rest-api-sample-spring/*.zip 51 | .zowe-api-dev/ 52 | cov-int/ 53 | zowe-rest-api-sample-kotlin-spring/bin/ 54 | cov-int.tgz 55 | -------------------------------------------------------------------------------- /.licence/Apache-or-EPL-License-Header.txt: -------------------------------------------------------------------------------- 1 | This program and the accompanying materials are made available and may be used, at your option, under either: 2 | * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 3 | * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 6 | 7 | Copyright Contributors to the Zowe Project. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Zowe](https://zowe.org/) REST API SDK and Sample Service · [![CircleCI](https://circleci.com/gh/zowe/sample-spring-boot-api-service.svg?style=shield)](https://circleci.com/gh/zowe/sample-spring-boot-api-service) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=zowe_sample-spring-boot-api-service&metric=alert_status)](https://sonarcloud.io/dashboard?id=zowe_sample-spring-boot-api-service) [ ![download](https://api.bintray.com/packages/plavjanik/zowe/zowe-rest-api-commons-spring/images/download.svg?version=1.1.0) ](https://bintray.com/plavjanik/zowe/zowe-rest-api-commons-spring/1.1.0/link)Coverity Scan Build Status 2 | 3 | This project provides: 4 | 5 | 1. [Sample REST API service](zowe-rest-api-sample-spring/README.md) that run on z/OS and can use native z/OS interfaces 6 | 2. SDK (software development kit) for creating such services that includes: 7 | - [Common Java library for REST APIs on z/OS](zowe-rest-api-commons-spring/README.md) that includes the reusable functionality for developing such API services on z/OS 8 | - [CLI tool zowe-api-dev](zowe-api-dev/README.md) that will allow use to develop your API service on PC and deploy it to z/OS UNIX environment 9 | 10 | ## Getting Started 11 | 12 | ### Developing New REST API Service 13 | 14 | Follow the instructions at [Zowe Sample API Service](zowe-rest-api-sample-spring/README.md). 15 | 16 | ## Demo 17 | 18 | ### Deploying the sample REST API to z/OS under 5 minutes 19 | 20 | [![asciicast](https://asciinema.org/a/266002.svg)](https://asciinema.org/a/266002) 21 | 22 | ## Documentation for SDK Developers 23 | 24 | - [Building SDK](docs/building.md) 25 | - [Building z/OS native code](docs/zos-native-code.md) 26 | - [Releasing](docs/releasing.md) 27 | 28 | ## License 29 | 30 | The repository is dual-licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) and [Eclipse Public License - v 2.0](https://www.eclipse.org/legal/epl-2.0/). 31 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | jcenter() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0' 10 | } 11 | } 12 | 13 | apply from: 'gradle/sonar.gradle' 14 | apply from: 'gradle/generate-pom.gradle' 15 | 16 | allprojects { 17 | ext.getLastGitTag = { -> 18 | try { 19 | def stdout = new ByteArrayOutputStream() 20 | exec { 21 | commandLine 'git', 'describe', '--abbrev=0', '--tags' 22 | standardOutput = stdout 23 | } 24 | return stdout.toString().trim() 25 | } catch (ignored) { 26 | return null 27 | } 28 | } 29 | 30 | ext.getLastGitTagWithNewCommit = { -> 31 | try { 32 | def stdout = new ByteArrayOutputStream() 33 | exec { 34 | commandLine 'git', 'describe', '--tags' 35 | standardOutput = stdout 36 | } 37 | return stdout.toString().trim() 38 | } catch (ignored) { 39 | return null 40 | } 41 | } 42 | 43 | ext.getVersionFromGitTag = { -> 44 | def pattern = ~/^v(\d{1,3})\.(\d{1,3})\.\d{1,4}$/ 45 | def lastTag = getLastGitTag() ?: 'v0.0.0' 46 | if ((lastTag != null) && lastTag.matches(pattern) && (lastTag == getLastGitTagWithNewCommit())) { 47 | return lastTag.substring(1) 48 | } 49 | else { 50 | // See docs/releasing.md 51 | return "0.0.0-SNAPSHOT" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /coverity/scan.groovy: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | docker { 4 | image 'plavjanik/coverity-oss' 5 | label 'docker' 6 | args '-v "$HOME"/.gradle:/root/.gradle' 7 | } 8 | } 9 | 10 | options { 11 | buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5')) 12 | } 13 | 14 | triggers { 15 | cron('H 23 * * *') 16 | } 17 | 18 | stages { 19 | stage('Coverity Scan') { 20 | steps { 21 | withCredentials([ 22 | usernamePassword( 23 | credentialsId: 'coverityScanZoweSampleSpringBootApiService', 24 | usernameVariable: 'COVERITY_EMAIL', 25 | passwordVariable: 'COVERITY_TOKEN')]) { 26 | sh 'scripts/coverity-scan.sh' 27 | } 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dco_signoffs/Dan Kelosky-sample-spring-boot-api-service.txt: -------------------------------------------------------------------------------- 1 | I, Dan Kelosky hereby sign-off-by all of my past commits to this repo subject to the Developer Certificate of Origin (DCO), Version 1.1. In the past I have used emails: dkelosky@gmail.com 2 | ef3dcd61bd3c4f152aaf42e29d35934cfa84ef88 Merge deploy instructions (#25) 3 | -------------------------------------------------------------------------------- /docs/building.md: -------------------------------------------------------------------------------- 1 | # Building SDK 2 | 3 | This page provides instruction how to build subprojects of the SDK. This is intended for SDK developers. If you need to build a new API service, follow instructions at [zowe-rest-api-sample-spring/README.md](../zowe-rest-api-sample-spring/README.md). 4 | 5 | ## Java code 6 | 7 | ### All Projects 8 | 9 | In the repository root directory: 10 | 11 | ```bash 12 | ./gradlew build 13 | ``` 14 | 15 | This builds both `zowe-rest-api-commons-spring` and `zowe-rest-api-sample-spring`. `zowe-rest-api-sample-spring` includes `zowe-rest-api-commons-spring` as a Gradle subproject. 16 | 17 | ### Individually 18 | 19 | ```bash 20 | cd zowe-rest-api-commons-spring 21 | ./gradlew publishToMavenLocal 22 | ``` 23 | 24 | This places the artifacts of `zowe-rest-api-commons-spring` library to local Maven repository 25 | with a hardcoded version `0.0.0-SNAPSHOT` that will be used by the sample project. 26 | 27 | ```bash 28 | cd ../zowe-rest-api-sample-spring 29 | ./gradlew build 30 | ``` 31 | 32 | ## CLI Tool 33 | 34 | See [zowe-api-dev/README.md](zowe-api-dev/README.md). 35 | 36 | ## z/OS Native Code 37 | 38 | - [Building z/OS native code](docs/zos-native-code.md) 39 | -------------------------------------------------------------------------------- /docs/releasing.md: -------------------------------------------------------------------------------- 1 | # Releasing 2 | 3 | Releasing of the new version of SDK and sample is simple: 4 | 5 | 1. Create new release with a tag in format `vm.n.p` (e.g. `v1.2.3`) - e.g. using 6 | 7 | The [CircleCI build](https://circleci.com/gh/zowe/sample-spring-boot-api-service) publishes new versions of the commons library, `zowe-api-dev` tool, and creates new version of [the ZIP file with the sample](https://github.com/zowe/sample-spring-boot-api-service/releases/latest/download/zowe-rest-api-sample-spring.zip). 8 | 9 | There is no need to change versions in the source code. 10 | 11 | When you build all subprojects using `./gradlew build` in the repository root then the sample is using the commons library subproject. When you build the sample by `./gradlew build` in subdirectory `zowe-rest-api-sample-spring` it uses version `0.0.0-SNAPSHOT` that is expected to be at local Maven repository where it can be published by `./gradlew :zowe-rest-api-commons-spring:publishToMavenLocal`. During the CircleCI build the `0.0.0-SNAPSHOT` is replaced by the version taken from the tag. 12 | -------------------------------------------------------------------------------- /docs/zos-native-code.md: -------------------------------------------------------------------------------- 1 | # Building z/OS Native Code 2 | 3 | Both subprojects provide documentation on how to build the z/OS native code: 4 | 5 | - [zowe-rest-api-sample-spring](/zowe-rest-api-sample-spring/docs/zos-native-os-linkage.md) 6 | - [zowe-rest-api-commons-spring](/zowe-rest-api-commons-spring/docs/zos-native-code.md) 7 | 8 | ## Building in CircleCI 9 | 10 | Native code is built on `zzow01.zowe.marist.cloud`. 11 | The definition of the steps in CircleCI is labeled `&zosbuild` in [`.circleci/config.yml`](/.circleci/config.yml) 12 | It calls `npm run zosbuild` that invokes [`scripts/zosbuild.sh`](.scripts/zosbuild.sh). `npm run` is used to initialize the NPM environment with Zowe CLI and zowe-api-dev modules. [`scripts/zosbuild.sh`](.scripts/zosbuild.sh) does following: 13 | 14 | - Try to invoke Gradle tasks `zosbuild` for all subprojects. If it succeeds, it means that the build has been cached, if not scripts needs to continue 15 | - Initialize Zowe profiles 16 | - Initialize zFS filesystem for all Zowe builds if necessary (its size is defined in [zowe-api.json](/zowe-api.json)) 17 | - Execute z/OS builds for subprojects 18 | - Delete build work files 19 | 20 | ### Required Environment Variables 21 | 22 | Everything except credentials (`ZOS_USERID`, `ZOS_PASSWORD`, `TEST_USERID`, `TEST_PASSWORD`) is stored in [`.circleci/marist.env`](/.circleci/marist.env). 23 | This file is read by `zosbuild` step in [`.circleci/config.yml`](/.circleci/config.yml). 24 | Credentials are set in . 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | org.gradle.jvmargs=-Duser.country=US -Duser.language=en -Dfile.encoding=UTF-8 3 | 4 | # Repository URL for getting Zowe artifacts: 5 | zoweArtifactoryRepository=https://gizaartifactory.jfrog.io/gizaartifactory/libs-release 6 | 7 | # Artifactory credentials to read Zowe artifacts: 8 | zoweArtifactoryUser=apilayer-build 9 | zoweArtifactoryPassword=lHj7sjJmAxL5k7obuf80Of+tCLQYZPMVpDob5oJG1NI= 10 | -------------------------------------------------------------------------------- /gradle/bootstrap/bootstrap-gradlew.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist gradle/wrapper/gradle-wrapper.jar ( 4 | echo Gradle wrapper not found. Attempting to download... 5 | powershell -Command "& {wget https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar -OutFile gradle/wrapper/gradle-wrapper.jar}" 6 | IF ERRORLEVEL 1 ( 7 | echo Gradle wrapper download failed. Bootstrap failed. 8 | ) ELSE ( 9 | echo Gradle wrapper download success. Bootstrap complete. 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /gradle/bootstrap/bootstrap-gradlew.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ ! -f gradle/wrapper/gradle-wrapper.jar ]; then 4 | echo "Gradle wrapper not found. Attempting to download..." 5 | curl --silent --output gradle/wrapper/gradle-wrapper.jar \ 6 | https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar 7 | rc=$?; 8 | if [ $rc != 0 ]; then 9 | echo "Gradle wrapper download failed. Bootstrap failed." 10 | exit 1 11 | else 12 | echo "Gradle wrapper download success. Bootstrap complete." 13 | exit 0 14 | fi 15 | else 16 | exit 0 17 | fi 18 | -------------------------------------------------------------------------------- /gradle/generate-pom.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | apply plugin: 'java' 3 | apply plugin: 'maven' 4 | 5 | task generatePom { 6 | doLast { 7 | pom { 8 | 9 | }.writeTo("$buildDir/pom.xml") 10 | } 11 | } 12 | 13 | build.dependsOn generatePom 14 | } 15 | -------------------------------------------------------------------------------- /gradle/sonar.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "org.sonarqube" 2 | 3 | ext.pullRequest = System.getenv()['CHANGE_ID'] ?: null 4 | 5 | def gitBranch() { 6 | def branch = "" 7 | def proc = "git rev-parse --abbrev-ref HEAD".execute() 8 | proc.in.eachLine { line -> branch = line } 9 | proc.err.eachLine { line -> println line } 10 | proc.waitFor() 11 | branch 12 | } 13 | 14 | sonarqube { 15 | properties { 16 | property "sonar.host.url", project.getProperty('sonar.host.url') 17 | property "sonar.login", project.hasProperty('sonar.login') ? project.getProperty('sonar.login') : null 18 | property "sonar.sourceEncoding", "UTF-8" 19 | property "sonar.organization", "zowe" 20 | property "sonar.projectKey", "zowe_sample-spring-boot-api-service" 21 | property "sonar.projectName", "Zowe REST API SDK and Sample Service" 22 | property "sonar.projectVersion", project.version 23 | property "sonar.language", "java" 24 | property "sonar.links.scm", "https://github.com/zowe/sample-spring-boot-api-service" 25 | property "sonar.links.ci", System.getenv()['BUILD_URL'] ?: null 26 | if (pullRequest != null) { 27 | property "sonar.pullrequest.key", System.getenv()['CHANGE_ID'] ?: null 28 | property "sonar.pullrequest.branch", System.getenv()['CHANGE_BRANCH'] ?: null 29 | property "sonar.pullrequest.base", System.getenv()['CHANGE_TARGET'] ?: null 30 | property "sonar.github.pullRequest", pullRequest 31 | property "sonar.github.repository", "zowe/sample-spring-boot-api-service" 32 | property "sonar.github.oauth", project.hasProperty('sonar.github.oauth') ? project.getProperty('sonar.github.oauth') : null 33 | } else { 34 | property "sonar.branch.name", System.getenv()['BRANCH_NAME'] ?: gitBranch() 35 | } 36 | } 37 | } 38 | 39 | subprojects { 40 | sonarqube { 41 | properties { 42 | property "sonar.sources", "src/main/java" 43 | property "sonar.tests", "src/test/java" 44 | } 45 | } 46 | } 47 | 48 | project(":zowe-rest-api-sample-kotlin-spring") { 49 | sonarqube { 50 | properties { 51 | property "sonar.sources", "src/main/kotlin" 52 | property "sonar.tests", "src/test/kotlin" 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /jarpatcher/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | gradle/wrapper/gradle-wrapper.jar 4 | 5 | # Ignore Gradle build output directory 6 | build 7 | bin 8 | -------------------------------------------------------------------------------- /jarpatcher/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | id 'jacoco' 5 | id 'com.github.hierynomus.license' version '0.15.0' 6 | } 7 | 8 | java.sourceCompatibility = JavaVersion.VERSION_1_8 9 | java.targetCompatibility = JavaVersion.VERSION_1_8 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.projectlombok:lombok:1.18.12' 17 | annotationProcessor 'org.projectlombok:lombok:1.18.12' 18 | testImplementation 'junit:junit:4.13' 19 | testImplementation 'commons-io:commons-io:2.7' 20 | testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' 21 | } 22 | 23 | application { 24 | mainClassName = 'jarpatcher.JarPatcher' 25 | } 26 | 27 | jacoco { 28 | toolVersion = '0.8.5' 29 | } 30 | 31 | jacocoTestReport { 32 | reports { 33 | xml.enabled true 34 | html.enabled true 35 | } 36 | doLast { 37 | println "JaCoCo Test report written to: ${jacocoTestReport.reports.html.destination}/index.html" 38 | } 39 | } 40 | 41 | jacocoTestReport.dependsOn test 42 | 43 | check.dependsOn jacocoTestReport 44 | 45 | license { 46 | header rootProject.file('.licence/Apache-or-EPL-License-Header.txt') 47 | ext.year = Calendar.getInstance().get(Calendar.YEAR) 48 | excludes(["**/*.yml", "**/*.json", "**/*.sh", "**/*.txt", "**/*.p12", "**/*.xml", "**/*.jsp", "**/*.html", "**/*.jks", "**/*.so", "**/*.md"]) 49 | mapping { 50 | java = 'SLASHSTAR_STYLE' 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jarpatcher/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | -------------------------------------------------------------------------------- /jarpatcher/lombok.config: -------------------------------------------------------------------------------- 1 | lombok.addLombokGeneratedAnnotation = true 2 | -------------------------------------------------------------------------------- /jarpatcher/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/5.6.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'jar-patch' 11 | -------------------------------------------------------------------------------- /jarpatcher/src/test/java/jarpatcher/ArchiveDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package jarpatcher; 11 | 12 | import java.util.LinkedHashMap; 13 | import java.util.Map; 14 | 15 | import lombok.Getter; 16 | import lombok.ToString; 17 | 18 | @ToString 19 | public class ArchiveDefinition { 20 | @Getter 21 | private final Map files = new LinkedHashMap<>(); 22 | 23 | public ArchiveDefinition addFiles(TestFile... testFiles) { 24 | for (TestFile file: testFiles) { 25 | files.put(file.getFilename(), file); 26 | } 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jarpatcher/src/test/java/jarpatcher/TestFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package jarpatcher; 11 | 12 | import lombok.AllArgsConstructor; 13 | import lombok.Data; 14 | import lombok.ToString; 15 | 16 | @Data 17 | @AllArgsConstructor 18 | @ToString 19 | public class TestFile { 20 | private String filename; 21 | private String data; 22 | 23 | public TestFile(String filename) { 24 | this(filename, null); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zowedev/sample-spring-boot-api-service", 3 | "version": "0.0.0-dev", 4 | "description": "Internal scripts for building of the Zowe REST API sample service and SDK", 5 | "main": "index.js", 6 | "dependencies": {}, 7 | "devDependencies": { 8 | "@zowe/cli": "6.0.0", 9 | "@zowedev/zowe-api-dev": "file:zowe-api-dev/zowedev-zowe-api-dev-0.0.0-dev.tgz" 10 | }, 11 | "scripts": { 12 | "version": "zowe --version && zowe-api-dev --version", 13 | "zosbuild": "scripts/zosbuild.sh", 14 | "zos-cleanup": "scripts/zos-cleanup.sh", 15 | "zos-integration-tests": "scripts/run-integration-tests-zos.sh", 16 | "zos-kotlin-integration-tests": "scripts/run-integration-tests-kotlin-zos.sh", 17 | "test": "echo \"Error: no test specified\" && exit 1" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/zowe/sample-spring-boot-api-service.git" 22 | }, 23 | "author": "Zowe Contributors", 24 | "license": "EPL-2.0", 25 | "bugs": { 26 | "url": "https://github.com/zowe/sample-spring-boot-api-service/issues" 27 | }, 28 | "homepage": "https://github.com/zowe/sample-spring-boot-api-service#readme" 29 | } 30 | -------------------------------------------------------------------------------- /scripts/build-sample.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ./gradlew :zowe-rest-api-commons-spring:saveVersion :zowe-rest-api-commons-spring:publishToMavenLocal 5 | VERSION=$(cat zowe-rest-api-commons-spring/.version) 6 | RE="org\.zowe:zowe-rest-api-commons-spring:[0-9]\.[0-9]\.[0-9]\(-SNAPSHOT\)\{0,1\}" 7 | 8 | echo VERSION=$VERSION 9 | cd zowe-rest-api-sample-spring 10 | 11 | echo "Previous version:" 12 | grep "$RE" build.gradle 13 | cp build.gradle build.gradle-orig 14 | cat build.gradle-orig | sed "s|$RE|org.zowe:zowe-rest-api-commons-spring:$VERSION|g" > build.gradle 15 | 16 | echo "New version:" 17 | grep "$RE" build.gradle 18 | 19 | echo "" >> gradle.properties 20 | echo "# Version of the sample that has been used" >> gradle.properties 21 | echo "zoweSampleVersion=$VERSION" >> gradle.properties 22 | 23 | ./gradlew build 24 | 25 | rm build.gradle-orig 26 | 27 | cp -v build/libs/zowe-rest-api-sample-spring-*.jar ../build/zowe-rest-api-sample-spring.jar 28 | -------------------------------------------------------------------------------- /scripts/coverity-scan.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | cov-build --fs-capture-search zowe-api-dev/src --dir cov-int ./gradlew --no-build-cache --no-daemon -x checkSharedObject -x test clean build 4 | tar czvf cov-int.tgz cov-int 5 | curl --form token=$COVERITY_TOKEN \ 6 | --form email=$COVERITY_EMAIL \ 7 | --form file=@cov-int.tgz \ 8 | --form version="1.1.0" \ 9 | --form description="Automated Coverity Scan - $GIT_BRANCH ($GIT_COMMIT)" \ 10 | "https://scan.coverity.com/builds?project=zowe%2Fsample-spring-boot-api-service" 11 | -------------------------------------------------------------------------------- /scripts/lock-port.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | DSN="$ZOS_USERID.ZOWE.SDKLOCKS" 5 | DSN_MEMBER="$DSN(P${TEST_PORT})" 6 | 7 | echo "Locking test environment for port $TEST_PORT" 8 | 9 | if ! zowe files ls am $DSN; then 10 | zowe files cre classic $DSN 11 | fi 12 | 13 | URL="https://${ZOS_HOST}:${ZOS_ZOSMF_PORT}/zosmf/restfiles/ds/$DSN_MEMBER" 14 | echo URL=$URL 15 | 16 | DATA="$CIRCLE_PROJECT_USERNAME:$CIRCLE_PROJECT_REPONAME:$CIRCLE_BUILD_NUM" 17 | 18 | REPEAT=1 19 | while [ "$REPEAT" -eq "1" ]; do 20 | curl --include --user $ZOS_USERID:$ZOS_PASSWORD --insecure -X PUT --header 'X-CSRF-ZOSMF-HEADER: true' --header 'Content-Type: text/plain' --header 'Accept: application/json' --header 'X-IBM-Data-Type: text' --header 'X-IBM-Migrated-Recall: wait' --header 'X-IBM-Obtain-ENQ: SHRW' -d $DATA "$URL" > lock.out 21 | if grep 'Enqueue for QNAME=SPFEDIT failed' lock.out; then 22 | echo "Waiting for lock to $DSN_MEMBER to be obtained" 23 | sleep 5 24 | else 25 | REPEAT=0 26 | if ! grep 'HTTP/1.1 20' lock.out; then 27 | cat lock.out 28 | echo "ERROR: Locking of $DSN_MEMBER failed" 29 | exit 1 30 | fi 31 | fi 32 | done 33 | SESSION_REF=$(grep 'X-IBM-Session-Ref:' lock.out | awk '{ print $2 }') 34 | echo $SESSION_REF > .lock-session 35 | echo SESSION_REF=$SESSION_REF 36 | rm -f lock.out 37 | -------------------------------------------------------------------------------- /scripts/package-sample.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ./gradlew clean 5 | rm -rf zowe-rest-api-sample-spring/.gradle 6 | rm -rf zowe-rest-api-sample-spring/bin 7 | rm -rf zowe-rest-api-sample-spring/build 8 | rm -f zowe-rest-api-sample-spring/lastJob.json 9 | rm -f zowe-rest-api-sample-spring/user-zowe-api.json 10 | rm -f zowe-rest-api-sample-spring/build.gradle-orig 11 | mkdir -p build 12 | rm -f build/zowe-rest-api-sample-spring.zip 13 | zip -r build/zowe-rest-api-sample-spring.zip zowe-rest-api-sample-spring 14 | ls -l build/zowe-rest-api-sample-spring.zip 15 | -------------------------------------------------------------------------------- /scripts/publish-sample.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | PLATFORM_OS=${PLATFORM_OS:-"linux"} 5 | PLATFORM_ARCH=${PLATFORM_ARCH:-"amd64"} 6 | TAG=${TAG:-`git describe --tags --abbrev=0`} 7 | cd build 8 | curl -OL https://github.com/aktau/github-release/releases/download/v0.7.2/${PLATFORM_OS}-${PLATFORM_ARCH}-github-release.tar.bz2 9 | tar -xjvf ${PLATFORM_OS}-${PLATFORM_ARCH}-github-release.tar.bz2 10 | bin/${PLATFORM_OS}/${PLATFORM_ARCH}/github-release info -u zowe -r sample-spring-boot-api-service 11 | bin/${PLATFORM_OS}/${PLATFORM_ARCH}/github-release upload -u zowe -r sample-spring-boot-api-service -t ${TAG} -n "zowe-rest-api-sample-spring.zip" -f zowe-rest-api-sample-spring.zip 12 | bin/${PLATFORM_OS}/${PLATFORM_ARCH}/github-release upload -u zowe -r sample-spring-boot-api-service -t ${TAG} -n "zowe-rest-api-sample-spring.jar" -f zowe-rest-api-sample-spring.jar 13 | bin/${PLATFORM_OS}/${PLATFORM_ARCH}/github-release upload -u zowe -r sample-spring-boot-api-service -t ${TAG} -n "zowedev-zowe-api-dev.tgz" -f zowedev-zowe-api-dev.tgz 14 | -------------------------------------------------------------------------------- /scripts/run-integration-tests-kotlin-zos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | scripts/lock-port.sh 5 | 6 | cd zowe-rest-api-sample-kotlin-spring 7 | zowe-api-dev init --zosTargetDir $ZOS_TARGET_DIR/b$CIRCLE_BUILD_NUM/zowe-rest-api-sample-kotlin-spring --zosHlq $ZOS_HLQ.B$CIRCLE_BUILD_NUM.SAMPLE --account $ZOS_ACCOUNT_NUMBER --javaHome=$ZOS_JAVA_HOME --javaLoadlib $ZOS_JAVA_LOADLIB --force 8 | zowe-api-dev deploy 9 | zowe-api-dev config --name zos -p port=$TEST_PORT 10 | zowe-api-dev start --job --killPrevious 11 | 12 | TEST_BASE_URI=https://$ZOS_HOST ./gradlew integrationTest 13 | TEST_RESULT=$? 14 | 15 | set +e 16 | zowe-api-dev stop 17 | cd .. 18 | 19 | scripts/unlock-port.sh 20 | exit $TEST_RESULT 21 | -------------------------------------------------------------------------------- /scripts/run-integration-tests-kotlin.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | cd zowe-rest-api-sample-kotlin-spring 5 | java -jar build/libs/zowe-rest-api-sample-kotlin-spring-*.jar --spring.config.additional-location=file:./config/local/local.yml & 6 | PID=$! 7 | echo $PID > .pid 8 | 9 | TEST_USERID=zowe2 TEST_PASSWORD=zowe TEST_PORT=10090 TEST_WAIT_MINUTES=1 ./gradlew integrationTest 10 | TEST_RESULT=$? 11 | cd .. 12 | 13 | PID=$(cat zowe-rest-api-sample-kotlin-spring/.pid) 14 | rm zowe-rest-api-sample-kotlin-spring/.pid 15 | echo "Killing process $PID" 16 | kill -9 $PID 17 | exit $TEST_RESULT 18 | -------------------------------------------------------------------------------- /scripts/run-integration-tests-zos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | scripts/lock-port.sh 5 | 6 | cd zowe-rest-api-sample-spring 7 | zowe-api-dev deploy 8 | zowe-api-dev config --name zos -p port=$TEST_PORT 9 | zowe-api-dev start --job --killPrevious 10 | 11 | TEST_BASE_URI=https://$ZOS_HOST ./gradlew integrationTest 12 | TEST_RESULT=$? 13 | 14 | set +e 15 | zowe-api-dev stop 16 | cd .. 17 | 18 | scripts/unlock-port.sh 19 | exit $TEST_RESULT 20 | -------------------------------------------------------------------------------- /scripts/run-integration-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | cd zowe-rest-api-sample-spring 5 | java -jar build/libs/zowe-rest-api-sample-spring-*.jar --spring.config.additional-location=file:./config/local/application.yml & 6 | PID=$! 7 | echo $PID > .pid 8 | 9 | TEST_USERID=zowe2 TEST_PASSWORD=zowe TEST_PORT=10080 TEST_WAIT_MINUTES=1 ./gradlew integrationTest 10 | TEST_RESULT=$? 11 | cd .. 12 | 13 | PID=$(cat zowe-rest-api-sample-spring/.pid) 14 | rm zowe-rest-api-sample-spring/.pid 15 | echo "Killing process $PID" 16 | kill -9 $PID 17 | exit $TEST_RESULT 18 | -------------------------------------------------------------------------------- /scripts/so-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | mkdir -p test_libs 5 | java -cp zowe-rest-api-sample-spring/build/libs/zowe-rest-api-sample-spring-*.jar -Dloader.main=org.zowe.sample.apiservice.LibsExtractor org.springframework.boot.loader.PropertiesLauncher test_libs 6 | test -f test_libs/libzowe-sample.so && test -f test_libs/libzowe-commons-secur.so 7 | echo "Result: $?" 8 | -------------------------------------------------------------------------------- /scripts/unlock-port.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | DSN="$ZOS_USERID.ZOWE.SDKLOCKS" 5 | DSN_MEMBER="$DSN(P${TEST_PORT})" 6 | 7 | echo "Unlocking test environment for port $TEST_PORT" 8 | 9 | if [ ! -f ".lock-session" ]; then 10 | echo "WARN: .lock-session file does not exist" 11 | exit 0 12 | fi 13 | 14 | URL="https://${ZOS_HOST}:${ZOS_ZOSMF_PORT}/zosmf/restfiles/ds/$DSN_MEMBER" 15 | echo URL=$URL 16 | 17 | SESSION_REF=$(cat .lock-session) 18 | echo SESSION_REF=$SESSION_REF 19 | curl --include --user $ZOS_USERID:$ZOS_PASSWORD --insecure -X PUT --header 'X-CSRF-ZOSMF-HEADER: true' --header 'Content-Type: text/plain' --header 'Accept: application/json' --header 'X-IBM-Data-Type: text' --header 'X-IBM-Migrated-Recall: wait' --header 'X-IBM-Release-ENQ: true' --header "X-IBM-Session-Ref:$SESSION_REF" -d '' "$URL" > unlock.out 20 | if ! grep 'HTTP/1.1 204 No Content' unlock.out; then 21 | cat unlock.out 22 | echo -e "\nERROR: Unlocking of $DSN_MEMBER failed" 23 | exit 1 24 | fi 25 | rm -f unlock.out 26 | rm -f .lock-session 27 | -------------------------------------------------------------------------------- /scripts/zos-cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ -z "$ZOS_TARGET_DIR" ] 5 | then 6 | echo "\$ZOS_TARGET_DIR is not set. It needs to be set to the z/OS UNIX target directory where the z/OS native code build will be done" 7 | exit 1 8 | fi 9 | 10 | if [ -z "$ZOS_USERID" ] 11 | then 12 | echo "\$ZOS_USERID is not set. It needs to be set to the user ID that is used for builds" 13 | exit 1 14 | fi 15 | 16 | if [ -z "$ZOS_PASSWORD" ] 17 | then 18 | echo "\$ZOS_PASSWORD is not set. It needs to be set to the password of the '$ZOS_USERID' user ID" 19 | exit 1 20 | fi 21 | 22 | echo "Preparing Zowe CLI profiles" 23 | zowe profiles create ssh-profile $ZOWE_CLI_PROFILE_NAME --host $ZOS_HOST --port $ZOS_SSH_PORT --user $ZOS_USERID --password "$ZOS_PASSWORD" --overwrite > /dev/null 24 | zowe profiles set-default ssh $ZOWE_CLI_PROFILE_NAME 25 | 26 | echo "Removing $ZOS_TARGET_DIR/b$CIRCLE_BUILD_NUM" 27 | zowe zos-uss issue ssh "rm -rf $ZOS_TARGET_DIR/b$CIRCLE_BUILD_NUM" 28 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | 7 | include 'zowe-rest-api-sample-spring' 8 | include 'zowe-rest-api-sample-kotlin-spring' 9 | include 'zowe-rest-api-commons-spring' 10 | include 'jarpatcher' 11 | 12 | rootProject.name = 'zowe' 13 | -------------------------------------------------------------------------------- /zowe-api-dev/.gitignore: -------------------------------------------------------------------------------- 1 | *-debug.log 2 | *-error.log 3 | /.nyc_output 4 | /dist 5 | /lib 6 | /tmp 7 | /yarn.lock 8 | node_modules 9 | -------------------------------------------------------------------------------- /zowe-api-dev/README.md: -------------------------------------------------------------------------------- 1 | # Zowe REST API SDK Command Line Tool 2 | 3 | Provides convenience functions to build native code, deploy REST API, and start it in a form of a CLI tool `zowe-api`. 4 | 5 | ## Installation 6 | 7 | ### From NPM (for users) 8 | 9 | ```bash 10 | npm -g install @zowedev/zowe-api-dev 11 | ``` 12 | 13 | ### From sources (for developers) 14 | 15 | ```bash 16 | git clone https://github.com/zowe/sample-spring-boot-api-service 17 | cd sample-spring-boot-api-service 18 | ./gradlew :jarpatcher:build 19 | cd zowe-api-dev 20 | npm install 21 | npm pack 22 | npm link 23 | ``` 24 | 25 | **Note:** The `npm pack` is required to include the `jarpatcher.jar` that is created by `./gradlew :jarpatcher:build`. 26 | 27 | ## Usage 28 | 29 | See [zowe-api-dev - Zowe API Development CLI Tool](/zowe-rest-api-sample-spring/docs/devtool.md). 30 | 31 | ```txt 32 | $ zowe-api-dev 33 | 34 | Zowe REST API Development CLI 35 | 36 | USAGE 37 | $ zowe-api-dev [COMMAND] 38 | 39 | COMMANDS 40 | config configure the API service on z/OS 41 | deploy deploy the API service artifacts to z/OS 42 | help display help for zowe-api-dev 43 | init initialize user configuration file 44 | start start the API service on z/OS 45 | status get status of API service 46 | stop stop the API service on z/OS 47 | zfs initialize user configuration file 48 | zosbuild build z/OS source on z/OS UNIX 49 | ``` 50 | -------------------------------------------------------------------------------- /zowe-api-dev/bin/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('@oclif/command').run() 4 | .then(require('@oclif/command/flush')) 5 | .catch(require('@oclif/errors/handle')) 6 | -------------------------------------------------------------------------------- /zowe-api-dev/bin/run.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | node "%~dp0\run" %* 4 | -------------------------------------------------------------------------------- /zowe-api-dev/src/commands/deploy.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | import { Command, flags } from "@oclif/command"; 12 | import * as logSymbols from "log-symbols"; 13 | import { readConfiguration } from "../config"; 14 | import { transferFiles } from "../files"; 15 | import { checkZowe } from "../zowe"; 16 | 17 | export default class Deploy extends Command { 18 | static description = "deploy the API service artifacts to z/OS"; 19 | 20 | static flags = { 21 | force: flags.boolean({ char: "f", description: "forces full deployment even if there is no change", default: false }), 22 | }; 23 | 24 | async run() { 25 | const f = this.parse(Deploy).flags; 26 | const [userConfig, projectConfig] = readConfiguration(this); 27 | 28 | 29 | checkZowe(this); 30 | 31 | if (!projectConfig.deployment.files) { 32 | this.warn("Nothing to deploy"); 33 | } else { 34 | transferFiles(projectConfig.deployment.files, userConfig.zosTargetDir, userConfig, this, f.force); 35 | this.log(logSymbols.success, "Deployment to z/OS completed"); 36 | this.log( 37 | logSymbols.info, 38 | "Use 'zowe-api-dev config' to configure your application to z/OS or 'zowe-api-dev start' to start already configured application" 39 | ); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /zowe-api-dev/src/commands/status.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | import { Command } from "@oclif/command"; 12 | import * as Debug from "debug"; 13 | import { clearLastJob, findJob, readLastJob, saveLastJob } from "../jes"; 14 | 15 | const debug = Debug("status"); 16 | 17 | export default class Status extends Command { 18 | static description = "get status of API service"; 19 | 20 | async run() { 21 | const lastJob = readLastJob(); 22 | if (lastJob == null) { 23 | this.error("No job previously started from this directory"); 24 | } else { 25 | const job = findJob(lastJob.jobid); 26 | if (job == null) { 27 | clearLastJob(); 28 | this.error(`Job ${lastJob.jobname} (${lastJob.jobid}) not found. Removing the 'lastJob.json' file`); 29 | } else { 30 | debug(job); 31 | saveLastJob(job); 32 | this.log(`Job ${job.jobname} (${job.jobid}) is in ${job.status} status, retcode=${job.retcode}`); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /zowe-api-dev/src/commands/stop.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | import { Command } from "@oclif/command"; 12 | import * as Debug from "debug"; 13 | import { clearLastJob, findJob, IJob, readLastJob, saveLastJob } from "../jes"; 14 | import { zoweSync } from "../zowe"; 15 | 16 | const debug = Debug("stop"); 17 | 18 | export default class Stop extends Command { 19 | static description = "stop the API service on z/OS"; 20 | 21 | async run() { 22 | const lastJob = readLastJob(); 23 | if (lastJob == null) { 24 | this.error("No job previously started from this directory"); 25 | } else { 26 | const job = findJob(lastJob.jobid); 27 | if (job == null) { 28 | clearLastJob(); 29 | this.error(`Job ${lastJob.jobname} (${lastJob.jobid}) not found. Removing the 'lastJob.json' file`); 30 | } else { 31 | debug(job); 32 | saveLastJob(job); 33 | if (job.status === "ACTIVE") { 34 | this.log(`Stopping job ${job.jobname} (${job.jobid})`); 35 | const updatedJob = zoweSync(`zos-console issue command "P ${job.jobname}"`).data as IJob; 36 | saveLastJob(updatedJob); 37 | } else { 38 | this.warn(`Stopping job ${job.jobname} (${job.jobid}) is not active but in ${job.status} status`); 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /zowe-api-dev/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | export { run } from "@oclif/command"; 12 | -------------------------------------------------------------------------------- /zowe-api-dev/src/jes.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | import * as Debug from "debug"; 12 | import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs"; 13 | import { zoweSync } from "./zowe"; 14 | 15 | const debug = Debug("jes"); 16 | 17 | export interface IJob { 18 | jobname: string; 19 | jobid: string; 20 | status: string; 21 | retcode: string | null; 22 | owner: string; 23 | } 24 | 25 | const lastJobPath = "lastJob.json"; 26 | 27 | export function readLastJob(): IJob | null { 28 | if (existsSync(lastJobPath)) { 29 | const job = JSON.parse(readFileSync(lastJobPath, "utf8")) as IJob; 30 | debug(job); 31 | return job; 32 | } 33 | return null; 34 | } 35 | 36 | export function clearLastJob() { 37 | unlinkSync(lastJobPath); 38 | } 39 | 40 | export function saveLastJob(job: IJob) { 41 | writeFileSync(lastJobPath, JSON.stringify(job, null, 4)); 42 | } 43 | 44 | export function findJob(jobid: string): IJob | null { 45 | try { 46 | const job = zoweSync(`jobs view job-status-by-jobid ${jobid}`).data as IJob; 47 | debug(job); 48 | return job; 49 | } catch (error) { 50 | if (error.message.indexOf("Job not found") > -1) { 51 | return null; 52 | } else { 53 | throw error; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /zowe-api-dev/test/commands/hello.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | 3 | describe('hello', () => { 4 | test 5 | .stdout() 6 | .command(['hello']) 7 | .it('runs hello', ctx => { 8 | expect(ctx.stdout).to.contain('hello world') 9 | }) 10 | 11 | test 12 | .stdout() 13 | .command(['hello', '--name', 'jeff']) 14 | .it('runs hello --name jeff', ctx => { 15 | expect(ctx.stdout).to.contain('hello jeff') 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /zowe-api-dev/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --watch-extensions ts 3 | --recursive 4 | --reporter spec 5 | --timeout 5000 6 | -------------------------------------------------------------------------------- /zowe-api-dev/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig", 3 | "compilerOptions": { 4 | "noEmit": true 5 | }, 6 | "references": [ 7 | {"path": ".."} 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /zowe-api-dev/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "outDir": "lib", 7 | "rootDir": "src", 8 | "strict": true, 9 | "target": "es2018" 10 | }, 11 | "include": [ 12 | "src/**/*" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /zowe-api-dev/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint:latest", 4 | "tslint-config-prettier" 5 | ], 6 | "rules": { 7 | "member-access": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /zowe-api.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zowe REST API SDK", 3 | "defaultDirName": "zowe-rest-api-sdk", 4 | "defaultHlqSegment": "ZOWE.APISDK", 5 | "zfsMegabytes": 500 6 | } 7 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | /bin/ 4 | gradle/wrapper/gradle-wrapper.jar 5 | .DS_Store 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /out/ 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | 33 | deploy/scripts/out 34 | deploy/templates/jcl/out 35 | deploy/config/local.ts 36 | node_modules 37 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/README.md: -------------------------------------------------------------------------------- 1 | # Zowe REST API Common Library for Spring 2 | 3 | [![Download](https://api.bintray.com/packages/plavjanik/zowe/zowe-rest-api-commons-spring/images/download.svg)](https://bintray.com/plavjanik/zowe/zowe-rest-api-commons-spring/_latestVersion) 4 | 5 | Java library that provides useful functionality for z/OS REST APIs developed in Spring Boot. 6 | 7 | ## Creating new version 8 | 9 | ```bash 10 | git tag v0.0.1 11 | git push origin v0.0.1 12 | ``` 13 | 14 | ## Publishing to Maven Local 15 | 16 | `./gradlew publishToMavenLocal` 17 | 18 | ## Publishing to Bintray 19 | 20 | You need to provide your credentials to Bintray. You can get it from , section `API Key`. 21 | 22 | `BINTRAY_USER=user BINTRAY_API_KEY=apikey ./gradlew uploadBintray` 23 | 24 | ## Using the Library 25 | 26 | ```gradle 27 | plugins { 28 | id 'java' 29 | } 30 | 31 | repositories { 32 | mavenLocal() 33 | jcenter() 34 | } 35 | 36 | dependencies { 37 | implementation 'org.zowe:zowe-rest-api-commons-spring:' 38 | } 39 | ``` 40 | 41 | ## Other documentation 42 | 43 | - [Building z/OS native code](docs/zos-native-code.md) 44 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/docs/zos-native-code.md: -------------------------------------------------------------------------------- 1 | # Common z/OS Native Code 2 | 3 | The commons library contains following native libraries: 4 | 5 | - `libzowe-commons-secur.so` - contains security related functionality 6 | 7 | ## Building 8 | 9 | The code is `zossrc` folder including the makefile. 10 | 11 | These scripts are experimental and will be improved a lot in future and integrated to the Gradle build process. 12 | 13 | 1. `cd zowe-rest-api-commons-cli` 14 | 2. `npm install; npm link` 15 | 3. Create a z/OSMF and SSH profiles with Zowe CLI 16 | 4. Mount a zFS file system for the build 17 | 5. `zowe-api-dev init -t ` 18 | 6. `zowe-api-dev zosbuild` 19 | 7. `./gradlew build` includes the `libzowe-commons-secur.so` in the to `.jar` file 20 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | 3 | # Repository URL for getting Zowe artifacts: 4 | zoweArtifactoryRepository=https://zowe.jfrog.io/zowe/libs-release 5 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/lombok.config: -------------------------------------------------------------------------------- 1 | lombok.addLombokGeneratedAnnotation = true 2 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/AccentStrippingPatternLayerEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons; 11 | 12 | import ch.qos.logback.classic.encoder.PatternLayoutEncoder; 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.Layout; 15 | import lombok.Setter; 16 | import org.apache.commons.lang3.ArrayUtils; 17 | 18 | import java.nio.charset.Charset; 19 | import java.text.Normalizer; 20 | 21 | public class AccentStrippingPatternLayerEncoder extends PatternLayoutEncoder { // NOSONAR 22 | // Sonar exclusion: This class is extending Logback class that is not under our control 23 | 24 | private static final String STRIP_ACCENTS_PROPERTY_NAME = "org.zowe.commons.logging.stripAccents"; 25 | 26 | @Setter 27 | private boolean stripAccents = "true".equalsIgnoreCase(System.getProperty(STRIP_ACCENTS_PROPERTY_NAME)); 28 | 29 | @Override 30 | public byte[] encode(ILoggingEvent event) { 31 | String txt = layout.doLayout(event); 32 | if (stripAccents) { 33 | String stripped = stripAccents(txt); 34 | if (stripped == null) { 35 | return ArrayUtils.EMPTY_BYTE_ARRAY; 36 | } 37 | 38 | Charset charset = getCharset(); 39 | if (charset == null) { 40 | charset = Charset.defaultCharset(); 41 | } 42 | return stripped.getBytes(charset); 43 | } else { 44 | return super.encode(event); 45 | } 46 | } 47 | 48 | private String stripAccents(String input) { 49 | return input == null ? null 50 | : Normalizer.normalize(input, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); // NOSONAR: Used for internal strings 51 | } 52 | 53 | void overrideLayout(Layout layout) { 54 | this.layout = layout; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/UseridFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons; 11 | 12 | import org.slf4j.MDC; 13 | import org.slf4j.Marker; 14 | 15 | import ch.qos.logback.classic.Level; 16 | import ch.qos.logback.classic.Logger; 17 | import ch.qos.logback.classic.turbo.TurboFilter; 18 | import ch.qos.logback.core.spi.FilterReply; 19 | 20 | public class UseridFilter extends TurboFilter { 21 | 22 | @Override 23 | public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { 24 | if (MDC.get("userid") == null) { 25 | MDC.put("userid", System.getProperty("user.name")); 26 | } 27 | 28 | return FilterReply.NEUTRAL; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/apidoc/ApiDocConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apidoc; 11 | 12 | public final class ApiDocConstants { 13 | public static final String DOC_SCHEME_BASIC_AUTH = "basicAuth"; 14 | 15 | private ApiDocConstants() { 16 | // Utility class 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/apidoc/BasePathProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apidoc; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | import springfox.documentation.spring.web.paths.DefaultPathProvider; 14 | 15 | /** 16 | * @deprecated This class does not correctly work with SpringFox 3.x 17 | * A base path is not modified although paths for each endpoint are changed 18 | * 19 | * Use {@link org.zowe.commons.apidoc.BasePathTransformationFilter} instead 20 | * 21 | */ 22 | @Deprecated 23 | @Slf4j 24 | public class BasePathProvider extends DefaultPathProvider { 25 | private final String basePath; 26 | 27 | public BasePathProvider(String basePath) { 28 | this.basePath = basePath; 29 | log.warn("BasePathProvider class is deprecated and does not work correctly. Use `org.zowe.commons.apidoc.BasePathTransformationFilter` instead."); 30 | } 31 | 32 | @Override 33 | public String getOperationPath(String operationPath) { 34 | String newOperationPath = super.getOperationPath(operationPath); 35 | if (newOperationPath.startsWith(basePath)) { 36 | return newOperationPath.substring(basePath.length()); 37 | } else { 38 | return newOperationPath; 39 | } 40 | } 41 | 42 | @Override 43 | protected String getDocumentationPath() { 44 | return basePath + "/apiDocs"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/apiml/ApiMediationServiceConfigBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apiml; 11 | 12 | import org.springframework.boot.context.properties.ConfigurationProperties; 13 | import org.zowe.apiml.eurekaservice.client.config.ApiMediationServiceConfig; 14 | 15 | @ConfigurationProperties("apiml.service") 16 | public class ApiMediationServiceConfigBean extends ApiMediationServiceConfig { 17 | } 18 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/apiml/CatalogUiTile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apiml; 11 | 12 | import lombok.Data; 13 | import org.springframework.boot.context.properties.ConfigurationProperties; 14 | import org.springframework.context.annotation.Configuration; 15 | import org.zowe.apiml.eurekaservice.client.config.Catalog; 16 | 17 | /** 18 | * Represents one API Catalog UI tile (groups services together) 19 | * 20 | * @deprecated used to maintain the backward compatibility with the older version of APIML Java enabler 21 | */ 22 | @Deprecated 23 | @Configuration 24 | @ConfigurationProperties("apiml.service.catalog-ui-tile") 25 | @Data 26 | public class CatalogUiTile { 27 | private String id; 28 | private String title; 29 | private String description; 30 | private String version; 31 | 32 | public Catalog toCatalog() { 33 | Catalog.Tile tile = new Catalog.Tile(id, title, description, version); 34 | return new Catalog(tile); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/apiml/SslConfigBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apiml; 11 | 12 | import org.springframework.boot.context.properties.ConfigurationProperties; 13 | import org.zowe.apiml.eurekaservice.client.config.Ssl; 14 | 15 | @ConfigurationProperties("server.ssl") 16 | public class SslConfigBean extends Ssl { 17 | } 18 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/error/CommonsErrorService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | public final class CommonsErrorService { 13 | private static ErrorService errorService = ErrorServiceImpl.getCommonsDefault(); 14 | 15 | private CommonsErrorService() { 16 | } 17 | 18 | public static ErrorService get() { 19 | return errorService; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/error/DuplicateMessageException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | /** 13 | * Exception thrown when a message is already defined before 14 | */ 15 | public class DuplicateMessageException extends RuntimeException { 16 | private static final long serialVersionUID = -3407108866724093071L; 17 | 18 | public DuplicateMessageException(String message) { 19 | super(message); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/error/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | import org.zowe.commons.rest.response.MessageType; 13 | 14 | import lombok.AllArgsConstructor; 15 | import lombok.Data; 16 | import lombok.NoArgsConstructor; 17 | 18 | @Data 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | public class ErrorMessage { 22 | private String key; 23 | private String number; 24 | private MessageType type; 25 | private String text; 26 | private String reason; 27 | private String action; 28 | private String component; 29 | 30 | public ErrorMessage(String key, String number, MessageType type, String text) { 31 | this(key, number, type, text, null, null, null); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/error/ErrorMessages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class ErrorMessages { 16 | private List messages; 17 | 18 | public ErrorMessages(List messages) { 19 | this.messages = messages; 20 | } 21 | 22 | public ErrorMessages() { 23 | this.messages = new ArrayList<>(); 24 | } 25 | 26 | public List getMessages() { 27 | return messages; 28 | } 29 | 30 | public void setMessages(List messages) { 31 | this.messages = messages; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/error/MessageLoadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | /** 13 | * Exception thrown when a message couldn't be loaded or has wrong definition 14 | */ 15 | public class MessageLoadException extends RuntimeException { 16 | private static final long serialVersionUID = -1890955912059595381L; 17 | 18 | public MessageLoadException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/rest/response/ApiMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.rest.response; 11 | 12 | import java.util.List; 13 | 14 | import com.fasterxml.jackson.annotation.JsonInclude; 15 | 16 | /** 17 | * This interface is intended for REST API responses that contain error, 18 | * warning, or informational messages in the common Zowe format. 19 | * 20 | * It is preferred to return successful responses without messages if possible 21 | * and use only plain responses without wrapping for them. 22 | * 23 | * The {@link ApiMessage} and its implementation 24 | * {@link org.zowe.commons.rest.response.BasicApiMessage} should be used in the 25 | * case when a problem (an error) happens and then the response contains only 26 | * the error(s). 27 | * 28 | * When a response needs to contain both data and messages (e.g. warnings) then 29 | * it is advised for the response class to implement {@link ApiMessage} too. But 30 | * this should be an exception and we should try to make the REST API easy to 31 | * use without the need for the API user to process informational and warning 32 | * messages. 33 | */ 34 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 35 | public interface ApiMessage { 36 | /** 37 | * A list of messages that contain error, warning, and informational content. 38 | */ 39 | List getMessages(); 40 | 41 | /** 42 | * Returns the first message in the format that can be printed to console as a 43 | * single line or displayed to the user. 44 | */ 45 | String toReadableText(); 46 | 47 | /** 48 | * The message that can be used in the server log. Includes the message instance 49 | * ID. 50 | */ 51 | String toLogMessage(); 52 | } 53 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/rest/response/MessageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.rest.response; 11 | 12 | /** 13 | * Represents the severity of a problem. Higher severity has higher value. 14 | */ 15 | public enum MessageType { 16 | ERROR(40, "ERROR", 'E'), WARNING(30, "WARNING", 'W'), INFO(20, "INFO", 'I'), DEBUG(10, "DEBUG", 'D'), 17 | TRACE(0, "TRACE", 'T'); 18 | 19 | private int levelInt; 20 | private String levelStr; 21 | private char levelChar; 22 | 23 | MessageType(int i, String s, char c) { 24 | levelInt = i; 25 | levelStr = s; 26 | levelChar = c; 27 | } 28 | 29 | public int toInt() { 30 | return levelInt; 31 | } 32 | 33 | public char toChar() { 34 | return levelChar; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return levelStr; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/DefaultMessageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import java.net.InetAddress; 13 | import java.net.UnknownHostException; 14 | 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.boot.context.event.ApplicationReadyEvent; 17 | import org.springframework.context.ApplicationListener; 18 | import org.springframework.context.annotation.Configuration; 19 | import org.springframework.core.env.Environment; 20 | import org.zowe.commons.error.CommonsErrorService; 21 | import org.zowe.commons.error.ErrorService; 22 | 23 | import lombok.extern.slf4j.Slf4j; 24 | 25 | @Configuration 26 | @Slf4j 27 | public class DefaultMessageSource implements ApplicationListener { 28 | private final Environment environment; 29 | private final ErrorService errorService; 30 | 31 | @Autowired 32 | public DefaultMessageSource(ErrorService errorService, Environment environment) { 33 | this.errorService = errorService; 34 | this.environment = environment; 35 | } 36 | 37 | @Override 38 | public void onApplicationEvent(ApplicationReadyEvent event) { 39 | String hostname; 40 | try { 41 | hostname = InetAddress.getLocalHost().getCanonicalHostName(); 42 | } catch (UnknownHostException e) { 43 | log.warn("Could not obtain hostname", e); 44 | hostname = "?"; 45 | } 46 | String serviceId = environment.getProperty("apiml.service.serviceId"); 47 | String messageSource = String.format("%s:%s:%s", hostname, environment.getProperty("server.port"), serviceId); 48 | errorService.setDefaultMessageSource(messageSource); 49 | CommonsErrorService.get().setDefaultMessageSource(messageSource); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/EnableEurekaLoggingTimerTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import java.util.TimerTask; 13 | 14 | import org.slf4j.LoggerFactory; 15 | 16 | import ch.qos.logback.classic.Level; 17 | import ch.qos.logback.classic.Logger; 18 | import ch.qos.logback.classic.LoggerContext; 19 | 20 | public class EnableEurekaLoggingTimerTask extends TimerTask { 21 | static final String[] EUREKA_LOGGER_NAMES = new String[] { "com.netflix.discovery.DiscoveryClient", 22 | "com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient" }; 23 | 24 | @Override 25 | public void run() { 26 | LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); 27 | for (String name : EUREKA_LOGGER_NAMES) { 28 | Logger logger = loggerContext.getLogger(name); 29 | logger.setLevel(Level.ERROR); // NOSONAR: Error level is safe 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/ServiceStartupEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import java.lang.management.ManagementFactory; 13 | 14 | import org.springframework.stereotype.Component; 15 | import org.zowe.commons.error.CommonsErrorService; 16 | 17 | import lombok.extern.slf4j.Slf4j; 18 | 19 | @Slf4j 20 | @Component 21 | public class ServiceStartupEventHandler { 22 | public static final int DEFAULT_DELAY_FACTOR = 5; 23 | 24 | public void onServiceStartup(String serviceName, int delayFactor) { 25 | long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); 26 | log.info(CommonsErrorService.get().createApiMessage("org.zowe.commons.service.started", serviceName, uptime / 1000.0).toReadableText()); 27 | 28 | new java.util.Timer().schedule(new EnableEurekaLoggingTimerTask(), uptime * delayFactor); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/SpringContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import org.springframework.context.ApplicationContext; 13 | import org.springframework.context.ApplicationContextAware; 14 | import org.springframework.stereotype.Component; 15 | 16 | @Component 17 | public class SpringContext implements ApplicationContextAware { 18 | 19 | private static ApplicationContext context; 20 | 21 | public static T getBean(Class beanClass) { 22 | return context.getBean(beanClass); 23 | } 24 | 25 | public static ApplicationContext getApplicationContext() { 26 | return context; 27 | } 28 | 29 | @Override 30 | public void setApplicationContext(ApplicationContext context) { 31 | setSpringContext(context); 32 | } 33 | 34 | private static synchronized void setSpringContext(ApplicationContext context) { 35 | SpringContext.context = context; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/WebConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.http.MediaType; 15 | import org.springframework.web.servlet.LocaleResolver; 16 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; 17 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 18 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 19 | import org.springframework.web.servlet.i18n.CookieLocaleResolver; 20 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 21 | 22 | @Configuration 23 | public class WebConfig implements WebMvcConfigurer { 24 | private static final String LANG_PARAM_NAME = "lang"; 25 | 26 | @Bean 27 | public LocaleChangeInterceptor localeInterceptor() { 28 | LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); 29 | localeInterceptor.setParamName(LANG_PARAM_NAME); 30 | return localeInterceptor; 31 | } 32 | 33 | @Override 34 | public void addInterceptors(InterceptorRegistry registry) { 35 | registry.addInterceptor(localeInterceptor()); 36 | } 37 | 38 | @Override 39 | public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 40 | configurer 41 | .favorParameter(false) 42 | .ignoreAcceptHeader(true) 43 | .useRegisteredExtensionsOnly(true) 44 | .defaultContentType(MediaType.APPLICATION_JSON); 45 | } 46 | 47 | @Bean 48 | public LocaleResolver localeResolver() { 49 | return new CookieLocaleResolver(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/security/CsrfController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring.security; 11 | 12 | import org.springframework.security.web.csrf.CsrfToken; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | @RestController 17 | public class CsrfController { 18 | 19 | @GetMapping("/csrf") 20 | public CsrfToken csrf(CsrfToken token) { 21 | return token; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/security/HttpsWebServerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring.security; 11 | 12 | import org.apache.coyote.http11.AbstractHttp11Protocol; 13 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 14 | import org.springframework.boot.web.server.WebServerFactoryCustomizer; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | 18 | @Configuration 19 | public class HttpsWebServerConfig { 20 | 21 | @Bean 22 | public WebServerFactoryCustomizer servletContainerCustomizer() { 23 | return factory -> factory.addConnectorCustomizers(connector -> { 24 | AbstractHttp11Protocol abstractProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler(); 25 | abstractProtocol.setUseServerCipherSuitesOrder(true); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/security/MethodSecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring.security; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 14 | import org.springframework.context.annotation.Configuration; 15 | import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; 16 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 17 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 18 | import org.zowe.commons.zos.security.service.PlatformSecurityService; 19 | 20 | @Configuration 21 | @EnableGlobalMethodSecurity(prePostEnabled = true) 22 | @EnableConfigurationProperties(SafSecurityConfigurationProperties.class) 23 | public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { // NOSONAR 24 | @Autowired 25 | private PlatformSecurityService platformSecurityService; 26 | 27 | @Autowired 28 | private SafSecurityConfigurationProperties safSecurityConfigurationProperties; 29 | 30 | @Override 31 | protected MethodSecurityExpressionHandler createExpressionHandler() { 32 | return new SafMethodSecurityExpressionHandler(platformSecurityService, safSecurityConfigurationProperties); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/spring/security/SafSecurityConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring.security; 11 | 12 | import org.springframework.boot.context.properties.ConfigurationProperties; 13 | 14 | import lombok.AllArgsConstructor; 15 | import lombok.Data; 16 | import lombok.NoArgsConstructor; 17 | 18 | @ConfigurationProperties("zowe.commons.security.saf") 19 | @Data 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | class SafSecurityConfigurationProperties { 23 | private String serviceResourceClass; 24 | private String serviceResourceNamePrefix; 25 | } 26 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/CommonsNativeLibraries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class CommonsNativeLibraries implements NativeLibraries { 16 | public static final String SECUR_LIBRARY_NAME = "zowe-commons-secur"; 17 | 18 | @Override 19 | public List getNativeLibrariesNames() { 20 | List libraries = new ArrayList<>(); 21 | libraries.add(SECUR_LIBRARY_NAME); 22 | return libraries; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/LibLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | 14 | @Slf4j 15 | public class LibLoader { 16 | public String libraryFileName(String libraryName) { 17 | return "lib" + libraryName + ".so"; 18 | } 19 | 20 | public void loadLibrary(String libraryName) { 21 | try { 22 | System.loadLibrary(libraryName); 23 | } catch (UnsatisfiedLinkError e) { 24 | 25 | log.error("Could not load native library (shared object) '{}. " 26 | + "Check that the library file is present in a directory of Java library path. " 27 | + "The Java library path is set by LIBPATH environment variable or java.library.path property. " 28 | + "Check that the library file has program controlled attribute and is executable. " 29 | + "java.library.path={}", libraryFileName(libraryName), System.getProperty("java.library.path")); 30 | throw e; 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/NativeLibraries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos; 11 | 12 | import java.util.List; 13 | 14 | public interface NativeLibraries { 15 | public List getNativeLibrariesNames(); 16 | } 17 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/ZosUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos; 11 | 12 | public class ZosUtils { 13 | private ZosUtils() { 14 | // no instances 15 | } 16 | 17 | /** 18 | * @return True when running on z/OS. 19 | */ 20 | public static boolean isRunningOnZos() { 21 | String osName = System.getProperty("os.name"); 22 | return "z/OS".equals(osName); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/authentication/ZosAuthenticationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.authentication; 11 | 12 | import org.springframework.security.core.AuthenticationException; 13 | import org.zowe.commons.zos.security.platform.PlatformReturned; 14 | 15 | public class ZosAuthenticationException extends AuthenticationException { 16 | private static final long serialVersionUID = 6652673387938170807L; 17 | private final PlatformReturned platformReturned; 18 | 19 | public ZosAuthenticationException(String message, PlatformReturned platformReturned) { 20 | super(message); 21 | this.platformReturned = platformReturned; 22 | } 23 | 24 | public PlatformReturned getPlatformReturned() { 25 | return platformReturned; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/jni/Secur.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.jni; 11 | 12 | import static org.zowe.commons.zos.CommonsNativeLibraries.SECUR_LIBRARY_NAME; 13 | 14 | import org.zowe.commons.zos.LibLoader; 15 | 16 | import lombok.extern.slf4j.Slf4j; 17 | 18 | @Slf4j 19 | public class Secur { 20 | public Secur() { 21 | new LibLoader().loadLibrary(SECUR_LIBRARY_NAME); 22 | } 23 | 24 | public native int createSecurityEnvironment(String userid, String password, String applId); 25 | 26 | public native int createSecurityEnvironmentByDaemon(String userid, String applId); 27 | 28 | public native int removeSecurityEnvironment(); 29 | 30 | public native int getLastErrno2(); 31 | 32 | public native int setApplid(String applid); 33 | } 34 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/MockPlatformUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public class MockPlatformUser implements PlatformUser { 13 | // Sonar exclusion: The passwords are using only for testing with this mock 14 | 15 | public static final String VALID_USERID = "zowe"; 16 | public static final String VALID_USERID2 = "zowe2"; 17 | public static final String VALID_PASSWORD = "zowe"; // NOSONAR 18 | public static final String INVALID_USERID = "notzowe"; 19 | public static final String INVALID_PASSWORD = "notzowe"; // NOSONAR 20 | public static final String EXPIRED_PASSWORD = "expired"; // NOSONAR 21 | public static final String FAILING_PASSWORD = "failing"; // NOSONAR 22 | 23 | @Override 24 | public PlatformReturned authenticate(String userid, String password) { 25 | if ((userid.equalsIgnoreCase(VALID_USERID) || userid.equalsIgnoreCase(VALID_USERID2)) 26 | && password.equalsIgnoreCase(VALID_PASSWORD)) { 27 | return null; 28 | } else { 29 | PlatformReturned.PlatformReturnedBuilder builder = PlatformReturned.builder().success(false); 30 | if (EXPIRED_PASSWORD.equalsIgnoreCase(password)) { 31 | builder.errno(PlatformPwdErrno.EMVSEXPIRE.errno); 32 | } else if (FAILING_PASSWORD.equalsIgnoreCase(password)) { 33 | builder.errno(PlatformPwdErrno.EMVSERR.errno).errno2(PlatformErrno2.JREnvDirty.errno2); 34 | } 35 | return builder.build(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | /** 13 | * Creates classes for platform-specific behavior. The purpose is wrap original 14 | * classes without interfaces and with static methods into classes that 15 | * implement interfaces. Implementations of this class factory can either return 16 | * the original z/OS classes or dummy implementations to enable unit testing or 17 | * running off z/OS for development purposes. 18 | */ 19 | public interface PlatformClassFactory { 20 | Class getPlatformReturnedClass() throws ClassNotFoundException; 21 | 22 | Class getPlatformUserClass() throws ClassNotFoundException; 23 | 24 | Object getPlatformUser(); 25 | 26 | Class getPlatformAccessControlClass() throws ClassNotFoundException; 27 | 28 | Object getPlatformAccessControl() throws ClassNotFoundException; 29 | 30 | PlatformReturned convertPlatformReturned(Object safReturned) 31 | throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException; 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformErrorType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public enum PlatformErrorType { 13 | /** 14 | * Error during the security processing which means that security product did 15 | * not allow the action but no details should be shared with the user - e.g. 16 | * invalid user ID or password 17 | */ 18 | DEFAULT, 19 | /** 20 | * Error during the security processing which means that security product did 21 | * not allow the action and details should be shared with the user - e.g expired 22 | * password 23 | */ 24 | USER_EXPLAINED, 25 | /** 26 | * Internal failure during the security processing which means that security 27 | * product or the service are not configured properly 28 | */ 29 | INTERNAL, 30 | /** 31 | * errno2 value is required to understand the cause of the failure 32 | */ 33 | ERRNO2_REQUIRED 34 | } 35 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformReturned.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | import java.io.IOException; 13 | import java.io.ObjectInputStream; 14 | import java.io.ObjectOutputStream; 15 | import java.io.Serializable; 16 | 17 | import lombok.Builder; 18 | import lombok.Data; 19 | 20 | /** 21 | * More details about the z/OS security call results. 22 | *

23 | * See also: 24 | * https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformReturned.html 25 | */ 26 | @Data 27 | @Builder 28 | public class PlatformReturned implements Serializable { 29 | 30 | private static final long serialVersionUID = -2699057722238941755L; 31 | 32 | private boolean success; 33 | private int rc; 34 | private int errno; 35 | private int errno2; 36 | private String errnoMsg; 37 | private String stringRet; 38 | private transient Object objectRet; 39 | 40 | private void readObject(ObjectInputStream ois) throws IOException { 41 | success = ois.readBoolean(); 42 | rc = ois.readInt(); 43 | errno = ois.readInt(); 44 | errno2 = ois.readInt(); 45 | errnoMsg = ois.readUTF(); 46 | stringRet = ois.readUTF(); 47 | objectRet = this; 48 | } 49 | 50 | private void writeObject(ObjectOutputStream oos) throws IOException { 51 | oos.writeBoolean(success); 52 | oos.writeInt(rc); 53 | oos.writeInt(errno); 54 | oos.writeInt(errno2); 55 | oos.writeUTF(errnoMsg); 56 | oos.writeUTF(stringRet); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | /** 13 | * Interface to z/OS thread-level information. 14 | * 15 | * It is inspired by 16 | * https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformThread.html 17 | * class. But it provides interface instead of class with static methods so 18 | * non-z/OS implementation of this inteface can be created. 19 | */ 20 | public interface PlatformThread { 21 | /** 22 | * @return User ID associated with the current thread. 23 | */ 24 | String getUserName(); 25 | } 26 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/PlatformUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | /** 13 | * Interface to do z/OS user authentication. 14 | * 15 | * It is inspired by 16 | * https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.zsecurity.api.80.doc/com.ibm.os390.security/com/ibm/os390/security/PlatformUser.html 17 | * class. But it provides interface instead of class with static methods so 18 | * non-z/OS implementation of this interface can be created. 19 | */ 20 | public interface PlatformUser { 21 | /** 22 | * Authenticates an user. 23 | * 24 | * @return If successful, a null object is returned. If not successful an instance of 25 | * the PlatformReturned class is returned. 26 | */ 27 | PlatformReturned authenticate(String userid, String password); 28 | } 29 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public class SafConstants { 13 | private SafConstants() { 14 | // no instances 15 | } 16 | 17 | public static final String CLASS_FACILITY = "FACILITY"; 18 | public static final String BPX_SERVER = "BPX.SERVER"; 19 | } 20 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public class SafPlatformError extends RuntimeException { 13 | private static final long serialVersionUID = 1920433542069453114L; 14 | 15 | public SafPlatformError(Throwable e) { 16 | super(e); 17 | } 18 | 19 | public SafPlatformError(String message, Exception e) { 20 | super(message, e); 21 | } 22 | 23 | public SafPlatformError(String message) { 24 | super(message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | import java.lang.reflect.InvocationTargetException; 13 | 14 | public class SafPlatformThread implements PlatformThread { 15 | 16 | @Override 17 | public String getUserName() { 18 | try { 19 | return (String) Class.forName("com.ibm.os390.security.PlatformThread").getMethod("getUserName") 20 | .invoke(null); 21 | 22 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException 23 | | SecurityException | ClassNotFoundException e) { 24 | throw new SafPlatformError(e.getMessage(), e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafPlatformUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | import java.lang.reflect.InvocationTargetException; 13 | 14 | public class SafPlatformUser implements PlatformUser { 15 | private final PlatformClassFactory platformClassFactory; 16 | 17 | public SafPlatformUser(PlatformClassFactory platformClassFactory) { 18 | this.platformClassFactory = platformClassFactory; 19 | } 20 | 21 | @Override 22 | public PlatformReturned authenticate(String userid, String password) { 23 | if ((password == null) || password.isEmpty()) { 24 | return PlatformReturned.builder().success(false).rc(0).errno(PlatformPwdErrno.EINVAL.errno).errno2(PlatformErrno2.ERRNO2_BASE | PlatformErrno2.JRPasswordLenError.errno2).build(); 25 | } 26 | try { 27 | Object safReturned = platformClassFactory.getPlatformUserClass() 28 | .getMethod("authenticate", String.class, String.class) 29 | .invoke(platformClassFactory.getPlatformUser(), userid, password); 30 | if (safReturned == null) { 31 | return null; 32 | } else { 33 | return platformClassFactory.convertPlatformReturned(safReturned); 34 | } 35 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException 36 | | SecurityException | ClassNotFoundException | NoSuchFieldException e) { 37 | throw new SafPlatformError(e.getMessage(), e); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/platform/SafUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | import org.zowe.commons.zos.ZosUtils; 13 | import org.zowe.commons.zos.security.jni.Secur; 14 | 15 | public class SafUtils { 16 | 17 | private static final SetApplid SECUR; 18 | 19 | static { 20 | if (ZosUtils.isRunningOnZos()) { 21 | SECUR = new SetApplid() { 22 | 23 | private final Secur secur = new Secur(); 24 | 25 | @Override 26 | public int setApplid(String applid) { 27 | return secur.setApplid(applid); 28 | } 29 | 30 | }; 31 | } else { 32 | SECUR = applId -> 0; 33 | } 34 | } 35 | 36 | /** 37 | * Sets the APPLID for the current thread so the PlatformUser.authenticate can 38 | * use PassTickets for the provide APPLID. 39 | *

40 | * The APPLID can be changed but not unset. 41 | * 42 | * @param applid The APPLID to be set. Up to 8 characters. 43 | */ 44 | public static void setThreadApplid(String applid) { 45 | if ((applid == null) || applid.isEmpty()) { 46 | return; 47 | } 48 | 49 | SECUR.setApplid(applid); 50 | } 51 | 52 | private interface SetApplid { 53 | 54 | int setApplid(String applId); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/service/AccessControlError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.service; 11 | 12 | import org.zowe.commons.zos.security.platform.PlatformReturned; 13 | 14 | public class AccessControlError extends RuntimeException { 15 | private static final long serialVersionUID = -101853226410917728L; 16 | private final PlatformReturned platformReturned; 17 | 18 | public AccessControlError(String message, PlatformReturned platformReturned) { 19 | super(message); 20 | this.platformReturned = platformReturned; 21 | } 22 | 23 | public PlatformReturned getPlatformReturned() { 24 | return platformReturned; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/service/SecurityRequestFailed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.service; 11 | 12 | import lombok.Getter; 13 | 14 | public class SecurityRequestFailed extends RuntimeException { 15 | private static final long serialVersionUID = 6832104396884487813L; 16 | 17 | @Getter 18 | private final String module; 19 | @Getter 20 | private final int function; 21 | @Getter 22 | private final int errno; 23 | 24 | public SecurityRequestFailed(String module, int function, int errno, Throwable cause) { 25 | super(String.format("Platform security request has failed: module=%s, function=%d, errno=%d", module, function, 26 | errno), cause); 27 | this.module = module; 28 | this.function = function; 29 | this.errno = errno; 30 | } 31 | 32 | public SecurityRequestFailed(String module, int function, int errno) { 33 | this(module, function, errno, null); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/CallInThreadLevelSecurityEnvironmentByDaemon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.thread; 11 | 12 | import java.util.concurrent.Callable; 13 | 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.util.Assert; 16 | import org.zowe.commons.zos.security.service.PlatformSecurityService; 17 | 18 | public final class CallInThreadLevelSecurityEnvironmentByDaemon implements Callable { 19 | private final PlatformSecurityService service; 20 | private final Callable callable; 21 | private final Authentication authentication; 22 | 23 | public CallInThreadLevelSecurityEnvironmentByDaemon(PlatformSecurityService service, Callable callable, 24 | Authentication authentication) { 25 | Assert.notNull(service, "service cannot be null"); 26 | Assert.notNull(callable, "callable cannot be null"); 27 | Assert.notNull(authentication, "authentication cannot be null"); 28 | this.service = service; 29 | this.callable = callable; 30 | this.authentication = authentication; 31 | } 32 | 33 | @Override 34 | public T call() throws Exception { 35 | createSecurityEnvironment(); 36 | try { 37 | return callable.call(); 38 | } finally { 39 | service.removeThreadSecurityContext(); 40 | } 41 | } 42 | 43 | private void createSecurityEnvironment() { 44 | service.createThreadSecurityContextByDaemon(authentication.getName(), null); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return callable.toString(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/PlatformThreadLevelSecurity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.thread; 11 | 12 | import org.springframework.security.core.context.SecurityContext; 13 | 14 | import java.util.concurrent.Callable; 15 | 16 | public interface PlatformThreadLevelSecurity { 17 | Runnable wrapRunnableInEnvironmentForAuthenticatedUser(Runnable runnable); 18 | 19 | Runnable wrapRunnableInEnvironment(Runnable runnable, SecurityContext authentication); 20 | 21 | Callable wrapCallableInEnvironmentForAuthenticatedUser(Callable runnable); 22 | 23 | Callable wrapCallableInEnvironment(Callable runnable, SecurityContext authentication); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/java/org/zowe/commons/zos/security/thread/RunInThreadLevelSecurityEnvironmentByDaemon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.thread; 11 | 12 | import org.springframework.security.core.Authentication; 13 | import org.springframework.util.Assert; 14 | import org.zowe.commons.zos.security.service.PlatformSecurityService; 15 | 16 | public final class RunInThreadLevelSecurityEnvironmentByDaemon implements Runnable { 17 | private final PlatformSecurityService service; 18 | private final Runnable runnable; 19 | private final Authentication authentication; 20 | 21 | public RunInThreadLevelSecurityEnvironmentByDaemon(PlatformSecurityService service, Runnable runnable, 22 | Authentication authentication) { 23 | Assert.notNull(service, "service cannot be null"); 24 | Assert.notNull(runnable, "runnable cannot be null"); 25 | Assert.notNull(authentication, "authentication cannot be null"); 26 | this.service = service; 27 | this.runnable = runnable; 28 | this.authentication = authentication; 29 | } 30 | 31 | @Override 32 | public void run() { 33 | createSecurityEnvironment(); 34 | try { 35 | runnable.run(); 36 | } finally { 37 | service.removeThreadSecurityContext(); 38 | } 39 | } 40 | 41 | private void createSecurityEnvironment() { 42 | service.createThreadSecurityContextByDaemon(authentication.getName(), null); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return runnable.toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/resources/commons-messages_cs.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | messages.org.zowe.commons.error.invalidMessageKey.text=Interní chyba: Neplatný klíč zprávy '%s'. Další pomoc vám poskytne technická podpora. 12 | messages.org.zowe.commons.error.invalidMessageKey.reason=Toto je interní chyba. Produkt se pokusil získat přístup ke zprávě pomocí klíče, který není definován. 13 | messages.org.zowe.commons.error.invalidMessageKey.action=Další pomoc vám poskytne technická podpora. 14 | 15 | messages.org.zowe.commons.rest.notFound.text=Služba nemůže najít požadovaný zdroj. 16 | messages.org.zowe.commons.service.started.text='%s' se spustila za %.3f sekund 17 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/main/resources/lib/README.md: -------------------------------------------------------------------------------- 1 | # `resources/lib` folder 2 | 3 | This folder is a placeholder for `.so` files that are z/OS shared object libraries. 4 | 5 | Zowe GitHub repositories cannot contain binary files so you need to build it using 6 | `zowe-api-dev zosbuild` command. 7 | 8 | This folder `resources/lib` is packaged into the JAR file. `.so` files in the JAR file 9 | can be extracted to regular files using `LibsExtractor`. 10 | These files need to be executable and program-controlled on z/OS in order to be loadable by Java. 11 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/AccentStrippingPatternLayerEncoderTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.mockito.Mockito.mock; 14 | import static org.mockito.Mockito.when; 15 | 16 | import org.junit.Test; 17 | 18 | import ch.qos.logback.classic.spi.ILoggingEvent; 19 | import ch.qos.logback.core.Layout; 20 | 21 | public class AccentStrippingPatternLayerEncoderTests { 22 | @Test 23 | public void testWrapRunnableInEnvironmentForAuthenticatedUser() { 24 | AccentStrippingPatternLayerEncoder encoder = new AccentStrippingPatternLayerEncoder(); 25 | Layout layout = mock(Layout.class); 26 | ILoggingEvent event = null; 27 | when(layout.doLayout(event)).thenReturn("Příliš žluťoučký kůň úpěl ďábelské ódy"); 28 | encoder.overrideLayout(layout); 29 | encoder.setStripAccents(true); 30 | byte[] bytes = encoder.encode(event); 31 | assertEquals("Prilis zlutoucky kun upel dabelske ody", new String(bytes)); 32 | encoder.setStripAccents(false); 33 | byte[] bytes2 = encoder.encode(event); 34 | assertEquals("Příliš žluťoučký kůň úpěl ďábelské ódy", new String(bytes2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/apiml/ApimlIntegrationFailureDetectorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.apiml; 11 | 12 | import ch.qos.logback.classic.Level; 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.classic.LoggerContext; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import org.junit.Test; 17 | import org.zowe.commons.spring.SpringContext; 18 | 19 | import javax.net.ssl.SSLHandshakeException; 20 | import javax.net.ssl.SSLPeerUnverifiedException; 21 | 22 | import static org.junit.Assert.*; 23 | 24 | public class ApimlIntegrationFailureDetectorTests { 25 | 26 | @Test 27 | public void ApiMediationClientErrorIsDetected() { 28 | new SpringContext().setApplicationContext(null); 29 | ApimlIntegrationFailureDetector detector = new ApimlIntegrationFailureDetector(); 30 | assertEquals(FilterReply.NEUTRAL, 31 | detector.decide(null, null, Level.INFO, null, null, new NullPointerException())); 32 | assertFalse(detector.reportFatalError(Level.INFO, new NullPointerException())); 33 | assertTrue(detector.reportFatalError(Level.ERROR, new SSLHandshakeException("test"))); 34 | assertTrue(detector.reportFatalError(Level.ERROR, new SSLPeerUnverifiedException("test"))); 35 | 36 | LoggerContext ctx = new LoggerContext(); 37 | Logger logger = ctx.getLogger("com.netflix.DiscoveryClient"); 38 | logger.setLevel(Level.ERROR); 39 | assertEquals(FilterReply.DENY, detector.decide(null, logger, Level.ERROR, 40 | null, null, new NullPointerException("test"))); 41 | 42 | logger = ctx.getLogger("com.netflix.RedirectingEurekaHttpClient"); 43 | assertEquals(FilterReply.DENY, detector.decide(null, logger, Level.ERROR, 44 | null, null, new NullPointerException(null))); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/error/CommonsErrorServiceTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.error; 11 | 12 | import static org.junit.Assert.assertTrue; 13 | 14 | import java.util.Locale; 15 | 16 | import org.junit.Test; 17 | 18 | public class CommonsErrorServiceTests { 19 | @Test 20 | public void returnsReadableMessage() { 21 | assertTrue(CommonsErrorService.get() 22 | .getReadableMessage("org.zowe.commons.apiml.serviceCertificateNotTrusted", "param").contains("param")); 23 | } 24 | 25 | @Test 26 | public void returnsLocalizedMessage() { 27 | assertTrue(CommonsErrorService.get() 28 | .createApiMessage(Locale.forLanguageTag("cs"), "org.zowe.commons.rest.notFound").getMessages().get(0) 29 | .getMessageContent().contains("Služba")); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/rest/response/BasicMessageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.rest.response; 11 | 12 | import org.junit.Test; 13 | 14 | import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; 15 | import static org.junit.jupiter.api.Assertions.assertEquals; 16 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 17 | 18 | public class BasicMessageTest { 19 | private Message getTestErrorMessage() { 20 | return new BasicMessage(MessageType.ERROR, "MAS0001", "Message text."); 21 | } 22 | 23 | private Message getTestInfoMessage() { 24 | return new BasicMessage(MessageType.INFO, "MAS0002", "Message text."); 25 | } 26 | 27 | @Test 28 | public void toReadableText() { 29 | Message message = getTestErrorMessage(); 30 | assertEquals("MAS0001E Message text.", message.toReadableText()); 31 | } 32 | 33 | @Test 34 | public void testHashCode() { 35 | Message message = getTestErrorMessage(); 36 | assertNotEquals(0, message.hashCode()); 37 | } 38 | 39 | @Test 40 | public void testEquals() { 41 | Message message = getTestErrorMessage(); 42 | Message differentMessage = getTestInfoMessage(); 43 | assertEquals(message, message); 44 | assertNotEquals(message, differentMessage); 45 | } 46 | 47 | @Test 48 | public void basicJsonFormat() { 49 | assertThatJson(getTestErrorMessage()).whenIgnoringPaths("messageInstanceId").isEqualTo("{\n" + " \"messageType\" : \"ERROR\",\n" 50 | + " \"messageNumber\" : \"MAS0001\",\n" + " \"messageContent\" : \"Message text.\"\n" + "}"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/DefaultMessageSourceTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import static org.junit.Assert.assertTrue; 13 | 14 | import org.junit.Test; 15 | import org.springframework.mock.env.MockEnvironment; 16 | import org.zowe.commons.error.CommonsErrorService; 17 | 18 | public class DefaultMessageSourceTests { 19 | @Test 20 | public void defaultMessageSourceContainsPortAndServiceName() { 21 | DefaultMessageSource defaultMessageSource = new DefaultMessageSource(CommonsErrorService.get(), new MockEnvironment().withProperty("apiml.service.serviceId", "testservice").withProperty("server.port", "1234")); 22 | defaultMessageSource.onApplicationEvent(null); 23 | assertTrue(CommonsErrorService.get().getDefaultMessageSource().endsWith(":1234:testservice")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/EnableEurekaLoggingTimerTaskTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import static org.junit.Assert.assertTrue; 13 | import static org.zowe.commons.spring.EnableEurekaLoggingTimerTask.EUREKA_LOGGER_NAMES; 14 | 15 | import org.junit.Test; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import ch.qos.logback.classic.LoggerContext; 19 | 20 | public class EnableEurekaLoggingTimerTaskTests { 21 | SpringContext context = new SpringContext(); 22 | 23 | @Test 24 | public void enableEurekaLoggingTimerTaskDoesNotFail() { 25 | LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); 26 | 27 | new EnableEurekaLoggingTimerTask().run(); 28 | for (String name : EUREKA_LOGGER_NAMES) { 29 | assertTrue(loggerContext.getLogger(name).isErrorEnabled()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/spring/SpringContextTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.spring; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | import org.junit.Test; 15 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; 16 | import org.springframework.context.ApplicationContext; 17 | import org.springframework.context.support.GenericApplicationContext; 18 | 19 | public class SpringContextTests { 20 | SpringContext context = new SpringContext(); 21 | 22 | @Test 23 | public void getApplicationContextReturnsSetContext() { 24 | try { 25 | ApplicationContext newContext = new GenericApplicationContext(); 26 | context.setApplicationContext(newContext); 27 | assertEquals(newContext, SpringContext.getApplicationContext()); 28 | } finally { 29 | context.setApplicationContext(null); 30 | } 31 | } 32 | 33 | @Test(expected = NoSuchBeanDefinitionException.class) 34 | public void getBeanFailsForNonExistentBean() { 35 | try { 36 | GenericApplicationContext newContext = new GenericApplicationContext(); 37 | newContext.refresh(); 38 | context.setApplicationContext(newContext); 39 | SpringContext.getBean(SpringContext.class); 40 | } finally { 41 | context.setApplicationContext(null); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/BadMockPlatformClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public class BadMockPlatformClassFactory implements PlatformClassFactory { 13 | 14 | @Override 15 | public Class getPlatformUserClass() throws ClassNotFoundException { 16 | return Class.forName("bad"); 17 | } 18 | 19 | @Override 20 | public Class getPlatformReturnedClass() throws ClassNotFoundException { 21 | return Class.forName("bad"); 22 | } 23 | 24 | @Override 25 | public Object getPlatformUser() { 26 | return null; 27 | } 28 | 29 | @Override 30 | public Class getPlatformAccessControlClass() throws ClassNotFoundException { 31 | return Class.forName("bad"); 32 | } 33 | 34 | @Override 35 | public Object getPlatformAccessControl() throws ClassNotFoundException { 36 | return null; 37 | } 38 | 39 | @Override 40 | public PlatformReturned convertPlatformReturned(Object safReturned) throws ClassNotFoundException, 41 | IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/MockPlatformClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.commons.zos.security.platform; 11 | 12 | public class MockPlatformClassFactory implements PlatformClassFactory { 13 | 14 | @Override 15 | public Class getPlatformUserClass() throws ClassNotFoundException { 16 | return MockPlatformUser.class; 17 | } 18 | 19 | @Override 20 | public Class getPlatformReturnedClass() throws ClassNotFoundException { 21 | return PlatformReturned.class; 22 | } 23 | 24 | @Override 25 | public Object getPlatformUser() { 26 | return new MockPlatformUser(); 27 | } 28 | 29 | @Override 30 | public Class getPlatformAccessControlClass() throws ClassNotFoundException { 31 | return MockPlatformAccessControl.class; 32 | } 33 | 34 | @Override 35 | public Object getPlatformAccessControl() throws ClassNotFoundException { 36 | return new MockPlatformAccessControl(); 37 | } 38 | 39 | @Override 40 | public PlatformReturned convertPlatformReturned(Object safReturned) throws ClassNotFoundException, 41 | IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { 42 | return (PlatformReturned) safReturned; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/java/org/zowe/commons/zos/security/platform/PlatformErnnoTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | 11 | package org.zowe.commons.zos.security.platform; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | import org.junit.Test; 16 | 17 | public class PlatformErnnoTests { 18 | @Test 19 | public void returnsErrno2ValueFromLongHexValue() { 20 | assertEquals(PlatformErrno2.JRSAFResourceUndefined, PlatformErrno2.valueOfErrno(0x93800CF)); 21 | } 22 | 23 | @Test 24 | public void returnsAckErrnoValueFromInt() { 25 | assertEquals(PlatformAckErrno.ESRCH, PlatformAckErrno.valueOfErrno(143)); 26 | } 27 | 28 | @Test 29 | public void returnsTlsErrnoValueFromInt() { 30 | assertEquals(PlatformTlsErrno.ESRCH, PlatformTlsErrno.valueOfErrno(143)); 31 | } 32 | 33 | @Test 34 | public void returnsPwdErrnoValueFromInt() { 35 | assertEquals(PlatformPwdErrno.ESRCH, PlatformPwdErrno.valueOfErrno(143)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/resources/test-duplicate-messages.yml: -------------------------------------------------------------------------------- 1 | messages: 2 | - key: org.zowe.commons.test.noArguments 3 | number: CSC0001 4 | type: ERROR 5 | text: "No arguments message" 6 | 7 | - key: org.zowe.commons.test.noArguments 8 | number: CSC0001 9 | type: ERROR 10 | text: "No arguments message" 11 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/resources/test-messages.yml: -------------------------------------------------------------------------------- 1 | messages: 2 | - key: org.zowe.commons.test.noArguments 3 | number: CSC0001 4 | type: ERROR 5 | text: "No arguments message" 6 | 7 | - key: org.zowe.commons.test.invalidParameterFormat 8 | number: TST0001 9 | type: INFO 10 | text: "Test message - expects decimal number %d" 11 | 12 | - key: org.zowe.commons.test.reason 13 | number: CSC0002 14 | type: ERROR 15 | text: "No arguments message" 16 | reason: Reason 17 | 18 | - key: org.zowe.commons.test.action 19 | number: CSC0003 20 | type: ERROR 21 | text: "No arguments message" 22 | action: Action 23 | 24 | - key: org.zowe.commons.test.reasonAndAction 25 | number: CSC0004 26 | type: ERROR 27 | text: "No arguments message" 28 | reason: Reason 29 | action: Action 30 | 31 | - key: org.zowe.commons.test.component 32 | number: CSC0005 33 | type: ERROR 34 | text: "No arguments message" 35 | component: zowe.sdk.commons.test 36 | 37 | - key: org.zowe.commons.test.localized 38 | number: CSC0006 39 | type: INFO 40 | text: "Localized message" 41 | component: "Component" 42 | 43 | - key: org.zowe.commons.test.parameters 44 | number: CSC0007 45 | type: INFO 46 | text: "Test message - expects decimal number %2$d and %1$s" 47 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/resources/test-messages_cs.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | messages.org.zowe.commons.test.localized.text: Lokalizovaná zpráva 12 | messages.org.zowe.commons.test.localized.reason: Důvod 13 | messages.org.zowe.commons.test.localized.action: Akce 14 | messages.org.zowe.commons.test.localized.component: Komponenta 15 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/resources/test-saf-invalid.yml: -------------------------------------------------------------------------------- 1 | # This file is used by the SafPlatformAccessControlTests class for testing how the invalid definition is handled 2 | # `WRONG_LEVEL` is an invalid access level 3 | safAccess: 4 | ZOWE: 5 | RESOURCE: 6 | WRONG_LEVEL: 7 | - ZOWE 8 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/src/test/resources/test-saf.yml: -------------------------------------------------------------------------------- 1 | # This file is used by the MockPlatformAccessControl class for testing and when the service is running outside of z/OS 2 | # It defines what are the access levels for SAF resources and users 3 | # 4 | # There are to special values of access level: 5 | # - `FAILURE` - the check request will fail with an internal error 6 | # - `NONE` - there is no access to the resource but the resource is defined 7 | # 8 | # This file is stored in `src/test/resources/test-saf.yml` which means that it will be used by the unit tests only. 9 | # 10 | safAccess: 11 | FACILITY: # class 12 | BPX.SERVER: # resource 13 | READ: # access level 14 | - ZOWE # users 15 | BPX.DAEMON: 16 | UPDATE: 17 | - ZOWE 18 | ZOWE: 19 | SAMPLE.RESOURCE: 20 | UPDATE: 21 | - ZOWE 22 | - ZOWE2 23 | FAILING: 24 | FAILURE: 25 | - ZOWE 26 | - ZOWE2 27 | DENIED: 28 | NONE: 29 | - NONE 30 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/zossrc/jnitools.c: -------------------------------------------------------------------------------- 1 | #define _OPEN_SYS 1 2 | #include 3 | #include 4 | #include "jnitools.h" 5 | 6 | char *jstring_to_ebcdic(JNIEnv *env, jstring jstr) 7 | { 8 | if (jstr == NULL) 9 | { 10 | return NULL; 11 | } 12 | 13 | int len; 14 | jint rc = GetStringPlatformLength(env, jstr, &len, "IBM-1047"); 15 | if (rc != 0) 16 | { 17 | return NULL; 18 | } 19 | 20 | char *str = __malloc31(len); 21 | rc = GetStringPlatform(env, jstr, str, len, "IBM-1047"); 22 | if (rc != 0) 23 | { 24 | free(str); 25 | return NULL; 26 | } 27 | 28 | return str; 29 | } 30 | 31 | void free_if_not_null(void *ptr) 32 | { 33 | if (ptr != NULL) 34 | { 35 | free(ptr); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/zossrc/jnitools.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *jstring_to_ebcdic(JNIEnv *env, jstring jstr); 4 | 5 | void free_if_not_null(void *ptr); 6 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/zossrc/makefile: -------------------------------------------------------------------------------- 1 | # makefile boilerplate to build the JNI implementation (C++), metal C code, and 2 | # bind into a "shared object" called at REST API runtime via the /wto endpoint 3 | # 4 | # This program and the accompanying materials are made available and may be used, at your option, under either: 5 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 6 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 9 | # 10 | # Copyright Contributors to the Zowe Project. 11 | 12 | CXX=xlc++ 13 | CC=xlc 14 | ASM=as 15 | 16 | MTL_OPTS=metal,\ 17 | langlvl(extended),\ 18 | sscom,\ 19 | nolongname,\ 20 | inline,\ 21 | genasm,\ 22 | inlrpt,\ 23 | csect,\ 24 | nose,\ 25 | lp64,\ 26 | list,\ 27 | warn64,\ 28 | optimize(2),\ 29 | list,\ 30 | showinc,\ 31 | showmacro,\ 32 | source,\ 33 | aggregate 34 | 35 | MTL_FLAGS=-S -W "c,$(MTL_OPTS)" 36 | 37 | MACLIBS=-ISYS1.MACLIB \ 38 | -ICBC.SCCNSAM 39 | 40 | MTL_HEADERS=-I/usr/include/metal 41 | 42 | DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended),dll,xplink,exportall" \ 43 | -qsearch=$(JAVA_HOME)/include \ 44 | -qsource \ 45 | -g \ 46 | -c 47 | 48 | DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" \ 49 | -g \ 50 | -qsource 51 | 52 | ASM_FLAGS=-mrent 53 | 54 | SIDEDECKPATH = $(JAVA_HOME)/bin/j9vm 55 | SIDEDECK = libjvm 56 | 57 | PREFIX := "../lib/" 58 | 59 | LIB_SECUR = "libzowe-commons-secur.so" 60 | 61 | all: $(LIB_SECUR) 62 | 63 | install: 64 | mkdir -p $(PREFIX) 65 | cp -vp *.so $(PREFIX) 66 | ls -E $(PREFIX) 67 | 68 | $(LIB_SECUR): secur.o jnitools.o 69 | $(CXX) $(DLL_BND_FLAGS) -o $@ $(SIDEDECKPATH)/$(SIDEDECK).x jnitools.o $^ > $*.bind.lst 70 | extattr +p $@ 71 | 72 | secur.o: secur.c 73 | $(CC) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ 74 | 75 | jnitools.o: jnitools.c 76 | $(CC) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ 77 | 78 | clean: 79 | rm *.o 80 | rm *.lst 81 | rm *.x 82 | rm *.so 83 | rm *.dbg 84 | rm *.s 85 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/zossrc/secur.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_zowe_commons_zos_security_jni_Secur */ 4 | 5 | #ifndef _Included_org_zowe_commons_zos_security_jni_Secur 6 | #define _Included_org_zowe_commons_zos_security_jni_Secur 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: org_zowe_commons_zos_security_jni_Secur 12 | * Method: createSecurityEnvironment 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_createSecurityEnvironment 16 | (JNIEnv *, jobject, jstring, jstring, jstring); 17 | 18 | /* 19 | * Class: org_zowe_commons_zos_security_jni_Secur 20 | * Method: createSecurityEnvironmentByDaemon 21 | * Signature: (Ljava/lang/String;Ljava/lang/String;)I 22 | */ 23 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_createSecurityEnvironmentByDaemon 24 | (JNIEnv *, jobject, jstring, jstring); 25 | 26 | /* 27 | * Class: org_zowe_commons_zos_security_jni_Secur 28 | * Method: removeSecurityEnvironment 29 | * Signature: ()I 30 | */ 31 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_removeSecurityEnvironment 32 | (JNIEnv *, jobject); 33 | 34 | /* 35 | * Class: org_zowe_commons_zos_security_jni_Secur 36 | * Method: getLastErrno2 37 | * Signature: ()I 38 | */ 39 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_getLastErrno2 40 | (JNIEnv *, jobject); 41 | 42 | /* 43 | * Class: org_zowe_commons_zos_security_jni_Secur 44 | * Method: setApplid 45 | * Signature: (Ljava/lang/String;)I 46 | */ 47 | JNIEXPORT jint JNICALL Java_org_zowe_commons_zos_security_jni_Secur_setApplid 48 | (JNIEnv *, jobject, jstring); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | #endif 54 | -------------------------------------------------------------------------------- /zowe-rest-api-commons-spring/zowe-api.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zowe REST API Commons Library for Spring", 3 | "zosSourcesDir": "zossrc", 4 | "buildCommand": "make && make install", 5 | "buildFiles": { 6 | "libzowe-commons-secur.so": "src/main/resources/lib/libzowe-commons-secur.so" 7 | }, 8 | "defaultDirName": "zowe-rest-api-commons-spring", 9 | "defaultHlqSegment": "ZOWE.SAMPLAPI.COMMONS", 10 | "zfsMegabytes": 10 11 | } 12 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .gradle 3 | build/ 4 | gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/.licence/Apache-or-EPL-License-Header.txt: -------------------------------------------------------------------------------- 1 | This program and the accompanying materials are made available and may be used, at your option, under either: 2 | * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 3 | * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 6 | 7 | Copyright Contributors to the Zowe Project. -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12 -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/config/local/local.yml: -------------------------------------------------------------------------------- 1 | # Configuration for running the locally on your workstation 2 | # It overrides service defaults provided in src/main/resources/local.yml 3 | 4 | spring.profiles.active: https 5 | 6 | server: 7 | address: 0.0.0.0 8 | port: 10090 9 | ssl: 10 | keyAlias: localhost 11 | keyPassword: password 12 | keyStore: config/local/keystore.p12 # For bootRun / CI 13 | # keyStore: zowe-rest-api-sample-kotlin-spring/config/local/keystore.p12 # For IDEA 14 | keyStorePassword: password 15 | keyStoreType: PKCS12 16 | trustStore: config/local/truststore.p12 # For bootRun / CI 17 | # trustStore: zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12 # For IDEA 18 | trustStorePassword: password 19 | trustStoreType: PKCS12 20 | 21 | apiml: 22 | service: 23 | serviceId: zowekotlinsample 24 | hostname: localhost 25 | serviceIpAddress: 127.0.0.1 26 | port: ${server.port} 27 | baseUrl: ${apiml.service.scheme}://${apiml.service.hostname}:${apiml.service.port} 28 | discoveryServiceUrls: 29 | - https://localhost:10011/eureka 30 | ssl: 31 | enabled: true 32 | verifySslCertificatesOfServices: true 33 | ciphers: ${server.ssl.ciphers} 34 | protocol: ${server.ssl.protocol} 35 | enabled-protocols: ${server.ssl.protocol} 36 | keyStoreType: ${server.ssl.keyStoreType} 37 | trustStoreType: ${server.ssl.trustStoreType} 38 | keyAlias: ${server.ssl.keyAlias} 39 | keyPassword: ${server.ssl.keyPassword} 40 | keyStore: ${server.ssl.keyStore} 41 | keyStorePassword: ${server.ssl.keyStorePassword} 42 | trustStore: ${server.ssl.trustStore} 43 | trustStorePassword: ${server.ssl.trustStorePassword} 44 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-kotlin-spring/config/local/truststore.p12 -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/config/zos/zos.yml.hbs: -------------------------------------------------------------------------------- 1 | # Configuration for running the on z/OS 2 | # It overrides service defaults provided in src/main/resources/application.yml 3 | 4 | spring.profiles.active: https 5 | 6 | 7 | server: 8 | address: 0.0.0.0 9 | port: {{port}} 10 | ssl: 11 | keyAlias: localhost 12 | keyPassword: password 13 | keyStore: etc/keystore.p12 14 | keyStorePassword: password 15 | keyStoreType: PKCS12 16 | trustStore: etc/truststore.p12 17 | trustStorePassword: password 18 | trustStoreType: PKCS12 19 | 20 | apiml: 21 | service: 22 | serviceId: zowekotlinsample 23 | hostname: localhost 24 | ipAddress: 127.0.0.1 25 | discoveryServiceUrls: 26 | - https://localhost:10021/eureka 27 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | 3 | # Repository URL for getting Zowe artifacts: 4 | zoweArtifactoryRepository=https://zowe.jfrog.io/zowe/libs-release 5 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/gradle/bootstrap/bootstrap-gradlew.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist gradle/wrapper/gradle-wrapper.jar ( 4 | echo Gradle wrapper not found. Attempting to download... 5 | powershell -Command "& {wget https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar -OutFile gradle/wrapper/gradle-wrapper.jar}" 6 | IF ERRORLEVEL 1 ( 7 | echo Gradle wrapper download failed. Bootstrap failed. 8 | ) ELSE ( 9 | echo Gradle wrapper download success. Bootstrap complete. 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/gradle/bootstrap/bootstrap-gradlew.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ ! -f gradle/wrapper/gradle-wrapper.jar ]; then 4 | echo "Gradle wrapper not found. Attempting to download..." 5 | curl --silent --output gradle/wrapper/gradle-wrapper.jar \ 6 | https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar 7 | rc=$?; 8 | if [ $rc != 0 ]; then 9 | echo "Gradle wrapper download failed. Bootstrap failed." 10 | exit 1 11 | else 12 | echo "Gradle wrapper download success. Bootstrap complete." 13 | exit 0 14 | fi 15 | else 16 | exit 0 17 | fi 18 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "zowe-rest-api-sample-kotlin-spring" 2 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/integrationTest/kotlin/org/zowe/sample/kotlin/apiservice/greeting/GreetingControllerIntegrationTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice.greeting 11 | 12 | import io.restassured.module.kotlin.extensions.Given 13 | import io.restassured.module.kotlin.extensions.Then 14 | import io.restassured.module.kotlin.extensions.When 15 | import org.apache.http.HttpHeaders 16 | import org.hamcrest.Matchers.equalTo 17 | import org.junit.jupiter.api.Test 18 | import org.zowe.sample.kotlin.apiservice.test.IntegrationTest 19 | import java.util.* 20 | 21 | const val GREETING_ENDPOINT = "/api/v1/greeting" 22 | 23 | class GreetingControllerIntegrationTests : IntegrationTest() { 24 | 25 | @Test 26 | fun `when greeting endpoint is called in English, Hello world is returned`() { 27 | Given { 28 | header(HttpHeaders.ACCEPT_LANGUAGE, Locale.US) 29 | } When { 30 | get(GREETING_ENDPOINT) 31 | } Then { 32 | statusCode(200) 33 | body("content", equalTo("Hello, world!")) 34 | } 35 | } 36 | 37 | @Test 38 | fun `when greeting endpoint is called in Czech, Ahoj svete is returned`() { 39 | Given { 40 | header(HttpHeaders.ACCEPT_LANGUAGE, "cs-CZ") 41 | } When { 42 | get(GREETING_ENDPOINT) 43 | } Then { 44 | statusCode(200) 45 | body("content", equalTo("Ahoj, světe!")) 46 | } 47 | } 48 | 49 | @Test 50 | fun `when greeting endpoint is called with the name parameter, Hello Jirka is returned`() { 51 | Given { 52 | header(HttpHeaders.ACCEPT_LANGUAGE, Locale.US) 53 | param("name", "Jirka") 54 | } When { 55 | get(GREETING_ENDPOINT) 56 | } Then { 57 | statusCode(200) 58 | body("content", equalTo("Hello, Jirka!")) 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/integrationTest/kotlin/org/zowe/sample/kotlin/apiservice/test/IntegrationTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice.test 11 | 12 | import org.junit.jupiter.api.BeforeAll 13 | import org.junit.jupiter.api.TestInstance 14 | 15 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 16 | open class IntegrationTest { 17 | 18 | private val serviceUnderTest = ServiceUnderTest() 19 | 20 | @BeforeAll 21 | fun setup() { 22 | serviceUnderTest.waitUntilIsReady() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/ZoweKotlinApiServiceApplication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice 11 | 12 | import org.springframework.boot.autoconfigure.SpringBootApplication 13 | import org.springframework.boot.runApplication 14 | 15 | @SpringBootApplication 16 | class ZoweRestApiSampleKotlinSpringApplication 17 | 18 | fun main(args: Array) { 19 | runApplication(*args) 20 | } 21 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/config/ApplicationConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice.config 11 | 12 | import org.springframework.context.annotation.ComponentScan 13 | import org.springframework.context.annotation.Configuration 14 | import org.springframework.context.annotation.FilterType 15 | import org.zowe.apiml.enable.EnableApiDiscovery 16 | 17 | @Configuration 18 | @EnableApiDiscovery 19 | @ComponentScan( 20 | basePackages = ["org.zowe.commons.spring"], 21 | useDefaultFilters = false, 22 | includeFilters = [ComponentScan.Filter(type = FilterType.REGEX, 23 | pattern = [ 24 | "org.zowe.commons.spring.CustomRestExceptionHandler", 25 | "org.zowe.commons.spring.WebConfig" 26 | ] 27 | )] 28 | ) 29 | class ApplicationConfig { 30 | } -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/config/WebSecurityConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice.config 11 | 12 | import org.springframework.context.annotation.Configuration 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity 14 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter 15 | 16 | @Configuration 17 | class WebSecurityConfig : WebSecurityConfigurerAdapter() { 18 | 19 | override fun configure(http: HttpSecurity) { 20 | http.authorizeRequests().anyRequest().permitAll() 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/kotlin/org/zowe/sample/kotlin/apiservice/greeting/Greeting.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.kotlin.apiservice.greeting 11 | 12 | import io.swagger.v3.oas.annotations.media.Schema 13 | 14 | data class Greeting( 15 | 16 | @Schema(description = "Generated sequence ID of the message") 17 | val id: Long, 18 | 19 | @Schema(description = "The greeting message") 20 | val content: String, 21 | 22 | @Schema(description = "The locale language tag used for this message") 23 | val languageTag: String 24 | ) 25 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Hello 12 | GreetingController.greetingTemplate={0}, {1}\! 13 | GreetingController.world=world 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_cs.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Ahoj 12 | GreetingController.greetingTemplate={0}, {1}\! 13 | GreetingController.world=světe 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_en.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/src/main/resources/messages_es.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Hola 12 | GreetingController.greetingTemplate=¡{0}, {1}\! 13 | GreetingController.world=mundo 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-kotlin-spring/zowe-api.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zowe Kotlin Sample REST API", 3 | "zosSourcesDir": "zossrc", 4 | "buildCommand": "make && make install", 5 | "buildFiles": { 6 | }, 7 | "deployment": { 8 | "files": { 9 | "build/libs/zowe-rest-api-sample-kotlin-spring-0.0.1-SNAPSHOT.jar": { 10 | "target": "bin/zowe-rest-api-sample-kotlin-spring.jar", 11 | "postSoUpdateCommands": [ 12 | ], 13 | "binary": true 14 | } 15 | } 16 | }, 17 | "shellStartCommand": "$JAVA -Djava.library.path=\"./lib:${LIBPATH}\" -Xquickstart -jar bin/zowe-rest-api-sample-kotlin-spring.jar --spring.config.additional-location=file:etc/zos.yml", 18 | "jobTemplatePath": "src/main/jcl/template.jcl", 19 | "jobPath": "build/api.jcl", 20 | "defaultDirName": "zowe-rest-api-sample-kotlin-spring", 21 | "defaultHlqSegment": "ZOWE.KOTLIN.SAMPLAPI", 22 | "zfsMegabytes": 100, 23 | "configurations": { 24 | "zos": { 25 | "files": { 26 | "config/zos/zos.yml.hbs": { 27 | "target": "etc/zos.yml", 28 | "binary": true, 29 | "template": true 30 | }, 31 | "config/local/keystore.p12": { 32 | "target": "etc/keystore.p12", 33 | "binary": true 34 | }, 35 | "config/local/truststore.p12": { 36 | "target": "etc/truststore.p12", 37 | "binary": true 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | max_line_length = 120 11 | 12 | [*.md] 13 | max_line_length = off 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | /bin/ 4 | gradle/wrapper/gradle-wrapper.jar 5 | .DS_Store 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /out/ 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | 33 | deploy/scripts/out 34 | deploy/templates/jcl/out 35 | deploy-config.json5 36 | node_modules 37 | *.so 38 | user-zowe-api.json 39 | lastJob.json 40 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/.licence/Apache-or-EPL-License-Header.txt: -------------------------------------------------------------------------------- 1 | This program and the accompanying materials are made available and may be used, at your option, under either: 2 | * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 3 | * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 6 | 7 | Copyright Contributors to the Zowe Project. -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/config/local/application.yml: -------------------------------------------------------------------------------- 1 | # Configuration for running the locally on your workstation 2 | # It overrides service defaults provided in src/main/resources/application.yml 3 | 4 | spring.profiles.active: https,diag 5 | 6 | logging: 7 | level: 8 | org.zowe.commons.zos.security: DEBUG 9 | 10 | server: 11 | address: 0.0.0.0 12 | port: 10080 13 | ssl: 14 | keyAlias: localhost 15 | keyPassword: password 16 | keyStore: config/local/keystore.p12 # Gradle 17 | # keyStore: zowe-rest-api-sample-spring/config/local/keystore.p12 # IntelliJ 18 | keyStorePassword: password 19 | keyStoreType: PKCS12 20 | trustStore: config/local/truststore.p12 # Gradle 21 | # trustStore: zowe-rest-api-sample-spring/config/local/truststore.p12 # IntelliJ 22 | trustStorePassword: password 23 | trustStoreType: PKCS12 24 | 25 | apiml: 26 | enabled: false 27 | service: 28 | serviceId: zowesample 29 | hostname: localhost 30 | ipAddress: 127.0.0.1 31 | discoveryServiceUrls: 32 | - https://localhost:10011/eureka 33 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/config/local/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/config/local/keystore.p12 -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/config/local/truststore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/config/local/truststore.p12 -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/config/zos/application.yml.hbs: -------------------------------------------------------------------------------- 1 | # Configuration for running the on z/OS 2 | # It overrides service defaults provided in src/main/resources/application.yml 3 | 4 | spring.profiles.active: https,diag,zos 5 | 6 | logging: 7 | level: 8 | org.zowe.commons.zos.security: DEBUG 9 | 10 | server: 11 | address: 0.0.0.0 12 | port: {{port}} 13 | ssl: 14 | keyAlias: localhost 15 | keyPassword: password 16 | keyStore: etc/keystore.p12 17 | keyStorePassword: password 18 | keyStoreType: PKCS12 19 | trustStore: etc/truststore.p12 20 | trustStorePassword: password 21 | trustStoreType: PKCS12 22 | 23 | apiml: 24 | enabled: false 25 | service: 26 | serviceId: zowesample 27 | hostname: localhost 28 | ipAddress: 127.0.0.1 29 | discoveryServiceUrls: 30 | - https://localhost:10011/eureka 31 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/config.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | Java applications that are using Spring Boot have configuration their configuration in the [`application.yml`](/src/main/resources/application.yml) and/or `bootstrap.yml` files. These files are packaged in the JAR file so the user cannot change them. 4 | 5 | There are various ways how these values can be overridden in Spring Boot (external YML file, environment variables, Java System properties). 6 | 7 | The Java System properties are a common way how to provide external configuration options. They are defined using `-D` options for Java. Java System properties can override any configuration. 8 | 9 | The values for Java System properties can be defined in STDENV member of JZOS Batch Launcher for Java started tasks on z/OS. 10 | 11 | When your run the sample application on your computer using `gradlew bootRun` it is using external configuration file [`config/local/application.yml`](/config/local/application.yml). This file contains the value for running on your computer in development mode. 12 | 13 | ## Overriding Properties using CLI 14 | 15 | Let's say that we want to use port `10081` instead of default `10080`. This is set by property `server.port`. 16 | 17 | Running from JAR: 18 | 19 | java -Dserver.port=10081 -jar build/libs/*.jar --spring.config.additional-location=file:./config/local/application.yml 20 | 21 | Running by Gradle: 22 | 23 | ./gradlew bootRun --args='--spring.config.additional-location=file:./config/local/application.yml --server.port=10081' 24 | 25 | ## YAML Files Conventions 26 | 27 | 1. Extension is `.yml` 28 | 2. Indentation is 4 spaces 29 | 3. Property names are using `camelCase` 30 | 4. The `application.yml` bundled into the JAR should contain only valid or typical values for any deployment (ie. it should not contain values that are correct only on your computer) 31 | 32 | ## Resources 33 | 34 | - Intro to Spring YML configuration - 35 | - Full reference - 36 | - For advanced use case of sharing a common YML file - 37 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/greeting-api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/greeting-api.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/hello-endpoint-swaggerui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/hello-endpoint-swaggerui.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/java-started-service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/java-started-service.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/landing-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/landing-page.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/sign-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/sign-in.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/swagger.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/images/vscode-yaml-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zowe/sample-spring-boot-api-service/8032a85601883aace256286d669b8381890e2344/zowe-rest-api-sample-spring/docs/images/vscode-yaml-help.png -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/java-debugging.md: -------------------------------------------------------------------------------- 1 | # Java Debugging 2 | 3 | Option `-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10081,suspend=n` will cause that the service will open a port for remote debugging. The server will start and work as usual. You can connect to the port 10081 from the remote debugger in your IDE. 4 | 5 | Example how to start the sample service with the debugging port: 6 | 7 | ```bash 8 | java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10081,suspend=n -jar build/libs/zowe-rest-api-sample-spring-*.jar --spring.config.additional-location=file:config/local/application.yml 9 | ``` 10 | 11 | ## Debugging on z/OS 12 | 13 | The `zowe-api-dev start` command can insert the right options to the Java on z/OS. 14 | 15 | You need to use option `-d` or `--debugPort` on the `start` command. For example: 16 | 17 | ```bash 18 | zowe-api-dev start --debugPort 10181 19 | ``` 20 | 21 | It can be used with the `--job` option as well: 22 | 23 | ```bash 24 | zowe-api-dev start --job --debugPort 10181 25 | ``` 26 | 27 | Then you can attach to the Java process on z/OS with your debugger. 28 | 29 | If you are using VS Code then you need to change the `hostName` and `port` to your z/OS host and the selected port. 30 | 31 | For example: 32 | 33 | ```json 34 | { 35 | "type": "java", 36 | "name": "Debug (Attach) - Remote", 37 | "request": "attach", 38 | "hostName": "ca32.lvn.broadcom.net", 39 | "port": 10181 40 | } 41 | ``` 42 | 43 | ## Resources 44 | 45 | * [VS Code -Running and Debugging Java](https://code.visualstudio.com/docs/java/java-debugging) 46 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/logging.md: -------------------------------------------------------------------------------- 1 | # Logging 2 | 3 | The default settings of the sample application produce a clean log that contains 4 | only important informational messages from the REST API service user perspective. 5 | Warnings and errors will be displayed. But information for developers are not included by default. 6 | 7 | ## Debug Profile 8 | 9 | In order to see debugging messages that are useful for developers, a debugging profile needs to be enabled. 10 | This profile is called `debug`. 11 | 12 | You can pass it as a command line argument `--spring.profiles.include=debug` when you start the JAR. For example: 13 | 14 | java -jar build/libs/*.jar --spring.config.additional-location=file:./config/local/application.yml --spring.profiles.include=debug 15 | 16 | Or with Gradle: 17 | 18 | ./gradlew bootRun --args='--spring.config.additional-location=file:./config/local/application.yml --spring.profiles.include=debug' 19 | 20 | ## Diagnostics Profile 21 | 22 | There is a profile called `diag` that is enabled in [`config/local/application.yml`](/config/local/application.yml). 23 | 24 | This profile enables all Spring Actuator endpoints that you can see at: 25 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/versioning.md: -------------------------------------------------------------------------------- 1 | # Versioning 2 | 3 | - The version of the sample REST API service is set to `version = '0.0.1-SNAPSHOT'` in `build.gradle` file. You can change it when you develop your REST API service. 4 | 5 | - The version of the SDK commons library `org.zowe:zowe-rest-api-commons-spring` follow [semantic version](https://semver.org/) as it is specified in `build.gradle` in this line: 6 | 7 | ```return "org.zowe:zowe-rest-api-commons-spring:"``` 8 | 9 | - When you download the latest sample ZIP file it will use the latest SDK commons library at that time. 10 | 11 | - If you want to use newer version in future, you need to manually update the version number. Since the current version is `0.x` there can be breaking changes at any time until `1.x` is reached but we will try to keep number of breaking changes at minimum. 12 | 13 | - For SDK developers: The published versions are controlled by Git tags. You do not need to change the versions in the code. 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/docs/web-security.md: -------------------------------------------------------------------------------- 1 | # Web Security 2 | 3 | ## Authentication 4 | 5 | The REST API service is protected by **HTTP Basic authentication** that is connected to `ZosAuthenticationProvider`. 6 | 7 | The REST API endpoints that require HTTP Basic authentication have declare it in the `@ApiOperation` annotation. 8 | This annotation is used only for API documentation. 9 | 10 | ```java 11 | import static org.zowe.sample.apiservice.apidoc.ApiDocConstants.DOC_SCHEME_BASIC_AUTH; 12 | 13 | @ApiOperation(..., authorizations = { @Authorization(value = DOC_SCHEME_BASIC_AUTH) }) 14 | @GetMapping("/greeting") 15 | public Greeting greeting( 16 | ``` 17 | 18 | The real protection by the authentication is configured in `WebSecurityConfig` class: 19 | 20 | ```java 21 | http.authorizeRequests().anyRequest().authenticated(); 22 | ``` 23 | 24 | ## Implementation 25 | 26 | More details are provided at [z/OS Security](zos-security.md). 27 | 28 | ## Future Direction 29 | 30 | The sample and SDK supports only the HTTP Basic authentication at this moment. 31 | HTTP Basic authentication will be always supported since it is the most easiest method supported by all clients. 32 | 33 | In order to support multi-factor authentication, the SDK and sample will support **stateless token-based authentication** in future. 34 | 35 | It will use following services: 36 | 37 | - [Zowe Authentication and Authorization Service](https://github.com/zowe/api-layer/wiki/Zowe-Authentication-and-Authorization-Service) 38 | - possibly other token-based security services such as z/OSMF 39 | 40 | It will be controlled by a configuration property (no or minimal change in Java code will be required). 41 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | 3 | # Repository URL for getting Zowe artifacts: 4 | zoweArtifactoryRepository=https://zowe.jfrog.io/zowe/libs-release 5 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/gradle/bootstrap/bootstrap-gradlew.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist gradle/wrapper/gradle-wrapper.jar ( 4 | echo Gradle wrapper not found. Attempting to download... 5 | powershell -Command "& {wget https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar -OutFile gradle/wrapper/gradle-wrapper.jar}" 6 | IF ERRORLEVEL 1 ( 7 | echo Gradle wrapper download failed. Bootstrap failed. 8 | ) ELSE ( 9 | echo Gradle wrapper download success. Bootstrap complete. 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/gradle/bootstrap/bootstrap-gradlew.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ ! -f gradle/wrapper/gradle-wrapper.jar ]; then 4 | echo "Gradle wrapper not found. Attempting to download..." 5 | curl --silent --output gradle/wrapper/gradle-wrapper.jar \ 6 | https://raw.githubusercontent.com/gradle/gradle/master/gradle/wrapper/gradle-wrapper.jar 7 | rc=$?; 8 | if [ $rc != 0 ]; then 9 | echo "Gradle wrapper download failed. Bootstrap failed." 10 | exit 1 11 | else 12 | echo "Gradle wrapper download success. Bootstrap complete." 13 | exit 0 14 | fi 15 | else 16 | exit 0 17 | fi 18 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/lombok.config: -------------------------------------------------------------------------------- 1 | lombok.addLombokGeneratedAnnotation = true 2 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | rootProject.name = 'zowe-rest-api-sample-spring' 7 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/greeting/GreetingControllerIntegrationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.greeting; 11 | 12 | import static io.restassured.RestAssured.given; 13 | import static io.restassured.RestAssured.when; 14 | import static org.hamcrest.Matchers.containsString; 15 | import static org.hamcrest.Matchers.equalTo; 16 | 17 | import org.junit.Test; 18 | import org.springframework.http.HttpHeaders; 19 | import org.zowe.sample.apiservice.test.IntegrationTests; 20 | 21 | public class GreetingControllerIntegrationTests extends IntegrationTests { 22 | @Test 23 | public void returnsGreeting() throws Exception { 24 | when().get("/api/v1/greeting").then().statusCode(200).body("content", equalTo("Hello, world!")); 25 | } 26 | 27 | @Test 28 | public void failsWithoutAuthentication() throws Exception { 29 | given().auth().none().when().get("/api/v1/greeting").then().statusCode(401) 30 | .headers(HttpHeaders.WWW_AUTHENTICATE, containsString("Basic realm=\"Zowe Sample API Service\"")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/test/IntegrationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.test; 11 | 12 | import org.junit.Before; 13 | 14 | public class IntegrationTests { 15 | protected ServiceUnderTest serviceUnderTest = ServiceUnderTest.getInstance(); 16 | 17 | @Before 18 | public void setup() { 19 | serviceUnderTest.waitUntilIsReady(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/integrationTest/java/org/zowe/sample/apiservice/wto/WtoControllerIntegrationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | import static io.restassured.RestAssured.when; 13 | import static org.hamcrest.Matchers.equalTo; 14 | import static org.hamcrest.Matchers.isEmptyOrNullString; 15 | import static org.hamcrest.Matchers.not; 16 | 17 | import org.junit.Test; 18 | import org.zowe.sample.apiservice.test.IntegrationTests; 19 | 20 | public class WtoControllerIntegrationTests extends IntegrationTests { 21 | @Test 22 | public void returnsWtoMessage() throws Exception { 23 | when().get("/api/v1/wto").then().statusCode(200).body("content", equalTo("Hello, world!")).body("message", 24 | not(isEmptyOrNullString())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/AppNativeLibraries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import org.zowe.commons.zos.NativeLibraries; 16 | 17 | public class AppNativeLibraries implements NativeLibraries { 18 | public static final String SAMPLE_LIBRARY_NAME = "zowe-sample"; 19 | 20 | @Override 21 | public List getNativeLibrariesNames() { 22 | List libraries = new ArrayList<>(); 23 | libraries.add(SAMPLE_LIBRARY_NAME); 24 | return libraries; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/LibsExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import org.zowe.commons.zos.LibExtractor; 16 | import org.zowe.commons.zos.CommonsNativeLibraries; 17 | 18 | public class LibsExtractor { 19 | public static void main(String[] args) { // NOSONAR 20 | LibExtractor ex = new LibExtractor(); 21 | List libraries = new ArrayList<>(); 22 | libraries.addAll(new AppNativeLibraries().getNativeLibrariesNames()); 23 | libraries.addAll(new CommonsNativeLibraries().getNativeLibrariesNames()); 24 | if (args.length == 1) { 25 | for(String library: libraries) { 26 | ex.extractLibrary(library, args[0]); 27 | } 28 | } else { 29 | System.err.println("No arguments provided. Expected: targetDir"); // NOSONAR 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/ZoweApiServiceApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice; 11 | 12 | import org.springframework.boot.SpringApplication; 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; 14 | import org.springframework.context.annotation.ComponentScan; 15 | 16 | @SpringBootApplication 17 | @ComponentScan 18 | public class ZoweApiServiceApplication { 19 | 20 | public static void main(String[] args) { // NOSONAR 21 | SpringApplication.run(ZoweApiServiceApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/config/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.config; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.boot.context.event.ApplicationReadyEvent; 15 | import org.springframework.context.ApplicationListener; 16 | import org.springframework.context.annotation.Bean; 17 | import org.springframework.context.annotation.ComponentScan; 18 | import org.springframework.context.annotation.Configuration; 19 | import org.zowe.commons.error.ErrorService; 20 | import org.zowe.commons.error.ErrorServiceImpl; 21 | import org.zowe.commons.spring.ServiceStartupEventHandler; 22 | 23 | @Configuration 24 | @ComponentScan("org.zowe.commons") 25 | public class ApplicationConfig implements ApplicationListener { 26 | 27 | @Value("${apiml.service.title}") 28 | private String serviceTitle; 29 | 30 | @Autowired 31 | private ServiceStartupEventHandler serviceStartupEventHandler; 32 | 33 | private final ErrorService errorService = ErrorServiceImpl.getDefault(); 34 | 35 | @Bean 36 | public ErrorService errorService() { 37 | return errorService; 38 | } 39 | 40 | @Override 41 | public void onApplicationEvent(final ApplicationReadyEvent event) { 42 | serviceStartupEventHandler.onServiceStartup(serviceTitle, ServiceStartupEventHandler.DEFAULT_DELAY_FACTOR); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/EmptyNameError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.greeting; 11 | 12 | public class EmptyNameError extends RuntimeException { 13 | private static final long serialVersionUID = -5418694915255263383L; 14 | } 15 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/Greeting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.greeting; 11 | 12 | import io.swagger.annotations.ApiModelProperty; 13 | import lombok.Data; 14 | 15 | @Data 16 | public class Greeting { 17 | @ApiModelProperty(value = "Generated sequence ID of the message") 18 | private final long id; 19 | 20 | @ApiModelProperty(value = "The greeting message") 21 | private final String content; 22 | 23 | @ApiModelProperty(value = "The locale language tag used for this message") 24 | private final String languageTag; 25 | } 26 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/GreetingControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.greeting; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.context.i18n.LocaleContextHolder; 14 | import org.springframework.core.Ordered; 15 | import org.springframework.core.annotation.Order; 16 | import org.springframework.http.HttpStatus; 17 | import org.springframework.http.MediaType; 18 | import org.springframework.http.ResponseEntity; 19 | import org.springframework.web.bind.annotation.ControllerAdvice; 20 | import org.springframework.web.bind.annotation.ExceptionHandler; 21 | import org.zowe.commons.error.ErrorService; 22 | import org.zowe.commons.rest.response.ApiMessage; 23 | 24 | /** 25 | * Creates responses for exceptional behavior of the {@link GreetingController}. 26 | */ 27 | @ControllerAdvice(assignableTypes = {GreetingController.class}) 28 | @Order(Ordered.HIGHEST_PRECEDENCE) 29 | public class GreetingControllerExceptionHandler { 30 | private final ErrorService errorService; 31 | 32 | @Autowired 33 | public GreetingControllerExceptionHandler(ErrorService errorService) { 34 | this.errorService = errorService; 35 | } 36 | 37 | @ExceptionHandler(EmptyNameError.class) 38 | public ResponseEntity handleEmptyName(EmptyNameError exception) { 39 | ApiMessage message = errorService.createApiMessage(LocaleContextHolder.getLocale(), "org.zowe.sample.apiservice.greeting.empty"); 40 | 41 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON).body(message); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/greeting/GreetingSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.greeting; 11 | 12 | import io.swagger.annotations.ApiModelProperty; 13 | import lombok.Data; 14 | import lombok.NoArgsConstructor; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | public class GreetingSettings { 19 | @ApiModelProperty(value = "The greeting message without the name") 20 | private String greeting; 21 | } 22 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/OffZosWto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | import org.springframework.context.annotation.Profile; 13 | import org.springframework.stereotype.Service; 14 | 15 | /** 16 | * off-z/OS implementation to allow the server to be run off z/OS for testing 17 | */ 18 | @Profile("!zos") 19 | @Service 20 | public class OffZosWto implements Wto { 21 | 22 | public WtoResponse call(int id, String content) { 23 | int rc = 0; 24 | String message = "[Mock] Message set from JNI"; 25 | return new WtoResponse(id, content, rc, message); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/Wto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | /** 13 | * Generic interface implemented in for z/OS and off-z/OS 14 | */ 15 | public interface Wto { 16 | WtoResponse call(int id, String content); 17 | } 18 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/WtoResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | import lombok.Data; 13 | 14 | /** 15 | * Class to model the data returned from the /wto endpoint 16 | */ 17 | @Data 18 | public class WtoResponse { 19 | private final int id; 20 | private final String content; 21 | private final int rc; 22 | private final String message; 23 | } 24 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/java/org/zowe/sample/apiservice/wto/ZosWto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | import org.springframework.context.annotation.Profile; 13 | import org.springframework.stereotype.Service; 14 | import org.zowe.commons.zos.LibLoader; 15 | 16 | import static org.zowe.sample.apiservice.AppNativeLibraries.SAMPLE_LIBRARY_NAME; 17 | 18 | /** 19 | * z/OS implementation calling the native, OS-linkage service WTO via a "shared 20 | * object" loaded at server runtime. 21 | */ 22 | @Profile("zos") 23 | @Service 24 | public class ZosWto implements Wto { 25 | static { 26 | new LibLoader().loadLibrary(SAMPLE_LIBRARY_NAME); 27 | } 28 | 29 | private native int wto(int id, String content); 30 | 31 | private String message; // String class variable set in JNI code 32 | 33 | public WtoResponse call(int id, String content) { 34 | int rc = wto(id, content); 35 | return new WtoResponse(id, content, rc, message); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | {"properties": [ 2 | { 3 | "name": "zowe.sample.authentication", 4 | "type": "java.lang.String", 5 | "description": "Text describing how to authenticate in Swagger UI" 6 | } 7 | ]} 8 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/lib/README.md: -------------------------------------------------------------------------------- 1 | # `resources/lib` folder 2 | 3 | This folder is a placeholder for `.so` files that are z/OS shared object libraries. 4 | 5 | Zowe GitHub repositories cannot contain binary files so you need to build it using 6 | `zowe-api-dev zosbuild` command. 7 | 8 | This folder `resources/lib` is packaged into the JAR file. `.so` files in the JAR file 9 | can be extracted to regular files using `LibsExtractor`. 10 | These files need to be executable and program-controlled on z/OS in order to be loadable by Java. 11 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 0 8 | 9 | 10 | 11 | 12 | 13 | %d{yyyy-MM-dd HH:mm:ss.SSS} %clr(<ZWEASA1:%thread:${PID:- }>){magenta} %X{userid:-} %clr(\(%logger:%line\)){cyan} %clr(%level) %msg%n 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Hello 12 | GreetingController.greetingTemplate=%s, %s\! 13 | GreetingController.world=world 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/messages.yml: -------------------------------------------------------------------------------- 1 | messages: 2 | - key: org.zowe.sample.apiservice.greeting.empty 3 | number: ZWEASA001 4 | type: ERROR 5 | text: "The provided name is empty. Provide a name that is not empty." 6 | - key: org.zowe.commons.service.started 7 | number: ZWEASA101 8 | type: INFO 9 | text: "'%s' has been started in %.3f seconds" 10 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/messages_cs.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Ahoj 12 | GreetingController.greetingTemplate=%s, %s\! 13 | GreetingController.world=světe 14 | messages.org.zowe.sample.apiservice.greeting.empty.text=Zadané jméno je prázdné. Zadejte jméno, které není prázdné. 15 | messages.org.zowe.commons.service.started.text='%s' se spustila za %.3f vteřin 16 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/messages_es.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This program and the accompanying materials are made available and may be used, at your option, under either: 3 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | # 6 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | # 8 | # Copyright Contributors to the Zowe Project. 9 | # 10 | 11 | GreetingController.greeting=Hola 12 | GreetingController.greetingTemplate=¡%s, %s\! 13 | GreetingController.world=mundo 14 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/main/resources/test-saf.yml: -------------------------------------------------------------------------------- 1 | # This file is used by the MockPlatformAccessControl class for testing and when the service is running outside of z/OS 2 | # It defines what are the access levels for SAF resources and users 3 | # 4 | # There are to special values of access level: 5 | # - `FAILURE` - the check request will fail with an internal error 6 | # - `NONE` - there is no access to the resource but the resource is defined 7 | # 8 | # This file is stored in `src/main/resources/test-saf.yml` which means that it will be used by the service and its unit tests. 9 | # If you can create a different file in `src/test/resources/test-saf.yml` then unit tests will use different definitions. 10 | # 11 | safAccess: 12 | FACILITY: # class 13 | BPX.SERVER: # resource 14 | READ: # access level 15 | - ZOWE # users 16 | BPX.DAEMON: 17 | UPDATE: 18 | - ZOWE 19 | - ZOWE2 20 | JESSPOOL: 21 | ALL: 22 | READ: 23 | - ZOWE 24 | - ZOWE2 25 | ZOWE: 26 | SAMPLE.RESOURCE: 27 | UPDATE: 28 | - ZOWE 29 | - ZOWE2 30 | CONTROL: 31 | - NONE 32 | FAILING: 33 | FAILURE: 34 | - ZOWE 35 | - ZOWE2 36 | DENIED: 37 | NONE: 38 | - NONE 39 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice; 11 | 12 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.EXPIRED_PASSWORD; 13 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.FAILING_PASSWORD; 14 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.INVALID_PASSWORD; 15 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.VALID_PASSWORD; 16 | import static org.zowe.commons.zos.security.platform.MockPlatformUser.VALID_USERID; 17 | 18 | import java.util.Base64; 19 | 20 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 21 | import org.zowe.commons.zos.security.platform.MockPlatformUser; 22 | 23 | public class TestUtils { 24 | public static final String ZOWE_BASIC_AUTHENTICATION = "Basic " 25 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + VALID_PASSWORD).getBytes()); 26 | public static final String ZOWE_BASIC_AUTHENTICATION_INVALID = "Basic " 27 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + INVALID_PASSWORD).getBytes()); 28 | public static final String ZOWE_BASIC_AUTHENTICATION_FAILING = "Basic " 29 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + FAILING_PASSWORD).getBytes()); 30 | public static final String ZOWE_BASIC_AUTHENTICATION_EXPIRED = "Basic " 31 | + Base64.getEncoder().encodeToString((VALID_USERID + ":" + EXPIRED_PASSWORD).getBytes()); 32 | public static final UsernamePasswordAuthenticationToken ZOWE_AUTHENTICATION_TOKEN = new UsernamePasswordAuthenticationToken( 33 | MockPlatformUser.VALID_USERID, null); 34 | } 35 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/ZoweApiServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | import org.junit.Test; 15 | import org.junit.runner.RunWith; 16 | import org.springframework.boot.test.context.SpringBootTest; 17 | import org.springframework.security.web.csrf.CsrfToken; 18 | import org.springframework.security.web.csrf.DefaultCsrfToken; 19 | import org.springframework.test.context.junit4.SpringRunner; 20 | import org.zowe.commons.spring.security.CsrfController; 21 | 22 | @RunWith(SpringRunner.class) 23 | @SpringBootTest 24 | public class ZoweApiServiceApplicationTests { 25 | 26 | @Test 27 | public void csrfControllerReturnsCsrfToken() { 28 | CsrfController controller = new CsrfController(); 29 | CsrfToken token = new DefaultCsrfToken("headerName", "parameterName", "token"); 30 | assertEquals(token, controller.csrf(token)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/src/test/java/org/zowe/sample/apiservice/wto/WtoControllerTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | package org.zowe.sample.apiservice.wto; 11 | 12 | import static org.hamcrest.CoreMatchers.is; 13 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 16 | 17 | import org.junit.Test; 18 | import org.junit.runner.RunWith; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 21 | import org.springframework.http.MediaType; 22 | import org.springframework.test.context.junit4.SpringRunner; 23 | import org.springframework.test.web.servlet.MockMvc; 24 | import org.zowe.sample.apiservice.TestUtils; 25 | 26 | @RunWith(SpringRunner.class) 27 | @WebMvcTest(WtoController.class) 28 | public class WtoControllerTests { 29 | 30 | @Autowired 31 | private MockMvc mvc; 32 | 33 | @Test 34 | public void returnsWtoMessage() throws Exception { 35 | mvc.perform(get("/api/v1/wto").header("Authorization", TestUtils.ZOWE_BASIC_AUTHENTICATION) 36 | .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) 37 | .andExpect(jsonPath("$.content", is("Hello, world!"))) 38 | .andExpect(jsonPath("$.message", is("[Mock] Message set from JNI"))); 39 | } 40 | 41 | @Test 42 | public void failsWithoutAuthentication() throws Exception { 43 | mvc.perform(get("/api/v1/wto")).andExpect(status().isUnauthorized()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/zossrc/makefile: -------------------------------------------------------------------------------- 1 | # makefile boilerplate to build the JNI implementation (C++), metal C code, and 2 | # bind into a "shared object" called at REST API runtime via the /wto endpoint 3 | # 4 | # This program and the accompanying materials are made available and may be used, at your option, under either: 5 | # * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 6 | # * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 9 | # 10 | # Copyright Contributors to the Zowe Project. 11 | 12 | CXX=xlc++ 13 | CC=xlc 14 | ASM=as 15 | 16 | MTL_OPTS=metal,\ 17 | langlvl(extended),\ 18 | sscom,\ 19 | nolongname,\ 20 | inline,\ 21 | genasm,\ 22 | inlrpt,\ 23 | csect,\ 24 | nose,\ 25 | lp64,\ 26 | list,\ 27 | warn64,\ 28 | optimize(2),\ 29 | list,\ 30 | showinc,\ 31 | showmacro,\ 32 | source,\ 33 | aggregate 34 | 35 | MTL_FLAGS=-S -W "c,$(MTL_OPTS)" 36 | 37 | MACLIBS=-ISYS1.MACLIB \ 38 | -ICBC.SCCNSAM 39 | 40 | MTL_HEADERS=-I/usr/include/metal 41 | 42 | DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended),dll,xplink,exportall"\ 43 | -qsearch=$(JAVA_HOME)/include \ 44 | -qsource \ 45 | -g \ 46 | -c 47 | 48 | DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" \ 49 | -g \ 50 | -qsource 51 | 52 | ASM_FLAGS=-mrent 53 | 54 | SIDEDECKPATH = $(JAVA_HOME)/bin/j9vm 55 | SIDEDECK = libjvm 56 | 57 | PREFIX := "../lib/" 58 | 59 | all: libzowe-sample.so 60 | 61 | install: 62 | mkdir -p $(PREFIX) 63 | cp -vp *.so $(PREFIX) 64 | extattr +p $(PREFIX)/*.so 65 | ls -E $(PREFIX) 66 | 67 | libzowe-sample.so: wtojni.o wtoexec.o 68 | $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst 69 | extattr +p $@ 70 | 71 | wtojni.o: wtojni.cpp 72 | $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ 73 | 74 | wtoexec.o: wtoexec.s 75 | $(ASM) $(ASM_FLAGS) -a=$*.asm.lst $(MACLIBS) -o $@ $^ 76 | 77 | wtoexec.s: wtoexec.c 78 | $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ 79 | 80 | clean: 81 | rm *.o 82 | rm *.lst 83 | rm *.x 84 | rm *.so 85 | rm *.dbg 86 | rm wtoexec.s 87 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/zossrc/wtoexec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This program and the accompanying materials are made available and may be used, at your option, under either: 3 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 4 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 5 | * 6 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 7 | * 8 | * Copyright Contributors to the Zowe Project. 9 | */ 10 | #include "wtoexec.h" 11 | #include "wto.h" 12 | 13 | #include 14 | #include 15 | 16 | /** 17 | * Metal C implementation running with z/OS linkage conventions and called 18 | * via JNI - C++ layer. 19 | * 20 | * Force the compiler and assembler to treat this function as a 21 | * "main" to aquire stack space. For production, create your 22 | * own or use your site's PROLOG & EPILOG. 23 | */ 24 | #pragma prolog(WTOEXE, "&CCN_MAIN SETB 1 \n MYPROLOG") 25 | 26 | int WTOEXE(int *number, const char *string) 27 | { 28 | WTO_BUF buf = {0}; 29 | buf.len = sprintf(buf.msg, "Number was: '%d'; String was: '%s'", *number, string); 30 | return wto(&buf); 31 | } -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/zossrc/wtoexec.h: -------------------------------------------------------------------------------- 1 | #ifndef WTOEXEC_H 2 | #define WTOEXEC_H 3 | 4 | /* 5 | * This program and the accompanying materials are made available and may be used, at your option, under either: 6 | * * Eclipse Public License v2.0, available at https://www.eclipse.org/legal/epl-v20.html, OR 7 | * * Apache License, version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | * 11 | * Copyright Contributors to the Zowe Project. 12 | */ 13 | 14 | /** 15 | * C/C++ interlanguage - "OS" meaning to call non-Language Environment conforming assembler. 16 | */ 17 | #if defined(__cplusplus) && (defined(__IBMCPP__) || defined(__IBMC__)) 18 | extern "OS" 19 | { 20 | #elif defined(__cplusplus) 21 | extern "C" 22 | { 23 | #endif 24 | 25 | int WTOEXE(int *, const char *); 26 | 27 | #if defined(__cplusplus) 28 | } 29 | #endif 30 | 31 | #endif -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/zossrc/wtojni.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_zowe_sample_apiservice_wto_ZosWto */ 4 | 5 | #ifndef _Included_org_zowe_sample_apiservice_wto_ZosWto 6 | #define _Included_org_zowe_sample_apiservice_wto_ZosWto 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: org_zowe_sample_apiservice_wto_ZosWto 12 | * Method: wto 13 | * Signature: (ILjava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_org_zowe_sample_apiservice_wto_ZosWto_wto 16 | (JNIEnv *, jobject, jint, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /zowe-rest-api-sample-spring/zowe-api.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zowe Sample REST API Service", 3 | "zosSourcesDir": "zossrc", 4 | "buildCommand": "make && make install", 5 | "buildFiles": { 6 | "libzowe-sample.so": "src/main/resources/lib/libzowe-sample.so" 7 | }, 8 | "deployment": { 9 | "files": { 10 | "build/libs/zowe-rest-api-sample-spring-0.0.1-SNAPSHOT.jar": { 11 | "target": "bin/zowe-rest-api-sample-spring.jar", 12 | "postSoUpdateCommands": [ 13 | "mkdir -p lib/ && $JAVA -cp bin/zowe-rest-api-sample-spring.jar -Dloader.main=org.zowe.sample.apiservice.LibsExtractor org.springframework.boot.loader.PropertiesLauncher lib && extattr +p lib/*.so && chmod a+x lib/*.so && ls -E lib/" 14 | ], 15 | "binary": true 16 | } 17 | } 18 | }, 19 | "shellStartCommand": "$JAVA -Dorg.zowe.commons.logging.stripAccents=true -Duser.language=en -Duser.country=US -Djava.library.path=\"./lib:${LIBPATH}\" -Xquickstart -jar bin/zowe-rest-api-sample-spring.jar --spring.config.additional-location=file:etc/application.yml", 20 | "jobTemplatePath": "src/main/jcl/template.jcl", 21 | "jobPath": "build/api.jcl", 22 | "defaultDirName": "zowe-rest-api-sample-spring", 23 | "defaultHlqSegment": "ZOWE.SAMPLAPI", 24 | "zfsMegabytes": 200, 25 | "configurations": { 26 | "zos": { 27 | "files": { 28 | "config/zos/application.yml.hbs": { 29 | "target": "etc/application.yml", 30 | "binary": true, 31 | "template": true 32 | }, 33 | "config/local/keystore.p12": { 34 | "target": "etc/keystore.p12", 35 | "binary": true 36 | }, 37 | "config/local/truststore.p12": { 38 | "target": "etc/truststore.p12", 39 | "binary": true 40 | } 41 | } 42 | } 43 | } 44 | } 45 | --------------------------------------------------------------------------------