Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    priyanka jaiswal
    Access Denied
    Topic posted November 20, 2014 by priyanka jaiswal 
    651 Views, 5 Comments
    Title:
    Access Denied
    Content:

    I am using Connect Web Service : Java . Tried using the sample code which was given . But I am getting access denied when I run the code

     

    import java.io.PrintWriter;
    import java.rmi.RemoteException;
    import java.util.Calendar;

    import javax.activation.DataHandler;

    import org.apache.axiom.om.OMElement;
    import org.apache.axiom.om.OMFactory;
    import org.apache.axiom.om.OMNamespace;
    import org.apache.axiom.om.impl.OMNamespaceImpl;
    import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
    import org.apache.ws.security.WSConstants;
    import org.apache.axis2.AxisFault;
    import org.apache.axis2.client.ServiceClient;
    import org.apache.ws.security.WSConstants;

    import com.rightnow.ws.base.ActionEnum;
    import com.rightnow.ws.base.ID;
    import com.rightnow.ws.base.NamedID;
    import com.rightnow.ws.base.NamedIDWithParent;
    import com.rightnow.ws.base.RNObject;
    import com.rightnow.ws.generic.RNObjectType;
    import com.rightnow.ws.messages.BatchRequestItem;
    import com.rightnow.ws.messages.BatchResponseItem;
    import com.rightnow.ws.messages.ClientInfoHeader;
    import com.rightnow.ws.messages.CreateProcessingOptions;
    import com.rightnow.ws.messages.DestroyProcessingOptions;
    import com.rightnow.ws.messages.DestroyResponseMsg;
    import com.rightnow.ws.messages.ExecuteMarketingFlowResponseMsg;
    import com.rightnow.ws.messages.GetProcessingOptions;
    import com.rightnow.ws.messages.QueryCSVResponseMsg;
    import com.rightnow.ws.messages.QueryResultData;
    import com.rightnow.ws.messages.RNObjectsResult;
    import com.rightnow.ws.messages.ResetContactPasswordResponseMsg;
    import com.rightnow.ws.messages.RunAnalyticsReportResponseMsg;
    import com.rightnow.ws.messages.SendMailingToContactResponseMsg;
    import com.rightnow.ws.messages.TransferSubObjectsResponseMsg;
    import com.rightnow.ws.messages.UpdateProcessingOptions;
    import com.rightnow.ws.messages.UpdateResponseMsg;
    import com.rightnow.ws.metadata.MetaDataClass;
    import com.rightnow.ws.objects.AnalyticsReport;
    import com.rightnow.ws.objects.Answer;
    import com.rightnow.ws.objects.Contact;
    import com.rightnow.ws.objects.Email;
    import com.rightnow.ws.objects.EmailList;
    import com.rightnow.ws.objects.PersonName;
    import com.rightnow.ws.wsdl.RequestErrorFault;
    import com.rightnow.ws.wsdl.RightNowSyncService;
    import com.rightnow.ws.wsdl.RightNowSyncServiceCallbackHandler;
    import com.rightnow.ws.wsdl.RightNowSyncServiceStub;
    import com.rightnow.ws.wsdl.ServerErrorFault;
    import com.rightnow.ws.wsdl.UnexpectedErrorFault;

    public class SampleClient {
         RightNowSyncService _service;
        
         public SampleClient() throws AxisFault
         {
          _service = new RightNowSyncServiceStub();  
          ServiceClient serviceclient = ((org.apache.axis2.client.Stub)_service)._getServiceClient();
          serviceclient.addHeader(createSecurityHeader("admin",""));
         }
        
         private OMElement createSecurityHeader(String username, String password)
            {
                // Set up the security header.
                OMFactory factory = new SOAP11Factory();
                OMNamespace wsseNS = factory.createOMNamespace(WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);

                // create the Security header block
                OMElement securityHeader = factory.createOMElement("Security", wsseNS);
                securityHeader.addAttribute("mustUnderstand", "1", null);

                // nest the UsernameToken in the Security header
                OMElement usernameTokenElement = factory.createOMElement(WSConstants.USERNAME_TOKEN_LN, wsseNS, securityHeader);

                // nest the Username and Password elements
                OMElement usernameElement = factory.createOMElement(WSConstants.USERNAME_LN, wsseNS, usernameTokenElement);
                usernameElement.setText(username);
                OMElement passwordElement = factory.createOMElement(WSConstants.PASSWORD_LN, wsseNS, usernameTokenElement);
                passwordElement.setText(password);
                passwordElement.addAttribute(WSConstants.PASSWORD_TYPE_ATTR, WSConstants.PASSWORD_TEXT, null);
                
                return securityHeader;        
            }
         private Contact populateContactInfo()
         {
                 Contact newContact = new Contact();
                 
                 PersonName personName = new PersonName();
                 personName.setFirst("Christopher");
                 personName.setLast("Omland");
                 newContact.setName(personName);
                 
                 EmailList emailList = new EmailList();
                 Email[] emailArray = new Email[1];
                 emailArray[0] = new Email();
                 emailArray[0].setAction(ActionEnum.add);
                 emailArray[0].setAddress("chris.omland@rightnow.com");
                 
                 NamedID addressType = new NamedID();
                 ID addressTypeID = new ID();
                 addressTypeID.setId(1);
                 addressType.setID(addressTypeID);
                 
                 emailArray[0].setAddressType(addressType);
                 emailArray[0].setInvalid(false);
                 
                 emailList.setEmailList(emailArray);
                 newContact.setEmails(emailList);
                 return newContact;
         }  
         public long createContact() throws RemoteException, ServerErrorFault, RequestErrorFault, UnexpectedErrorFault
            {
                Contact newContact = populateContactInfo();
                
                //Set the application ID in the client info header.
                ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                clientInfoHeader.setAppID("Axis2 Getting Started");
                
                //Set the create processing options, allow external events and rules to execute
                CreateProcessingOptions createProcessingOptions = new CreateProcessingOptions();
                createProcessingOptions.setSuppressExternalEvents(false);
                createProcessingOptions.setSuppressRules(false);
                
                RNObject[] createObjects = new RNObject[] { newContact };
                
                //Invoke the create operation on the RightNow server
                RNObjectsResult createResults = _service.create(createObjects, createProcessingOptions, clientInfoHeader);
                
                //We only created a single contact, this will be at index 0 of the results
                RNObject[] rnObjects = createResults.getRNObjects();
                newContact = (Contact)rnObjects[0];
                
                return newContact.getID().getId();
            }
        
        
        
        
         public static void main (String[] args)
         {
          try
          {
           SampleClient sampleclient = new SampleClient();
           long newContactID = sampleclient.createContact();
           System.out.println("New contact created with contact id : " +newContactID);
          }
          catch (AxisFault e)
          {
           System.out.println(e.getMessage());
           //e.printStackTrace();
           System.exit(1);
          }catch (RemoteException e)
          {
           System.out.println(e.getMessage());
           System.exit(1);
          }catch (ServerErrorFault e)
          {
           System.out.println(e.getMessage());
           System.exit(1);
          }catch (RequestErrorFault e)
          {
           System.out.println(e.getMessage());
           System.exit(1);
          }catch (UnexpectedErrorFault e)
          {
           System.out.println(e.getMessage());
           System.exit(1);
          }
          
         }

        }

    This is what I get in output console :

     

    log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).
    log4j:WARN Please initialize the log4j system properly.
    Access Denied

     

    Version:
    14.11

    Comment

     

    • Bipin Mittal

      Hi Priyanka,

      Have you made sure that you are using a valid username and password which has an account in RightNow and also the profile has Public SOAP API check box selected under Permissions.

      Thanks,

      Bipin

    • priyanka jaiswal

      Yes Bipin , I am using a valid staff account and the Public SOAP API permission is also given to the staff

    • Allan Schrum

      If this is a new site then server-side access control is turned on by default. This means that the permissions associated with the profile of the account you are using will apply. Does your profile permit the creation of contacts? If not, can you please adjust the profile to include Create and Update permissions for contact objects?

      Regards,

      -Allan

    • subrato das

      Hi Allan, Bipin,

      We are actually using the sample code provided on the Connect Object Documentation page. http://documentation.custhelp.com/euf/assets/devdocs/august2014/Connect_Web_Services_for_SOAP/Default.htm

      and the Java version with Eclipse. The Staff Account is using a Full Access Profile with all permissions checked. So, any information or best practices would be helpful to us.

       

      Thanks,
      Subrato

    • Ludovic LOPES

      HI Bipin

      You need to set on your application the configuration of the parameter "SEC_PAPI_INTEG_HOSTS_SOAP".

      Regards.