how to access database API to fetch the records - database

I am using grails and as my projects requirement I want to store companies database in my own project database.In order to do that I want to use companies database api's, but i don't know much about database api's.Can someone suggest me a way.thanks in advance..

tl;dr: build a REST service to deal with the other data source
I was having similar scenario, so let me tell that if it can help you.
scenario:
In the company I work for, we are building a Grails app for another company (lets call it company_b). So company_b has its own data warehouse and they want to push some of the data to the application I built.
N.B has its own developers.
The solution I came up with:
Looking at their database I designed the appropriate tables, and shared my db schema with the developers on company_b, then I build kind of REST API to expose the tables I designed( the domain objects). So then the developers on company_b developed an API to consume the rest API I built and they are now able to send any record or any operation(delete,update,etc..).
I used json, its structure looks like this.
{
"user": {
"username":"username",
"password":"password"
},
"operation":"INSERT",
"objectName":"Employee",
"objectId":"employeeId",
"object": {
"employeeId":"1212",
"phoneNumber":"0923335227",
"dateOfBirth":"12/7/1982"
}
}
Look at the user object above ^.
The requests that come to consume the REST API are skipped from the spring authentication and I use the user object to manually authenticate each request.
I hope it will give you some insight, but this might not be the right fit for your scenario. Refer the web a lot docs out there.

Related

How to work with "Identity Management Systems"?

This is my first question, so I hope I don't miss a thing. To be clear from the start: I don't expect an answer which dives deep into detail. This is just about getting a general understanding of how to work with this kind of software.
So I don't know if "Identity Management System" is a suitable term for what I mean but when I talk about Identity Management Systems I think of something like Azure AD, which as far as I know provides e.g. web developers the possibility to integrate a way users can authenticate (including access privilege etc.) on their website.
What I'm quite unsure about is how to work with/ integrate such tools in a project. I will try to make it clear with an example: Assuming I have a website let's say this website is a blog. The blog consist of different posts which are stored in my own database which is connected to the website. The posts are written by different users which authenticate with a tool like Azure AD. The user's data is stored somewhere on a server run by e.g. Microsoft. If I want to display the posts togethere with the name, email.... of the user who wrote them, how would I do this?
Is it possible to query the user's data directly from the Identity Management System and display it? This does not sound ideal to me as the consequence would be that data the website uses is stored in two different locations.
Would you kind of copy the user's data from the Identity Management System to the websites database and query it from there? This does not sound like a good solution either because then data would be duplicated.
So whats the "right workflow"?
I appreciate any hints and further information I can get:-)
AFAIK To get the user's information like name, email etc. you can add these claims while generating the JWT token.
To generate access token, you have multiple authentication flows such as Authorization code flow, ROPC flow, Implicit flow.
To add the claims that you need to return with the token, you can make settings like below:
Go to Azure Portal -> Azure Active Directory -> App Registrations -> Your app -> Token configuration -> Add optional claims
When you decode the token via JSON Web Tokens - jwt.io you can find the user information that you need.
To know how to generate access token, you can refer SO Thread which I solved it before.

