Showing posts with label API-Manager. Show all posts
Showing posts with label API-Manager. Show all posts

Monday, June 22, 2015



When it comes to Automating API Creation in Api Manager there two methods you can follow. One is to use the ApiPublisher Api provided to add an API. This is well documented here. Other way is t use the Design Implement and publish phases to create the API just like creating an API from the UI. So here are some samples commands to be used to create a API. Please note I'm using Api Manager 1.8 and these parameters may vary in other versions.

Creating an API with Publisher API

Make sure you login to Api Manager first with the following command.

curl -X POST -c cookies http://localhost:9763/publisher/site/blocks/user/login/ajax/login.jag -d 'action=login&username=admin&password=admin'

Now create the API by parsing the session cookie

curl -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-add/ajax/add.jag -d 'action=addAPI&name=MyNewAPI6&visibility=public&version=1.0&description=My New API created and published by curl&endpointType=secured&http_checked=&https_checked=https&wsdl=&tags=automated published&tier=Gold&thumbUrl=https://pbs.twimg.com/profile_images/493735622587064320/z7qZUG0E_bigger.png&context=/apicurl6&tiersCollection=Gold,Silver,Bronze,Unlimited&resourceCount=5&resourceMethod-0=GET&resourceMethodAuthType-0=Application,Application User&resourceMethodThrottlingTier-0=Unlimited&uriTemplate-0=/assignments&resourceMethod-1=OPTIONS&resourceMethodAuthType-1=None&resourceMethodThrottlingTier-1=Unlimited&uriTemplate-1=/assignments&resourceMethod-2=GET&resourceMethodAuthType-2=Application,Application User&resourceMethodThrottlingTier-2=Unlimited&uriTemplate-2=/journeys&resourceMethod-3=OPTIONS&resourceMethodAuthType-3=None&resourceMethodThrottlingTier-3=Unlimited&uriTemplate-3=/journeys&resourceMethod-4=GET&resourceMethodAuthType-4=Application,Application User&resourceMethodThrottlingTier-4=Unlimited&uriTemplate-4=/info&resourceMethod-5=OPTIONS&resourceMethodAuthType-5=None&resourceMethodThrottlingTier-5=Unlimited&uriTemplate-5=/info' -d 'endpoint_config={"production_endpoints":{"url":"https://internal-mysampleapi.com:9443","config":null}, "sandbox_endpoints": {"url":"https://internal-mysampleapi.com:9443/mock","config":null},"endpoint_type":"http"}'

The above command will create the API successfully.

Creating the API with Normal Creating Flow

Design Call

curl -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F context="/myapiycr555555context" -F visibility="public" -F roles="" -F apiThumb="" -F description="" -F tags="testtag" -F action="design" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & Application User","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

Implement Call

curl -F implementation_methods="endpoint" -F endpoint_type="http" -F endpoint_config='{"production_endpoints":{"url":"http://appserver/resource/ycrurlprod","config":null},"endpoint_type":"http"}' -F production_endpoints="http://appserver/resource/ycrurlprod" -F sandbox_endpoints="" -F endpointType="nonsecured" -F epUsername="" -F epPassword="" -F wsdl="" -F wadl="" -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F action="implement" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & ApplicationUser","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

Publish and Manage Call



curl -F default_version_checked="" -F tier="Unlimited" -F transport_http="http" -F transport_https="https" -F inSequence="none" -F outSequence="none" -F faultSequence="none" -F responseCache="disabled" -F cacheTimeout="300" -F subscriptions="current_tenant" -F tenants="" -F bizOwner="" -F bizOwnerMail="" -F techOwner="" -F techOwnerMail="" -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F action="manage" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & ApplicationUser","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -F outSeq="" -F faultSeq="json_fault" -F tiersCollection="Unlimited" -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

The above commands will also create the API successfully.

Tuesday, June 16, 2015



Some times you may accidentally delete an Api from the carbon management console. If you delete an API from Management console (Which is not the correct way) It will only delete API related metadata. Some of the data related to that API won't get removed from APi Manager tables. This will corrupt the Database and result in errors.

