
package com.sap.ccpbankscrtysrv.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BankSecurityController {
@GetMapping("/handlescrty")
public String handleScrty(){
return "Handle security";
}
}
---
applications:
- name: sapccp-bankscrtysrv
routes:
- route: sapccp-bankscrtysrv-cpcanary01.cfapps.sap.hana.ondemand.com
memory: 800M
timeout: 300
#random-route: true
path: target/sapccpbankscrtysrv-0.0.1-SNAPSHOT.jar
#buildpacks:
# - sap_java_buildpack
env:
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
JAVA_OPTS: -Djava.security.egd=file:///dev/./urandom
services:
- sapccp-bankscrtysrv-uaa
mvn clean install
cf push
{
"name": "sapccp-bankscrtysrv-approuter",
"dependencies": {
"@sap/approuter": "3.0.1"
},
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
},
"engines": {
"node": "8.16.1"
}
}
{
"routes": [
{
"source": "/",
"target": "/",
"destination": "dest-sapccp-bankscrtysrv"
}
]
}
---
applications:
- name: sapccp-bankscrtysrv-approuter
routes:
- route: sapccp-bankscrtysrv-approuter-<subdomain>.cfapps.sap.hana.ondemand.com
path: /
memory: 128M
buildpacks:
- nodejs_buildpack
env:
TENANT_HOST_PATTERN: 'sapccp-bankscrtysrv-approuter-(.*).cfapps.sap.hana.ondemand.com'
destinations: '[{"name":"dest-sapccp-bankscrtysrv", "url" :"https://sapccp-bankscrtysrv-<subdomain>.cfapps.sap.hana.ondemand.com", "forwardAuthToken": true}]'
services:
- sapccp-bankscrtysrv-uaa
TYPES:
BEGIN OF ty_token_json,
access_token TYPE string,
token_type TYPE string,
id_token TYPE string,
refresh_token TYPE string,
expires_in TYPE i,
scope TYPE string,
jti TYPE string,
END OF ty_token_json.
DATA lv_req_body TYPE string.
DATA lv_user TYPE string.
DATA lv_pwd TYPE string.
DATA lv_req_body_len_str TYPE string.
DATA lo_json_deserializer TYPE REF TO cl_trex_json_deserializer.
DATA ls_abap_response TYPE ty_token_json.
DATA lv_bearer_token TYPE string.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'https://<subdomain>.authentication.sap.<region>.ondemand.com/oauth/token'
IMPORTING
client = DATA(lo_http_client)
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
OTHERS = 7.
IF sy-subrc <> 0.
* Implement suitable error handling here
RETURN.
ENDIF.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
lv_user = '<client id>'.
lv_pwd = '<client secret>'.
CALL METHOD lo_http_client->authenticate
EXPORTING
username = lv_user
password = lv_pwd.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/x-www-form-urlencoded; charset=UTF-8'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
lv_req_body = |grant_type=password| &&
|&username=<email bound to subaccount>| &&
|&password=<password>| &&
|&client_id=<client id>| &&
|&client_secret=<client secret>| &&
|&response_type=token|.
DATA(lv_req_body_len) = strlen( lv_req_body ).
MOVE lv_req_body_len TO lv_req_body_len_str.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Length'
value = lv_req_body_len_str.
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = lv_req_body
offset = 0
length = lv_req_body_len.
CALL METHOD lo_http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD lo_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
DATA(lv_http_status) = lo_http_client->response->get_header_field( '~status_code' ).
DATA(lv_json_response) = lo_http_client->response->get_cdata( ).
REPLACE '"access_token"' IN lv_json_response WITH 'access_token'.
REPLACE '"token_type"' IN lv_json_response WITH 'token_type'.
REPLACE '"id_token"' IN lv_json_response WITH 'id_token'.
REPLACE '"refresh_token"' IN lv_json_response WITH 'refresh_token'.
REPLACE '"expires_in"' IN lv_json_response WITH 'expires_in'.
REPLACE '"scope"' IN lv_json_response WITH 'scope'.
REPLACE '"jti"' IN lv_json_response WITH 'jti'.
CREATE OBJECT lo_json_deserializer.
lo_json_deserializer->deserialize(
EXPORTING
json = lv_json_response
IMPORTING
abap = ls_abap_response ).
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'https://sapccp-bankscrtysrv-<subdomain>.cfapps.sap.<region>.ondemand.com/handlescrty'
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
OTHERS = 7.
IF sy-subrc <> 0.
* Implement suitable error handling here
RETURN.
ENDIF.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
lv_user = '<email bound to subaccount>'.
lv_pwd = '<password>'.
CALL METHOD lo_http_client->authenticate
EXPORTING
username = lv_user
password = lv_pwd.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'GET'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
CONCATENATE 'Bearer' ls_abap_response-access_token INTO lv_bearer_token SEPARATED BY space.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = lv_bearer_token.
CALL METHOD lo_http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD lo_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
lv_http_status = lo_http_client->response->get_header_field( '~status_code' ).
lv_json_response = lo_http_client->response->get_cdata( ).
CALL METHOD lo_http_client->close( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
15 | |
13 | |
9 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 |