Upload
adithya-kuchan
View
115
Download
0
Embed Size (px)
Citation preview
Basic Auth Implementation using
RAML in MulePrepared By: Aditya Kuchan
WHAT IS RAML?
• RAML stands for RESTful API Modeling Language. It's a way of describing practically-RESTful APIs in a way that's highly readable by both humans and computers. We say "practically RESTful" because, today in the real world, very few APIs today actually obey all constraints of REST. RAML isn't strict: for now, it focuses on cleanly describing resources, methods, parameters, responses, media types, and other HTTP constructs that form the basis for modern APIs that obey many, though perhaps not all, RESTful constraints.• RAML is a non-proprietary, vendor-neutral open spec. The aim is to help our
current API ecosystem and solve immediate problems, and then gently encourage ever-better API patterns.
• For more details on RAML Refer Below mentioned Link
http://raml.org/about/about-raml
Below is the Defined RAML with Basic OAuth Configuration
• #%RAML 0.8• ---• title: Basic Auth Impl• baseUri: https://api.sample.com/{version}• version: v1.0• securitySchemes:• - basicAuth:• description: Requires Basic Authentication for every API request.• type: Basic Authentication• securedBy: [basicAuth]• traits:• - secured:• description: Some requests require authentication• - unsecured:• description: This is not secured
/SalesforceData: get: description: Get Name, ID, OtherCountry, OtherPhone from Salesforce Account responses: 200: body: application/json: example: !include get_salesforce_example.json schema: !include get_salesforce_schema.json 400: 500:
After you Import your .raml file in the studio it will generate flows with all the mentioned
operations and with Error Codes.You just need to point to your main flow
where all the operations are performed. In my case I am pointing to listnerBasicAuth
flow where I am defining operation of getting the data from salesforce
This is how my main flow looks followed by .xml in upcoming slides
Xml for the Flow is shown as below• <spring:beans>• <ss:authentication-manager alias="authenticationManager">• <ss:authentication-provider>• <ss:user-service id="userService">• <ss:user name=“Aditya" password=“Aditya" authorities="ROLE_ADMIN" />• </ss:user-service>• </ss:authentication-provider>• </ss:authentication-manager>• </spring:beans>• <mule-ss:security-manager name="SecurityManager" doc:name="Spring Security Provider">• <mule-ss:delegate-security-provider name="memory-provider" delegate-
ref="authenticationManager" />• </mule-ss:security-manager>• <sfdc:config name="Salesforce__Basic_Authentication" username="${Username}"
password="${Password}" • securityToken="${SecurityToken}“• doc:name="Salesforce: Basic Authentication"/>
• <flow name="listenerBasicAuth">• <http:basic-security-filter realm="mule-realm"/>• <mule-ss:http-security-filter realm="mule-realm"/>• <logger message="#[payload] Checking" level="INFO"
doc:name="Logger"/>• <sfdc:query config-
ref="Salesforce__Basic_Authentication" query="dsql:SELECT • AccountId,Id,Name,OtherCountry,OtherPhone FROM Contact
ORDER BY AccountId ASC LIMIT 100 OFFSET 10" • doc:name="Salesforce"/>• <logger
message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>• </flow>