0

We have a Webservice implementation done by some consultants which uses Rest API. We are trying to trace the code and understand. It looks like, we have used JSON Id tokens for authentication. Wanted to know if there is any expiry period for that and how to generate those tokens. We see that token value is same in Sandboxes as well as Production. Please find below the apex class.

public class AccountServiceControllerExtension2 { public final Account acct{get;Set;} public String siebelId{get;set;} public String requestBody{get;set;} public String requestResult{get;set;}

public list<list<String>> mainList{get;set;}
public String pageUrl{get;set;}

public list<list<list<String>>> allList{get;set;}
public list<list<String>> temp;
public list<String> dataList1;
public list<String> dataList2;

public AccountServiceControllerExtension2(ApexPages.StandardController stdController) {
    this.acct = (Account)stdController.getRecord();
    pageUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/ServiceRequest2?id='+acct.id;


    List<Account> siebelIdLs=[select Siebel_Row_ID__c from Account where Id=:acct.id limit 1];
    siebelId='';
    if(siebelIdLs.size()==1){
        if(siebelIdls.get(0).Siebel_Row_ID__c!=''&&siebelIdls.get(0).Siebel_Row_ID__c!=null){
            siebelId=siebelIdls.get(0).Siebel_Row_ID__c;
        }
    }

    String requestUrl='https://ASBintg.nat.olc.org/services/getServiceRequest';

    String result='';
    if(siebelId!=''){
        try{
            AccountHttpRequest ahr=new AccountHttpRequest();
            result=ahr.postCall(requestUrl,siebelId);
        }catch(Exception e){
            result='';
            requestResult='Can not get data from web service.';
        }
    }else{
        requestResult='No Siebel Row ID.';
    }

    List<map<String,String>> mapList=parseJason(result);   //get list data from json response
    if(mapList.size()>0){
        requestResult='valid';

        list<WebRequestMapListWrapper> wrapperList=new list<WebRequestMapListWrapper>();   

        for(Integer i=0;i<mapList.size();i++){
            WebRequestMapListWrapper wrapper1=new WebRequestMapListWrapper(mapList.get(i));
            wrapperList.add(wrapper1);
        }
        wrapperList.sort();

        mapList=new List<map<String,String>>();
        //reverse order
        for(Integer i = wrapperList.size()-1; i>=0;i--){
            mapList.add(wrapperList.get(i).dataMap);
        }

    }else{
        if(requestResult==''||requestResult==null)
        requestResult='No data for this account.';
    }


    allList=new List<list<list<String>>>();     //Top level list for all rows
    list<String> dataList1=new List<String>();

    for(Integer i=0;i<mapList.size();i++){

        temp=new List<list<String>>();
        dataList1=new List<String>();          //Bottom level list for real data
        temp.add(dataList1);                  
        allList.add(temp); 

        if(mapList.get(i).get('abstract')==null) mapList.get(i).put('abstract','');
       //........same kind of statements


        dataList1.add(mapList.get(i).get('productShortName'));  //product
        dataList1.add(mapList.get(i).get('status'));  //status           
        dataList1.add('pageBlockTable'+String.valueOf(i)); //No.14              
    }
}


public list<map<String,String>> parseJason(String result){

    Map<String, String> amap=new Map<string, String>();

    List<map<String,String>> mapList=new List<map<String,String>>();
    if(result==''||result==null){
        return mapList;
    }

    Map<String, String> tempMap;

    JSONParser parser = JSON.createParser(result);
    boolean flag=false;

    while (parser.nextToken() != null) {
        if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){
            String fieldName = parser.getText();


            if(flag){
                if(fieldName=='abstract'){
                    tempMap = new Map<String, String>();
                    mapList.add(tempMap);
                    parser.nextToken();
                    tempMap.put('abstract',parser.getText());
                }
                //........same kind of statements
            }


            if(fieldName=='serviceRequest'){
                flag=true;     
   } } }

    return mapList;

} } }

2 Answers 2

1

The "token" in that code refers to the parse tokens from the JSON class. These are not the same as JSON Web Tokens for authentication. This snippet definitely doesn't have anything explicit about authentication in it.

1
  • I added complete Apex class code just fyi. My middle ware teammate mentioned that, the token that salesforce sends(token will be encapsulated in URL) will be extracted and verified in the middleware(which has hardcoded token value in groovy script). How to we generate these parse tokens?
    – Amulya
    Commented Feb 7, 2017 at 2:34
0

The static Oauth token was defined in 'AccountHttpRequest' class which I had not noticed before. Thanks and sorry for confusing with half cooked code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .