Thursday, February 5, 2015

How to remove header from a request using wso2 API Manager

File Name: /_system/governance/apimgt/customsequences/in/auth_token_remover.xml

Content:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuthToken--Remover--In">
    <header name="Authorization" scope="transport" action="remove"/>
    <log level="custom">
        <property name="TRACE" value="Global Mediation Extension by Krishna for Authorization remove."/>
    </log>
</sequence>

Tuesday, January 20, 2015

How to set/remove headers in api manager of wso2

File Name: /_system/governance/apimgt/customsequences/in/global_auth_header.xml

 

Content:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--ExtAuth--In">

    <property name="TPaaS-Authorization" expression="$trp:TPaaS-Authorization" scope="default" type="STRING"/>

    <filter xpath="fn:string-length(get-property('TPaaS-Authorization')) > 0">

          <then>

              <property name="Authorization" expression="get-property('TPaaS-Authorization')" scope="transport"/>

              <log level="custom">

                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is there."/>

              </log>

          </then>

          <else>

              <log level="custom">

                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is not there."/>

              </log>

          </else>

     </filter>

</sequence>

Sunday, January 18, 2015

How do I install cURL on a Windows machine for https?

Install cURL on Windows

There are 4 steps to follow to get cURL installed on Windows. There are two (2) libraries to install and they must be installed before cURL will work with SSL. Also, they must be installed in this order to work. Do not skip step 4.

·         Step 1 and Step 2 is to install SSL library

·         Step 3 is to install cURL

·         Step 4 is to install a recent certificate

Step One: Install Visual C++ 2008 Redistributables

From http://www.shininglightpro.com/products/Win32OpenSSL.html

For 64bit systems

·         Visual C++ 2008 Redistributables (x64)

For 32bit systems

·         Visual C++ 2008 Redistributables (x32)

Step Two: Install Win(32/64) OpenSSL v1.0.0k Light

Also from http://www.shininglightpro.com/products/Win32OpenSSL.html

For 64bit systems

·         Win64 OpenSSL v1.0.0k Light

For 32bit systems

·         Win32 OpenSSL v1.0.0k Light

Step Three: Install cURL

Visit http://curl.haxx.se/download.html.

Depending on if your system is 32 or 64 bit, download the corresponding curl.exe.

For example, go to the Win64 - Generic section and download the Win64 binary with SSL support (the one where SSL is not crossed out).

Unzip the file and copy curl.exe to C:\Windows\System32

Step Four: Install Recent CA Certificates

Do not skip this step.

Download a recent copy of valid CERT files from http://curl.haxx.se/docs/caextract.html.

Copy it to the same folder as you placed curl.exe (C:\Windows\System32) and rename it curl-ca-bundle.crt.

Test cURL

Be sure you are an Admin in Canvas.

Open a DOS command window, type in the following and press enter

curl https://yourcanvas.test.instructure.com (replace [yourcanvas] with your Canvas domain name)

You should get raw HTML output on the screen.

If you get an error such as ‘Command not found’ then cURL has not been installed

Notes on Running Commands

The DOS environment doesn't seem to like single quotes. Any example that uses single quotes to surround values is invalid on windows. The single quotes must be replaced with double quotes.

curl.exe -X POST -H "Content-Type: application/zip" --data-binary @BATCH_CANVAS_ACCOUNTS-TC.zip -H "Authorization: Bearer 7Ec3AJXBsRIgvFjkcF8P3rCtzDilNm8LuHcF5fki2" "https://<yourdomain>.instructure.com/api/v1/accounts/<your_account>/sis_imports.json?import_type=instructure_csv"

 

 

Tuesday, January 6, 2015

Error "File name/path too long" when you try to clone repo from git

When you clone Identity from git you will face an error which states “File name/path too long”.

 

Please execute the following command in your git console before you proceed.

 

 

git config core.longpaths true

 



Thanks & Regards,

Rajakrishna Reddy

Thursday, December 18, 2014

Not able to create Application in Store, UI hangs!

This  is the know issue in API-1.7.0.

Issue: Application can’t be created once the application count reaches 20.

 

Solution: Add the given line in the given file.

File name: repository/deployment/server/jaggeryapps/store/site/themes/fancy/templates/application/application-list/template.jag

Line: var urlPrefix = “”;





 

Wednesday, November 26, 2014

How to enable CORS in apache tomcat

This is the simplest way to enable CORS in apache tomcat.

 

Have to add the below configuration to your application’s web.xml and restart the tomcat if required.

 

<filter>

  <filter-name>CorsFilter</filter-name>

  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

  <init-param>

    <param-name>cors.allowed.origins</param-name>

    <param-value>*</param-value>

  </init-param>

  <init-param>

    <param-name>cors.allowed.methods</param-name>

    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>

  </init-param>

  <init-param>

    <param-name>cors.allowed.headers</param-name>

    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>

  </init-param>

  <init-param>

    <param-name>cors.exposed.headers</param-name>

    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>

  </init-param>

  <init-param>

    <param-name>cors.support.credentials</param-name>

    <param-value>true</param-value>

  </init-param>

  <init-param>

    <param-name>cors.preflight.maxage</param-name>

    <param-value>10</param-value>

  </init-param>