Looking for suggestions on web hosting solution (Wix, Squarespace, WordPress, for following

I want to host a clean, branded site that allows users to submit data which I will post process on some regular cadence and send custom emails based on data processing results. I can write code and have extensive experience with AWS, but am looking for the fastest solution.
Any experienced web developers have suggestions of which hosting solution to use? Wix, Squarespace, WordPress. I would prefer Squarespace but am not finding clear documentation stating I can create a form which writes to a database (I.e. DynamoDB, Redshift).
Any suggestions would be great! Thanks!
Having a good deal of experience with Squarespace, I will address the question "Is it possible to connect a Squarespace form to a third-party database and, if so, by what means?". While I won't address Wix or Wordpress, hopefully it will provide some objective answers and provide some help to your larger context/question.
Squarespace doesn't support any server-side code; it only supports supports the addition of HTML, CSS and Javascript within Code Injection, Code Blocks, and Developer Mode.
Therefore, your options are:
Send the data client-side with JavaScript. Write your own HTML form and insert it via code block, markdown block, of developer mode. Then write the corresponding JavaScript to send the data, on submit, to your external database. Alternatively, use a Squarespace form block, prevent the default submission from executing and use your own methods instead.
Connect the Squarespace form block to a Google Sheet and the sheet to the external DB via Apps Script. Once connected, use Apps Script (set to trigger when a row is added to the sheet) to obtain the submission from the sheet and send it to your external database (similar to this or this, but you'll be going "the other way", sending data to the external DB from Apps Script).
Use Zapier (or similar service) to bridge the gap, either using Squarespace's built-in integration or setting up Zapier on your own and setting the Zapier email address as the email recipient. You can use Zapier to send form submissions to a new item in DynamoDB, for example. It appears that, at a minimum, you'd have to pay for Zapier as that is a "Premium Integration". For Squarespace, if you were to use their built-in Zapier integration, you'll have to pay for a higher-cost plan (which could be avoided by using the email storage option instead, as mentioned previously).
I think you should choose WordPress, they have a huge documentation, a big community, you can get a ton of support from Wordpress's users when you run into a problem.

What is the best practices for building REST API with different subscribers (companies)?

What is the best design approach in term of security, performance and maintenance for REST API that has many subscribers (companies)?
What is the best approach to use?:
Build a general API and sub APIs for each subscriber (company), when request come we check the request and forward it to the sub API using (API Key) then retrieve data to general API then to client.
Should we make single API and many databases for storing each subscribe(company) data (because each company has huge records that why we suggested to separated databases to improve performance)? when request come we verify it and change database Connection String based on client request.
Should we make one API and one big database that handle all subscribes data?
Do you suggest any new approach to solve this problem? We used Web API and MS SQL Server and Azure Cloud.
In the past I've had one API, the API is secured using OAuth/JWT in the token we have a company id. When a request comes in we read the company id from the JWT and perform a lookup in a master database, this database holds global information such a connection strings for each company. We then create a unit of work that has the company's conneciton string associated with it and any database lookups use that.
This mean that you can start with one master and one node database, when the node database starts getting overloaded you can bring up another one and either add new companies to that or move existing companies to take pressure off. Essentially you're just scaling out when the need arises.
We had no performance issues with this setup.
Depends on the transaction volume and nature of data, you can go for a single database or separate database for each company.
Option 2 would be the best , if you have complex data model
I don't see any advantage of going for option 1, because , anyway general API will call for each request.
You can use the ClientID verification while issuing access tokes.
What I understood from your question is, you want an rest API for multiple consumers(companies). Logically the employees from that company will consume your API, employees may be admin, HR etc. So what I suggested for such scenario you must go with single Rest API for providing the services to your consumers and for security you have to use OpenId on the top of OAuth 2. This resolves the authentication and authorization for you.

How to show audit data in the front end as timeline when user adds,modifies,deletes etc

Single Page Application which is developed in angular JS. I Just wanted to know the audit of the user activity in the front end timeline based on the users interaction with the database.
The database layer is done using HIBERNATE and controller layer with JERSEY Restful web-services. I wants to Audit the user operations on add,modify,delete etc in the UI while interacting with the hibernate.
I have gone through some posts , Some suggests JPA API for hibernate auditing, some suggests Spring DATA to achieve it. I Wanted the audit data to be shown up when user interacts with the system as well as arranging it in the back-end also.
Help me from the best architecture perceptive,flow or road-map to achieve it and also give me some learning tutorials.
Thanks in advance
Based on the assumption that by auditing you mean to be able track the change history that is made to entity rows at the database level, then yes Hibernate has an extension called Hibernate Envers that does this for you.
You can find documentation on Envers here
The jist is that you simply need to annotate your entities with #Audited either at the class level or on a per property level, supply a few configuration parameters at the time you construct either your EntityManagerFactory or SessionFactory and make sure you have the appropriate tables created in your database.
Once the revision tracking has started, you can then easily query for audit changes by using the org.hibernate.envers.AuditReader interface. See the documentation for how to obtain this.

GoogleApps Provisioning API to move a user from one organization to another

i have a use case to move a user from one Organization to another. The Api i am using is provisioning API. Managing Org Users gave an example for lab. Can anybody please share more info on what jar's need to be used to implement this. My rest of code is able to manage the other user functionallity.
My Code is in java
I am using jars gdata-appsforyourdomain, gdata-client, gdata-core and gdata-collect. These jars dont have any API's to manage the organizations with users. It would be great help if any one can share docs or any sample data on this use-case. Thanks
I was able to figure out the way by going through the source code of the labs and deployed the same.
AppsPropertyService service=new AppsPropertyService(applicationName);
service.setUserCredentials(adminUserName,Password);
GenericEntry entry = new GenericEntry();
entry.addProperty("oldOrgUnitPath",oldOrg);
entry.addProperty("orgUnitPath", newOrg);
service.update(new URL("https://www.google.com/a/feeds/orguser/2.0/"+cutomerId+"/"+MailIdofUserToBeMoved), entry);
customerid- is the unique key of the admin.

Resources