2013-01-14 13:57:22 +00:00
# README
2011-10-16 13:40:36 +00:00
2014-12-27 18:28:18 +00:00
The Open Bank Project API
2011-10-16 13:40:36 +00:00
2013-01-14 13:57:22 +00:00
## ABOUT
2013-01-14 12:05:55 +00:00
2014-09-19 18:40:08 +00:00
The Open Bank Project is an open source API for banks that enables account holders to interact with their bank using a wider range of applications and services.
2013-01-14 12:05:55 +00:00
2014-12-27 18:28:18 +00:00
The OBP API supports transparency options (enabling account holders to share configurable views of their transaction data with trusted individuals and even the public), data blurring (to preserve sensitive information) and data enrichment (enabling users to add tags, comments and images to transactions).
2013-01-14 16:03:32 +00:00
2014-09-19 18:40:08 +00:00
Thus, the OBP API abstracts away the peculiarities of each core banking system so that a wide range of apps can interact with multiple banks on behalf of the account holder. We want to raise the bar of financial transparency and enable a rich ecosystem of innovative financial applications and services.
2013-01-14 16:03:32 +00:00
Our tag line is: Bank as a Platform. Transparency as an Asset.
2013-01-14 12:05:55 +00:00
2014-09-19 18:40:08 +00:00
The API uses OAuth 1.0 authentication.
2013-01-14 12:05:55 +00:00
2017-04-19 06:28:12 +00:00
The project roadmap is available [here. ](https://github.com/OpenBankProject/OBP-API/blob/develop/roadmap.md )
2013-07-19 13:49:39 +00:00
2013-01-14 15:57:46 +00:00
## DOCUMENTATION
2013-01-14 12:05:55 +00:00
2017-06-08 06:11:17 +00:00
The API documentation is best viewed using the OBP API Explorer or a third party tool that has imported the OBP Swagger definitions.
Please refer to the [wiki ](https://github.com/OpenBankProject/OBP-API/wiki ) for links.
2013-01-14 12:05:55 +00:00
2017-06-08 06:11:17 +00:00
## STATUS of API Versions
2013-01-14 13:57:22 +00:00
2017-06-08 06:11:17 +00:00
OBP instances support multiple versions of the API simultaniously (unless they are deactivated in config)
To see the status (DRAFT, STABLE or BLEEDING-EDGE) of an API version, look at the root endpoint e.g. /obp/v2.0.0/root or /obp/v3.0.0/root
On the 8th of June 2017, [V2.0.0 ](https://apisandbox.openbankproject.com/obp/v2.0.0/root ) was marked as stable.
2013-01-14 13:57:22 +00:00
## LICENSE
2013-01-14 12:05:55 +00:00
2015-12-23 05:57:47 +00:00
This project is dual licensed under the AGPL V3 (see NOTICE) and commercial licenses from TESOBE Ltd.
2013-01-14 12:05:55 +00:00
2013-01-14 13:57:22 +00:00
## SETUP
2013-01-14 12:05:55 +00:00
2015-01-13 10:43:19 +00:00
The project uses Maven 3 as its build tool.
2013-06-22 07:17:48 +00:00
2014-12-27 18:28:18 +00:00
To compile and run jetty, install Maven 3 and execute:
2013-01-14 13:57:22 +00:00
2016-12-30 11:22:15 +00:00
./mvn.sh jetty:run
2011-10-16 13:40:36 +00:00
2015-06-20 09:56:11 +00:00
## To run with IntelliJ IDEA
2015-06-20 10:05:44 +00:00
* Make sure you have the IntelliJ Scala plugin installed.
* Create a new folder e.g. OpenBankProject and cd there
* git clone https://github.com/OpenBankProject/OBP-API.git
* In IntelliJ IDEA do File -> New -> Project from existing sources
2017-08-08 10:24:50 +00:00
* Alternatively you can do File -> New -> Project from VCS and checkout the project directly from github.
2015-06-21 20:08:25 +00:00
2017-08-08 10:24:50 +00:00
* When / if prompted for SDK, choose Java 1.8 (and Scala 2.11) otherwise keep the defaults. Use the Maven options. Do not change the project name etc.
2015-06-20 10:05:44 +00:00
2016-05-13 16:38:40 +00:00
* Navigate to test/scala/code/RunWebApp. You may see a Setup Scala SDK link. Click this and check Scala 2.11.8 or so.
2015-06-20 10:05:44 +00:00
2015-06-21 20:08:25 +00:00
* In src/main/resources/props create a test.default.props for tests. Set connector=mapped
2016-08-14 00:27:04 +00:00
* In src/main/resources/props create a \<yourloginname\>.props (or default.props) for development. Set connector=mapped
2015-06-21 20:08:25 +00:00
2017-08-08 10:24:50 +00:00
* Now **Rebuild** the project so everything is compiled. At this point you may need to select the SDK, see above.
* Once you have rebuilt the project wihtout compile errors, you should be able to RunWebApp in src/test/scala
2015-06-20 10:05:44 +00:00
* Run RunWebApp by right clicking on it or selecting Run. The built in jetty server should start on localhost:8080
* Browse to localhost:8080 but don't try anything else there yet.
### Run some tests.
* Run a single test. For instance right click on test/scala/code/branches/MappedBranchProviderTest and select Run Mapp...
2016-05-21 12:49:44 +00:00
* Run multiple tests: Right click on test/scala/code and select Run. If need be:
2015-08-20 15:37:04 +00:00
Goto Run / Debug configurations
Test Kind: Select All in Package
Package: Select code
2016-05-21 12:49:44 +00:00
Add the absolute /path-to-your-OBP-API in the "working directory" field
You might need to assign more memory via VM Options: e.g. -Xmx1512M -XX:MaxPermSize=512M
2015-06-20 10:05:44 +00:00
2015-06-20 09:56:11 +00:00
Make sure your test.default.props has the minimum settings (see test.default.props.template)
2016-05-21 12:49:44 +00:00
2015-06-20 10:05:44 +00:00
2015-06-20 09:56:11 +00:00
Right click test/scala/code and select the Scala Tests in code to run them all.
2015-08-20 15:50:40 +00:00
Note: You may want to disable some tests not relevant to your setup e.g.:
set bank_account_creation_listener=false in test.default.props
2015-06-20 09:56:11 +00:00
2016-04-30 02:23:35 +00:00
## Other ways to run tests
2016-04-30 03:09:39 +00:00
* See pom.xml for test configuration
2016-04-30 02:23:35 +00:00
* See http://www.scalatest.org/user_guide
2016-04-30 03:44:46 +00:00
## From the command line
Set memory options
2016-12-30 11:22:15 +00:00
export MAVEN_OPTS="-Xmx3000m -XX:MaxPermSize=512m"
2016-04-30 03:44:46 +00:00
2016-12-30 11:22:15 +00:00
Run one test
2016-04-30 03:44:46 +00:00
2016-12-30 11:22:15 +00:00
mvn -DwildcardSuites=code.api.directloginTest test
2012-04-15 17:32:44 +00:00
2015-11-07 14:34:10 +00:00
## Ubuntu
If you use Ubuntu (or a derivate) and encrypted home directories (e.g. you have ~/.Private), you might run into the following error when the project is built:
uncaught exception during compilation: java.io.IOException
[ERROR] File name too long
[ERROR] two errors found
[DEBUG] Compilation failed (CompilerInterface)
The current workaround is to move the project directory onto a different partition, e.g. under /opt/ .
2016-03-30 07:11:52 +00:00
## Databases:
2013-06-22 07:17:48 +00:00
2015-06-21 20:08:25 +00:00
The default database for testing etc is H2. PostgreSQL is used for the sandboxes (user accounts, metadata, transaction cache).
2014-12-27 18:28:18 +00:00
2016-06-25 01:33:40 +00:00
## Sandbox data
To populate the OBP database with sandbox data:
2017-02-22 13:38:15 +00:00
1) In the API's props file, set `allow_sandbox_data_import=true`
Probably best then, is to use the API Explorer (https://github.com/OpenBankProject/API-Explorer):
2) Get your `user_id` from the API Explorer at `/#2_0_0-getCurrentUser`
3) Add this id to `super_admin_user_ids` in the API's props file and restart the API
4) Go back to API Explorer, log in again and grant your user the role `CanCreateSandbox` at `/#2_0_0-addEntitlement` (make `bank_id` empty)
5) Now post the JSON data using the payload field at `/#2_1_0-sandboxDataImport`
6) If successful you should see an empty result `{}` and no error message
2016-06-25 01:33:40 +00:00
2016-01-19 15:38:29 +00:00
2016-03-30 07:11:52 +00:00
## Kafka (optional):
2016-01-19 15:38:29 +00:00
If Kafka connector is selected in props (connector=kafka), Kafka and Zookeeper have to be installed, as well as OBP-Kafka-Python (which can be either running from command-propmpt or from inside Docker container):
2016-01-19 15:40:53 +00:00
* Kafka and Zookeeper can be installed using system's default installer or by unpacking the archives (http://apache.mirrors.spacedump.net/kafka/ and http://apache.mirrors.spacedump.net/zookeeper/)
* OBP-Kafka-Python can be downloaded from https://github.com/OpenBankProject/OBP-Kafka-Python
2016-01-19 15:38:29 +00:00
2017-03-10 10:27:08 +00:00
## Running with a Zookeeper/Kafka Cluster
2016-12-30 10:35:02 +00:00
1) NGINX Configuration for Load Balancing
* Create file /etc/nginx/sites-available/api
2016-12-30 11:22:15 +00:00
* Configure as follows:
upstream backend {
least_conn;
server host1:8080; # The name of the server shall be changed as appropriate
server host2:8080;
server host3:8080;
}
server {
server_name obptest.com www.obptest.com; # The server name should be changed as appropriate
access_log /var/log/nginx/api.access.log;
error_log /var/log/nginx/api.error.log;
location / {
proxy_pass http://backend/;
}
location /obp/v2.1.0/sandbox/data-import {
proxy_pass http://backend/;
}
}
2016-12-30 10:35:02 +00:00
2) Zookeeper/Kafka Cluster Setup
* The Zookeeper/Kafka cluster is deployed on 3 nodes. The following configurations need to be done on each of the three nodes
* Zookeeper configuration
2016-12-30 11:22:15 +00:00
* Inside the Kafka directory, edit the file conf/zookeeper.properties and include these lines:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
dataDir=/home/user/zookeeper
server.1=host1:2888:3888 # The name of the servers shall be changed as appropriate
server.2=host2:2888:3888
server.3=host3:2888:3888
initLimit=5
syncLimit=2
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Create a myid file under dataDir which is /home/user/zookeeper in this example:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
echo “1” > /home/user/zookeeper/myid #Insert unique id’ s on each of the machines
2016-12-30 10:35:02 +00:00
* Start the zookpeer daemons on each of the 3 machines
2016-12-30 11:22:15 +00:00
bin/zookeeper-server-start.sh config/zookeeper.properties &
2016-12-30 10:35:02 +00:00
* Kafka Configuration
2016-12-30 11:22:15 +00:00
* Inside the Kafka directory, edit the file conf/server.properties and include these lines:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
broker.id=1 # The broker.id should be unique for each host
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
num.partitions=4
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
zookeeper.connect=host1:2181,host2:2181,host3:2181
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Start the kafka broker daemons on all the machines:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
bin/kafka-server-start.sh config/server.properties &
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Create the topics:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
bin/kafka-topics.sh --create --zookeeper host1:2181,host2:2181,host3:2181 --replication-factor 1 --partitions 1 --topic Request
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
bin/kafka-topics.sh --create --zookeeper host1:2181,host2:2181,host3:2181 --replication-factor 1 --partitions 1 --topic Response
2016-12-30 10:35:02 +00:00
3) OBP-API
* Configuration
2017-03-10 10:27:08 +00:00
* Edit the OBP-API/src/main/resources/props/default.props so that it contains the following lines. Please note that
kafka.host is used by the producer and kafka.zookeeper_host is used by the consumer. This should be done on each node:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
connector=kafka
2017-03-10 10:27:08 +00:00
# Address to be used by consumer
2016-12-30 11:22:15 +00:00
kafka.zookeeper_host=localhost:2181
2017-03-10 10:27:08 +00:00
# Address to be used by producer
kafka.host=localhost:9092
2016-12-30 11:22:15 +00:00
kafka.request_topic=Request
kafka.response_topic=Response
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Start the server:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
cd OBP-API
mvn jetty:run
2016-12-30 10:35:02 +00:00
4) OBP-JVM
2016-12-30 11:22:15 +00:00
* Build the package:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
cd OBP-JVM
mvn install
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Run the demo:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
java -jar obp-ri-demo/target/obp-ri-demo-2016.9-SNAPSHOT-jar-with-dependencies.jar&
2016-12-30 10:35:02 +00:00
* Here be aware that the name of the jar file might be different, so make sure to use the correct name of the jar file
5) OBP-Kafka-Python
2016-12-30 11:22:15 +00:00
* Run from the command line:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
cd OBP-Kafka-Python
python server.py
2016-12-30 10:35:02 +00:00
6) To test the setup, try a request
http://localhost:8080/obp/v2.0.0/banks
2016-03-05 07:03:46 +00:00
2017-03-10 10:27:08 +00:00
## Production Options.
2016-12-26 13:40:10 +00:00
2016-12-31 19:04:43 +00:00
* set the status of HttpOnly and Secure cookie flags for production, uncomment the following lines of "webapp/WEB-INF/web.xml" :
2016-12-30 10:35:02 +00:00
2016-12-26 13:40:10 +00:00
< session-config >
< cookie-config >
< secure > true< / secure >
< http-only > true< / http-only >
< / cookie-config >
< / session-config >
2017-03-10 10:27:08 +00:00
## Running the API in Production Mode
2016-12-30 10:35:02 +00:00
We use jetty8 to run the API in production mode.
1) Install java and jetty8
2) jetty 8 configuration
* Edit the /etc/default/jetty8 file so that it contains the following settings:
2016-12-30 11:22:15 +00:00
NO_START=0
JETTY_HOST=127.0.0.1 #If you want your application to be accessed from other hosts, change this to your IP address
JAVA_OPTIONS="-Drun.mode=production -XX:PermSize=256M -XX:MaxPermSize=512M -Xmx768m -verbose -Dobp.resource.dir=$JETTY_HOME/resources -Dprops.resource.dir=$JETTY_HOME/resources"
2016-12-30 10:35:02 +00:00
* In src/main/resources/props create a test.default.props file for tests. Set connector=mapped
* In src/main/resources/props create a default.props file for development. Set connector=mapped
* In src/main/resources/props create a production.default.props file for production. Set connector=mapped.
* This file could be similar to the default.props file created above, or it could include production settings, such as information about Postgresql server, if you are using one. For example, it could have the following line for postgresql configuration.
2016-12-30 11:22:15 +00:00
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/yourdbname?user=yourdbusername& password=yourpassword
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Now, build the application to generate .war file which will be deployed on jetty8 server:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
cd OBP-API/
mvn package
2016-12-30 10:35:02 +00:00
* This will generate OBP-API-1.0.war under OBP-API/target/
* Copy OBP-API-1.0.war to /usr/share/jetty8/webapps/ directory and rename it to root.war
2016-12-30 11:22:15 +00:00
* Edit the /etc/jetty8/jetty.conf file and comment out the lines:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
etc/jetty-logging.xml
etc/jetty-started.xml
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
* Now restart jetty8:
2016-12-30 10:35:02 +00:00
2016-12-30 11:22:15 +00:00
sudo service jetty8 restart
2018-01-23 06:25:19 +00:00
2016-12-30 10:35:02 +00:00
* You should now be able to browse to localhost:8080 (or yourIPaddress:8080)
2016-12-26 13:40:10 +00:00
2017-03-07 13:58:32 +00:00
2017-03-07 14:04:35 +00:00
## Using Akka remote storage
Most internal OBP model data access now occurs over Akka. This is so the machine that has JDBC access to the OBP database can be physically separated from the OBP API layer. In this configuration we run two instances of OBP-API on two different machines and they communicate over Akka. Please see README.Akka.md for instructions.
2017-03-07 13:58:32 +00:00
2018-01-18 10:54:09 +00:00
## Using SSL Encryption with kafka
For SSL encryption we use jks keystores.
Note that both the keystore and the truststore (and all keys within) must have the same password for unlocking, for which
the api will stop at boot up and ask for.
* Edit your props file(s) to contain:
2018-01-18 11:24:49 +00:00
kafka.use.ssl=true
keystore.path=/path/to/api.keystore.jks
truststore.path=/path/to/api.truststore.jks
2018-01-18 10:54:09 +00:00
2018-02-19 10:23:32 +00:00
## Using SSL Encryption with props file
2017-03-07 13:58:32 +00:00
2018-02-19 10:23:32 +00:00
For SSL encryption we use jks keystores.
Note that keystore (and all keys within) must have the same password for unlocking, for which the api will stop at boot up and ask for.
* Edit your props file(s) to contain:
jwt.use.ssl=true
keystore.path=/path/to/api.keystore.jks
keystore.alias=SOME_KEYSTORE_ALIAS
A props key value, XXX, is considered encrypted if has an encryption property (XXX.is_encrypted) in addition to the regular props key name in the props file e.g:
* db.url.is_encrypted=true
* db.url=BASE64URL(SOME_ENCRYPTED_VALUE)
The Encrypt/Decrypt workflow is :
1. Encrypt: Array[Byte]
2. Helpers.base64Encode(encrypted)
3. Props file: String
4. Helpers.base64Decode(encryptedValue)
5. Decrypt: Array[Byte]
1st, 2nd and 3rd step can be done using an external tool
2018-02-21 12:03:19 +00:00
2018-09-10 11:41:34 +00:00
### Encrypting props values with openssl on the commandline
2018-02-21 12:03:19 +00:00
1. Export the public certificate from the keystore:
2018-09-10 11:41:34 +00:00
`keytool -export -keystore /PATH/TO/KEYSTORE.jks -alias CERTIFICATE_ALIAS -rfc -file apipub.cert`
2018-02-21 12:03:19 +00:00
2. Extract the public key from the public certificate
`openssl x509 -pubkey -noout -in apipub.cert > PUBKEY.pub`
3. Get the encrypted propsvalue like in the following bash script (usage ./scriptname.sh /PATH/TO/PUBKEY.pub propsvalue)
```
#!/bin/bash
echo -n $2 |openssl pkeyutl -pkeyopt rsa_padding_mode:pkcs1 -encrypt -pubin -inkey $1 -out >(base64)
```
2018-09-10 11:41:34 +00:00
## Using jetty password obfuscation with props file
You can obfuscate passwords in the props file the same way as for jetty:
1. Create the obfuscated value as described here: https://www.eclipse.org/jetty/documentation/9.3.x/configuring-security-secure-passwords.html
2. A props key value, XXX, is considered obfuscated if has an obfuscation property (XXX.is_obfuscated) in addition to the regular props key name in the props file e.g:
* db.url.is_obfuscated=true
* db.url=OBF:fdsafdsakwaetcetcetc
2018-09-05 14:59:53 +00:00
## Code Generation
We support to generate the OBP-API code from the following two types of json. You can choose one of them as your own requirements.
1 Choose one of the following types: type1 or type2
2 Modify the json file your selected,
3 Run the Main method according to your json file
4 Run/Restart OBP-API project.
5 Run API_Exploer project to test your new APIs. (click the Tag `APIBuilder B1)
Here are the two types:
Type1: If you use `modelSource.json` , please run `APIBuilderModel.scala` main method
```
OBP-API/src/main/scala/code/api/APIBuilder/modelSource.json
OBP-API/src/main/scala/code/api/APIBuilder/APIBuilderModel.scala
```
Type2: If you use `apisResource.json` , please run `APIBuilder.scala` main method
```
OBP-API/src/main/scala/code/api/APIBuilder/apisResource.json
OBP-API/src/main/scala/code/api/APIBuilder/APIBuilder.scala
```
2018-08-24 12:54:54 +00:00
## Using jetty password obfuscation with props file
You can obfuscate passwords in the props file the same way as for jetty:
1. Create the obfuscated value as described here: https://www.eclipse.org/jetty/documentation/9.3.x/configuring-security-secure-passwords.html
2. A props key value, XXX, is considered obfuscated if has an obfuscation property (XXX.is_obfuscated) in addition to the regular props key name in the props file e.g:
* db.url.is_obfuscated=true
* db.url=OBF:fdsafdsakwaetcetcetc
2018-02-21 12:03:19 +00:00
2018-09-13 15:03:47 +00:00
## Rate Limiting
We support rate limiting i.e functionality to limit calls per consumer key (App).
It is assumed that you have a Redis instance if you wan to use the functionality. In order to make it work edit your props file in next way:
```
use_consumer_limits=false, In case isn't defined default value is "false"
2018-09-13 15:23:30 +00:00
redis_address=YOUR_REDIS_URL_ADDRESS, In case isn't defined default value is 127.0.0.1
redis_port=YOUR_REDIS_PORT, In case isn't defined default value is 6379
2018-09-13 15:03:47 +00:00
```
Next types are supported:
```
2018-09-13 15:23:30 +00:00
1. per minute
2. per hour
3. per day
4. per week
5. per month
6. per year
2018-09-13 15:03:47 +00:00
```
If you exced rate limit per minute for instance you will get the response:
2018-09-13 15:23:30 +00:00
```json
2018-09-13 15:03:47 +00:00
{
"error": "OBP-10018: Too Many Requests.We only allow 3 requests per minute to this Web site per logged in user."
}
```
and response headers:
```
X-Rate-Limit-Limit → 3
X-Rate-Limit-Remaining → 0
X-Rate-Limit-Reset → 0
```
2018-09-13 15:31:20 +00:00
Description of the headers above:
1. `X-Rate-Limit-Limit` - The number of allowed requests in the current period
2. `X-Rate-Limit-Remaining` - The number of remaining requests in the current period
3. `X-Rate-Limit-Reset` - The number of seconds left in the current period
2018-09-13 15:03:47 +00:00
Please note that first will be checked `per minute` call limit then `per hour` etc.
2018-02-19 10:23:32 +00:00
2016-03-30 07:11:52 +00:00
## Scala / Lift
* We use scala and liftweb http://www.liftweb.net/
* Advanced architecture: http://exploring.liftweb.net/master/index-9.html
2016-03-05 07:03:46 +00:00
2017-02-22 13:38:15 +00:00
* A good book on Lift: "Lift in Action" by Timothy Perrett published by Manning.