</filter>

<filter-mapping>

  <filter-name>CorsFilter</filter-name>

  <url-pattern>/*</url-pattern>

</filter-mapping>



Thanks & Regards,

Rajakrishna Reddy

MySQL error java.sql.SQLException: Can't call commit when autocommit=true

When you see the error like below, please use the provided solution to get rid of this.

 

Caused by: java.sql.SQLException: Can't call commit when autocommit=true

        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)

        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)

        at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1740)

        at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.wso2.carbon.ndatasource.rdbms.ConnectionRollbackOnReturnInterceptor.invoke(ConnectionRollbackOnReturnInterceptor.java:51)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:71)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:153)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.TrapException.invoke(TrapException.java:41)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)

        at com.sun.proxy.$Proxy14.commit(Unknown Source)

        at org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.addAPI(ApiMgtDAO.java:4871)

        ... 65 more

 

 

Solution:

Use the url as shown here: <url>jdbc:mysql://varra:3306/DB_CARBON_IDENTITY?autoReconnect=true&amp;relaxAutoCommit=true</url>



Thanks & Regards,

Rajakrishna Reddy,

 

Tuesday, November 25, 2014

What is the best way to create an API in wso2 API-Manager 1.7.0

There was an issue with API improvements from 1.6.0 to 1.7.0 in multiple resource creation. Please apply attached PATCH-0580 to fix the issue.

 

Follow below mentioned guide to create multiple resources

 

1. To create multiple resources for a single uri-template (for multiple resource methods) refer below sample

 

ADD API:

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=Twitter&visibility=public&version=1.0.0&description=API for twitter&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=0&resourceMethod-0=GET,PUT,POST,DELETE&resourceMethodAuthType-0=Application,Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Bronze, Bronze,Unlimited,Gold" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

UPDATE API:

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=updateAPI&name=Twitter&provider=provider&visibility=public&version=1.0.0&description=API for twitter changed&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=0&resourceMethod-0=GET,PUT,POST&resourceMethodAuthType-0=Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Gold,Gold,Gold" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

 

2. To create multiple resources with multiple uri-templates refer below sample

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=Twitter&visibility=public&version=1.0.0&description=API for twitter&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=2&resourceMethod-0=GET,PUT,POST,DELETE&resourceMethodAuthType-0=Application,Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Bronze,Bronze,Unlimited,Gold&resourceMethod-1=GET,PUT&resourceMethodAuthType-1=Application User,Application User&uriTemplate-1=/test2/*&resourceMethodThrottlingTier-1=Unlimited,Unlimited" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

*NOTE : in this case follow following convention

resourceCount=[number of resources]

 

and for each resource parameters

[resource parameter]-[resource number 0,1,...]=[value]

example:

resourceMethod-1=GET

esourceMethodAuthType-1=Application .... etc.

 

Following configurations are also provided to manage api

default_version_checked, wsdl, wadl, inSequence, outSequence, faultSequence, responseCache, cacheTimeout, subscriptions, tenants,.. etc.


Thanks & Regards,

Rajakrishna Reddy,

 

Sunday, November 23, 2014

How to forward OAuth headers (Authorization) to backend Service using wso2 API-Manager

Needs a configuration change in api-manager.xml file under ${PRODUCT_HOME}/repository/conf/api-manager.xml

Eg:

 

<APIConsumerAuthentication>

        <!--

            Name of the security context header to be added to the validated requests.

        -->

        <SecurityContextHeader>X-JWT-Assertion</SecurityContextHeader>

 

        <!--

                Fully qualified name of the class that will retrieve additional user claims

                to be appended to the JWT. If not specified no claims will be appended.

                The DefaultClaimsRetriever class adds user claims from the default carbon user store.

        -->

 

 

        <!--

                Remove OAuth headers from outgoing message or keep with it.

        -->

 

        <RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>

 

    </APIConsumerAuthentication>



Thanks & Regards,

Rajakrishna Reddy,

 

Sunday, November 16, 2014

Refresh token is missing in the token request with grant type is 'password'

This could be the possible scenario happens with wso2 AM.

1. If the token is generated thru UI for the first time, Refresh token may miss in the next token request with grant type as ‘password’.

2. Once that token is revoke with the curl request we were able to get the refresh token.
Sample curl request we used:
curl -k -d "token=<ACCESS_TOKEN_TO_BE_REVOKED>" -H "Authorization: Basic Base64Encoded(Consumer key:consumer secret)" http://localhost:8280/revoke

3. Even the "RefreshTokenValidityPeriod" expires server didn't generate the refresh token.We found that we need to investigate further on this point.

Following the configuration we found in the "identity.xml"

<AccessTokenDefaultValidityPeriod>3600</AccessTokenDefaultValidityPeriod>
<RefreshTokenValidityPeriod>84600</RefreshTokenValidityPeriod>
<RenewRefreshTokenForRefreshGrant>true</RenewRefreshTokenForRefreshGrant>