The recommended way of deleting an API is to use the APIM Publisher application and delete it. This will remove all information related to the API. And if there are subscriptions for that API, it will inform you to unsubscribe it first (these won't happen if you use the management console. It is only provided for management tasks such as user management, etc)
Following is a list of things you need to do to completely remove the api from the API manager 1.8.

Please keep a backup of the database and any other resources before you do this.
Step 1 - Remove subscriptions of that api.
1. execute following query to get the application related information (You will need the APPLICATION_ID value to unsubscribe an API from that application)
SELECT * FROM AM_APPLICATION;
2. execute following query to get the API related information (You will need the API_ID value to unsubscribe an API from an application)
SELECT * FROM AM_API;
3. execute following to delete the subscription (Set the necessary ids. If you do not know which Application id to use, the use all ids from the AM_APPLICATION table. it will delete only the correct combination)
DELETE FROM AM_SUBSCRIPTION WHERE API_ID = ? AND APPLICATION_ID = ?;
Step 2 - Remove API
1. If you have an icon to this api, To delete it, go to following registry location in the management console and and delete the API (select 'Action' and delete)
/_system/governance/apimgt/applicationdata/icons/admin 
2. Delete API related meta data by login to the management console and navigating to Home > Metadata > List > APIs (You have already done that)
3. To delete the Swagger resources related to this API , go to following registy location and delete the resource collection (select on the api-doc resource and it will display swagger docs for all the resources. delete related on by selecting the Action button)
/_system/governance/apimgt/applicationdata/api-docs
4. Delete the synapse configuration for that api in AM_HOME/repository/deployment/server/synapse-configs/default/api location
5. Run following database queries to remove api related data
DELETE FROM AM_API_LC_EVENT WHERE API_ID=? 
DELETE FROM AM_API_COMMENTS WHERE API_ID=? 
DELETE FROM AM_API_RATINGS WHERE API_ID=? 
DELETE FROM AM_SUBSCRIPTION WHERE API_ID=?
DELETE FROM AM_EXTERNAL_STORES WHERE API_ID=?
DELETE FROM AM_API WHERE API_PROVIDER=? AND API_NAME=? AND API_VERSION=? 
DELETE FROM AM_API_URL_MAPPING WHERE API_ID = ?
following are two sample queries
DELETE FROM AM_SUBSCRIPTION WHERE API_ID=5;
DELETE FROM AM_API WHERE API_PROVIDER='admin' AND API_NAME='SampleAPI' AND API_VERSION='1.0';
6. remove api related collection from the registry location
/_system/governance/apimgt/applicationdata/provider/<user>. There should be an empty collection with the api name on it.
7. Restart the AM to remove any cached content.
This should remove all the content related to the api.

I would like to thank ChamilaA who provided the resources needed for this post. Hope this would help someone who is in need. Please drop a comment if you have further queries.

Saturday, May 9, 2015


There might be some use cases where a user wants to expose WSO2 API-Manager store over HTTP. Users can access the store via HTTP endpoint, but when the user is trying to login the user will be directed to the HTTPS endpoint.

And this is not recommended as well, if the Store is used over HTTP when authenticating the user credentials will be sent to the back-end as plain text. This can be a major sicurity issue when it comes to a production environment. So you should keep this in mind as well.

Since this is not supported by WSO2 API Manager we will have to do some code level changes. Just few lines. I will do the code change in a way that both HTTP and HTTPs endpoints can be used. If the user is accessing the HTTP endpoint everything will route over HTTP and if HTTPs endpoint is used the routing will take place throuch that EP.

WSO2 API Manager Version I'm Using : 1.8. You can read more about WSO2 API Manager from here.

So lets get started

1. Open the following file,

AM_HOME/wso2am-1.8.0/repository/deployment/server/jaggeryapps/store/site/themes/fancy/templates/ui/dialogs/template.jag

and place the following code. Or you can get a diff and do the code changes manually.

<% jagg.template("ui/dialogs", function(inputs, outputs, jagg){
var i18n = require("i18n");
var localeResourcesBasePath="/site/conf/locales/jaggery/";
i18n.init(request,localeResourcesBasePath);

%>
<script type="text/javascript">
        var isSecure = true;
        var showLogin = <%=session.get("showLogin")%>;
        var redirectToHTTPS = '<%=session.get("redirectToHTTPS")%>';

    </script>
 <%     var mod,httpUrl,httpsUrl;
        mod = jagg.module("manager");

        httpsUrl= mod.getHTTPsURL();
        var httpsURL =  httpsUrl + request.getRequestURI();

        if(request.getQueryString()){
            httpsURL += "?" + request.getQueryString();
        }

        session.put("showLogin","false");
        session.put("redirectToHTTPS","");
 %>
<div class="modal fade" id="messageModal"></div>
<div id="login-data" style="display:none;">

    <form id="mainLoginForm" autocomplete="off">
        <div class="modal-header">
            <button class="close" data-dismiss="modal">x</button>
            <h3><%=i18n.localize("login")%></h3>
        </div>

        <!--Error message viewer-->
        <div class="alert alert-error" id="loginErrorMsg" style="display:none">
            <div class="theMsg"></div>
        </div>

        <div class="modal-body">
            <label><%=i18n.localize("username")%>:</label>
            <input type="text" id="username" name="name" class="span3" placeholder="<%=i18n.localize("usernamePlcHolder")%>"/>
            <label><%=i18n.localize("password")%>:</label>
            <input type="password" id="password" name="pass" class="span3"/>
            <input type="hidden" id="tenant" name="tenant" value="<%=request_tenant%>">


        </div>
        <div class="modal-footer">
            <a href="#" class="btn btn-primary" id="loginBtn"><%=i18n.localize("login")%></a>
            <a href="#" class="btn" data-dismiss="modal"><%=i18n.localize("cancel")%></a>
        </div>
    </form>
</div>


<div id="confirmation-data" style="display:none;">
    <div class="modal-header">
        <button class="close" data-dismiss="modal">x</button>
        <h3 class="modal-title">Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body</p>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn btn-primary">Save changes</a>
        <a href="#" class="btn btn-other" data-dismiss="modal">Close</a>
    </div>
</div>
<% }); %>


2. Now open the following file and replace with the following code.

AM_HOME/wso2am-1.8.0/repository/deployment/server/jaggeryapps/store/site/themes/fancy/templates/user/login/template.jag

<% jagg.template("user/login", function(inputs, outputs, jagg) {
var i18n = require("i18n");var publisherUrl;
var localeResourcesBasePath="/site/conf/locales/jaggery/";
i18n.init(request,localeResourcesBasePath);
%>
<% var user = outputs.user; %>
<%
        var isSuperTenant, tenantDomain;
        var mod = jagg.module("manager");
        var httpsUrl= mod.getHTTPsURL();
  var isSelfSignupEnabled = mod.isSelfSignupEnabledForTenantUser(request_tenant);
    var log = new Log();

        var currentURL = request.getRequestURI();
        if(request.getQueryString()){
            currentURL += "?" + request.getQueryString();
        }
        var tenant=request_tenant;
        var urlPrefix;
        if(tenant!=null) {urlPrefix="tenant="+tenant;}else{urlPrefix='';}
        
        if (jagg.getUser() != null) {
         isSuperTenant = jagg.getUser().isSuperTenant;
   tenantDomain = jagg.getUser().username.split('@')[1];
        }
        


%>
<% if(user) { %>

<%if(jagg.getUser().hasPublisherAccess){%>
<%publisherUrl = jagg.module("manager").getAPIPublisherURL().url;
<%}%>
<ul class="nav actions login-sign-up pull-right">
            <li class="dropdown settingsSection">
                <i class="fa fa-tachometer"></i>
                                <br>
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Themes <b class="caret"></b></a>
              <ul class="dropdown-menu theme-container">
                <li  class="themeSelection"><h3><%=i18n.localize("selectTheme")%></h3>
                    <form id="themeSelectForm" action="<%=jagg.getAbsoluteUrl(jagg.getThemeFile("templates/user/theme/template.jag?theme=modern"))%>">
                        <input type="hidden" id="themeToApply" name="themeToApply" />
                        <input type="hidden" id="subthemeToApply" name="subthemeToApply" />
                        <input type="hidden" id="pathToSend" name="pathToSend" value="<%=currentURL%>" />
                        <table class="table">
                            <tr>
                                <td>
                                    <div class="thumbnail <% if(jagg.getUserTheme().base == "fancy" && jagg.getUserTheme().subtheme == null) { %>currentTheme<% } %>">
                                        <a data-theme="fancy" data-subtheme="" class="badge themeLabel" onclick="applyTheme(this)">
                                            <img src="<%=jagg.getAbsoluteUrl(jagg.getThemeFile("images/thumb-fancy.png"))%>" />
                                            <br /><div class="themeName"><%=i18n.localize("fancy")%></div>
                                        </a>
                                    </div>

                                </td>
                                <td>
                                    <div class="thumbnail <% if(jagg.getUserTheme().base == "dark" && jagg.getUserTheme().subtheme == null) { %>currentTheme<% } %>">
                                        <a data-theme="fancy" data-subtheme="dark" class="badge themeLabel" onclick="applyTheme(this)">
                                            <img src="<%=jagg.getAbsoluteUrl(jagg.getThemeFile("images/thumb-dark.png"))%>" />
                                            <br /><div class="themeName"><%=i18n.localize("dark")%></div>
                                        </a>
                                    </div>

                                </td>
                            </tr>
                        </table>
                    </form>
                </li>
              </ul>
            </li>
           <li class="divider-vertical"></li>
           <li class="dropdown">
               <i class="fa fa-user"></i>
               <br>
               <a class="link-to-user dropdown-toggle" data-toggle="dropdown"><%=user.username%> <b class="caret"></b></a>
             <ul class="dropdown-menu" id="userInfoMenu">
               <li class="userInfoSection">
                   <%=i18n.localize("logged")%> <h4><%=user.username%></h4>
               </li>
               <li class="logout-link-special"><button id="logout-link" class="btn btn-danger"><%=i18n.localize("logout")%></button></li>
             </ul>
           </li>
</ul>
<% } else { %>
<ul class="nav actions login-sign-up pull-right">
<%
var tenant=request_tenant;
if(isSelfSignupEnabled){%>
    <li>
        <i class="fa fa-pencil-square-o"></i>
        <br>
 <% if(site.request_url=="READ_FROM_REQUEST") { %>
 <a id="register-link" href="<%=site.context%>/site/pages/sign-up.jag?<%=urlPrefix%>"><%=i18n.localize("signup")%></a>
 
 <% } else {
     %>
 <a id="register-link" href="<%=site.request_url%>/site/pages/sign-up.jag?<%=urlPrefix%>"><%=i18n.localize("signup")%></a>
 
 <% } %>
    </li>
 <%}%>
    <li>
        <i class="fa fa-user"></i>
        <br>
        <a id="login-link"><%=i18n.localize("login")%></a>
    </li>
</ul>
<% } %>
<!--Links to Access Tenant Store and Public Store-->
<div class="tenant-position-setter">
<%if(jagg.getUser()!=null){%>
 <!--Links to Access Tenant Store and Public Store-->
  <%if (jagg.getUser().hasPublisherAccess) {%>
   Go to <a href="<%=publisherUrl%>" target="_blank" ><%=i18n.localize("apipublisher")%></a>
           <%if(site.showPublicStoreURL){%>
           |

  <%}}%>
 <%}%>

  <%if (tenant == null && isSuperTenant != null && !isSuperTenant && site.showPublicStoreURL) {%>

    Go to <a href="<%=jagg.getAbsoluteUrl("/")%><%="?tenant=" + tenantDomain%>"><%=tenantDomain%><%=i18n.localize("apistoreDesc")%></a>


  <%} else if ((tenant != null)&& site.showPublicStoreURL){%>

   Go to <a href="<%=jagg.getAbsoluteUrl("/")%>"><%=i18n.localize("publicAPIStore")%></a>


  <%}%>


 </div>

<% }); %>

3. Again open the following file and replace with following code. Or do the changes manually.

AM_HOME/wso2am-1.8.0/repository/deployment/server/jaggeryapps/store/site/themes/fancy/templates/user/sign-up/template.jag

<% jagg.template("user/sign-up", function(inputs, outputs, jagg) { %>
<%
 var fields = outputs.fields, length = fields.length;
        var user = session.get("logged.user");
        var mod = jagg.module("manager");
        var httpsUrl= mod.getHTTPsURL();
        if(user){ %>
        <script>
            location.href = "<%=site.context%>";
        </script>
        <% } %>
        <script>
            var context= "<%=site.context%>";
        </script>
<div class="title-section"><h2><%=i18n.localize("signupTitle")%></h2></div>
<div class="content-section shadow-up">
<div class="content-data">
<form class="form-horizontal" id="sign-up" autocomplete="off">
<fieldset>
    <div class="control-group">
        <label class="control-label"  for="newUsername"><%=i18n.localize("username")%>:<span class="requiredAstrix">*</span></label>
        <div class="controls">
            <input id="newUsername" name="newUsername" minlength="5" type="text" class="required validName input-medium noSpace" />
            <%              
                if(request_tenant != null) { %>
                     <label class="lblTenantDomainName"  for="newUsername"> @<%=request_tenant%></label>
            <%    }
            %>
           
            <input id="hiddenTenantDomain" type="hidden" value="<%=request_tenant%>"> 
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" for="newPassword"><%=i18n.localize("password")%>:<span class="requiredAstrix">*</span></label>
        <div class="controls">
            <div class="row-fluid">
                    <div class="span6">
                        <input type="password" class="input-large password" id="newPassword" name="newPassword" />

                        <div class="help-block" id="password-help" style="display:none">
                          <%=i18n.localize("pwHelpMsgLine1")%>
                            <ul>
                                <li><%=i18n.localize("pwHelpMsgLine2")%></li>
                                <li><%=i18n.localize("pwHelpMsgLine3")%></li>
                                <li><%=i18n.localize("pwHelpMsgLine4")%></li>
                                <li><%=i18n.localize("pwHelpMsgLine5")%></li>
                            </ul>

                        </div>
                    </div>
                    <div class="span6">
                        <div class="password-meter" style="display:none;">
                            <div class="password-meter-message"></div>
                            <div class="password-meter-bg">
                                <div class="password-meter-bar"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </div>



    <div class="control-group">
            <label class="control-label" for="newPasswordConfirm"><%=i18n.localize("retypePassword")%>:<span class="requiredAstrix">*</span></label>
            <div class="controls"><input type="password" class="matchPasswords input-large" id="newPasswordConfirm" /></div>
    </div>
    
    <%
        var i, field, inputClass;
        for(i = 0; i < length; i++) {
            field = fields[i];
            var required = field.required;
            var claimUri = field.claimUri;
            if (required == true) {
             inputClass = "required input-large";
            } else {
             inputClass = "input-xlarge";
            }
            if (claimUri.indexOf("name") !== -1) {
             inputClass = "required validName input-large noSpace";
            } else if (claimUri.indexOf("email") !== -1) {
             inputClass = "required validEmail input-large noSpace";
            } 
    %>
 <%if (required == true) {%>
         <div class="control-group">
            <label class="control-label" for="<%=i%>cliamUri"><%=i18n.localize(field.name, field.name)%>:
             <span class="requiredAstrix">*</span>
            </label>
            <div class="controls"><input type="text" id="<%=i%>cliamUri" name="<%=i%>cliamUri" class="<%=inputClass%>"/></div>
     </div>
  <%} %>
    <% } %>
        <div class="controls" style="padding-bottom:10px;" id="moreFieldsLink"><a onclick="showMoreFields()"><i class="icon-plus-sign"></i>More Details</a></div>
 <div class="controls" id="hideFieldsLink" style="display:none;padding-bottom:10px;">
  <a onclick="hideMoreFields()">
  <i class="icon-minus-sign"></i>More Details</a>
 </div>
        <div id="moreFields" style="display:none">
  <%  
  for(i = 0; i < length; i++) {
              field = fields[i];
              var required = field.required;
              var claimUri = field.claimUri;
   if(field.name == "Home Phone" || field.name == "Telephone") {
    field.name = "Land Phone";
   } else if (field.name == "Mobile") {
    field.name = "Mobile Phone";
   }
   if (claimUri.indexOf("address") !== -1) {
    inputClass = "input-address";
              } else if (claimUri.indexOf("country") !== -1) {
    inputClass = "input-medium";
       } else if (claimUri.indexOf("role") !== -1) {
    inputClass = "input-small";
       } else {
    inputClass = "input-large";
   }
  %>
   <%if (required != true) {%>
            <div class="control-group">
                <label class="control-label" for="<%=i%>cliamUri"><%=i18n.localize(field.name, field.name)%>:
                </label>
                <div class="controls"><input type="text" id="<%=i%>cliamUri" name="<%=i%>cliamUri" class="<%=inputClass%>"/></div>
        </div>
    <%} %>
  <% } %>
 </div>
 <input type="hidden" id="fieldCount" name="fieldCount" value="<%=length%>"/>
    <div class="form-actions">
        <input class="submit btn btn-primary" type="submit" value="<%=i18n.localize("submit")%>"/>

    </div>
</fieldset>
      </form>
</div>
</div>
<form id="signUpRedirectForm" method="post" action="<%=jagg.getAbsoluteUrl(jagg.getThemeFile("templates/user/sign-up/redirector.jag"))%>">
        <input type="hidden" name="redirectToHome" id="redirectToHome" value="<%=site.context%>" />
</form>


<% }); %>


4. Now refresh the page and you will be able to access the store via both HTTP and HTTPS.

Thanks for reading and please drop a comment if you have any queries.







There might be some use cases where a user wants to expose WSO2 API-Manager publisher over HTTP. This is not supported OOB in WSO2 API Manager.

And this is not recommended as well, if use Publisher over HTTP when authenticating the user credentials will be sent to the back-end as plain text. This can be a major sicurity issue when it comes to a production environment. So you should keep this in mind as well.

Since this is not supported by WSO2 API Manager we will have to do some code level changes. Just few lines.

WSO2 API Manager Version I'm Using : 1.8. You can read more about WSO2 API Manager from here.

So lets get started

Navigate to
"AM_HOME>/repository/deployment/server/jaggeryapps/publisher/site/themes/default/templates/user/login" and Open template.jag  file.

Change the code to match the following. That's it :)



<% jagg.template("user/login", function(inputs, outputs, jagg) { %>

<%      ///if(request.isSecure()){

            if(jagg.getUser() != null){
                response.sendRedirect('index.jag');
            }
%>
<div class="container-fluid login-container">
    <div class="row-fluid">
        <div class="span2 login-left">
            <div class="left-side-col">
            </div>
        </div>
        <div class="span6 login-content">
            <div class="title-section">
                <h2>Login</h2>
            </div>

            <div class="clear"></div>
            <div class="content-section shadow-up">
                <div class="content-data">
                       <div class="alert alert-error" id="loginError" style="display:none">
                           <span id="loginErrorSpan"></span>
                       </div>
                       <form class="" action="index.jag" id="loginForm" autocomplete="off">
                           <label><%=i18n.localize("username")%>:<span class="requiredAstrix">*</span></label>
                           <input type="text" id="username" autofocus="autofocus" validation="required"  />

                           <label><%=i18n.localize("password")%>:<span class="requiredAstrix">*</span></label>
                           <input type="password" id="pass" />
                           <input type="hidden"  id="tenant" value="<%= encode.forHtml(request.getParameter("tenant"))%>"/>
                           <div>
                               <input type="button" class="btn btn-primary" onclick="login()"  value="<%=i18n.localize("login")%>" id="loginButton" />
                               <input type="reset" class="btn" value="<%=i18n.localize("reset")%>" />
                           </div>
                       </form>
                </div>
            </div>
            <style>
                .api-count-display {
                    color: #747474;
                    font-size: 15px;
                    padding: 10px 20px 5px;
                }

                .api-count-display span {
                    font-size: 16px;
                    font-weight: bold;
                }
            </style>
        </div>
        <div class="span4">
        </div>
    </div>
    <div id="push"></div>
</div>
<% /*} else {
        var mod,httpsUrl;
        mod = jagg.module("manager");
        httpsUrl= mod.getHTTPsURL();

        response.sendRedirect(jagg.getHttpsUrl("/"));
}*/ %>
<%});%>

As you can see I have commented out the Security check. So the page will not be redirected to HTTPS endpoint if you try to access the publisher via the HTTP endpoint. So after doing this change refresh your page and you should be able to access the Publisher via the HTTP URL.

http://localhost:9763/publisher

Please drop a comment if you have any queries.


Subscribe to RSS Feed Follow me on Twitter!