Results 1 to 6 of 6
  1. #1
    jburchill is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Java to read in Service Account information

    Hello I'm not a java user, but am faced with a challange at work and thought maybe this would be the place for help. I have a cognos application that reads a java file. That file has a username and password that we hard code in there. Then it puts it into a string to sign into the site. The problem is maintenance of that password. Every 60 days we have to change it.

    Is it possible to read in the service account username and passwords. Sort of like how services use the service accounts. All I really know is that jdk 1.5 is intalled.

    Let me know what other info i need to gather or if this is even possible.

    Thank you

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Java to read in Service Account information

    Quote Originally Posted by jburchill View Post
    I have a cognos application that reads a java file.
    What's a cognos application, and what's a java file?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jburchill is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Java to read in Service Account information

    Cognos is an IBM application that is designed for report. The java file that I talk about is call DSServlet.java

    what is a db?

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    357
    Rep Power
    5

    Default Re: Java to read in Service Account information

    What does the "JAVA File" look like?

  5. #5
    jburchill is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Java to read in Service Account information

    /**
    * DSServlet.java
    *
    * Licensed Materials - Property of IBM
    * IBM Cognos Products: DOCS
    * (C) Copyright IBM Corp. 2004, 2010
    * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
    * IBM Corp.
    *
    * Copyright (C) 2004 Cognos ULC, an IBM Company. All rights reserved.
    * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
    */

    package com.cognos.demo;

    import javax.xml.namespace.QName;
    import javax.servlet.http.*;
    import java.io.*;

    import org.apache.axis.client.Stub;
    import org.apache.axis.message.SOAPHeaderElement;

    import com.cognos.developer.schemas.bibus._3.*;


    /**
    *
    *
    * To change this generated comment edit the template variable "typecomment":
    * Window>Preferences>Java>Templates.
    * To enable and disable the creation of type comments go to
    * Window>Preferences>Java>Code Generation.
    */
    public class DSServlet extends HttpServlet
    {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    {
    response.setContentType ("text/html;charset=utf-8");

    StringBuffer sb_xml;
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    xml += "<dataset xmlns=\"http://developer.cognos.com/schemas/xmldata/1/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\">";
    xml += " <metadata>";
    xml += "<item name=\"ReportPath\" type=\"xs:string\" length=\"512\"/>";
    xml += "</metadata>";
    xml += "<data>";
    //
    try
    {


    String username = "username";
    String password = "password";



    String namespace = "namespace";

    String endpoint = "http://localhost:9300/p2pd/servlet/dispatch/";
    /**
    *
    * The default port number 9300 above may need to be changed, if your Tomcat is listening on a different port number.
    * The port number 9300 is the default port for Tomcat.
    *
    */

    StringBuffer credentialXML = new StringBuffer();
    String BIBUS_NS = "http://developer.cognos.com/schemas/bibus/3/";
    String BIBUS_HDR = "biBusHeader";

    credentialXML.append("<credential>");

    credentialXML.append("<namespace>");
    credentialXML.append(namespace);
    credentialXML.append("</namespace>");

    credentialXML.append("<username>");
    credentialXML.append(username);
    credentialXML.append("</username>");

    credentialXML.append("<password>");
    credentialXML.append(password);
    credentialXML.append("</password>");

    credentialXML.append("</credential>");

    String encodedCredentials = credentialXML.toString();

    ContentManagerService_ServiceLocator cmServiceLocator=new ContentManagerService_ServiceLocator();
    ContentManagerService_PortType binding=null;
    binding=cmServiceLocator.getcontentManagerService( new java.net.URL(endpoint));

    binding.logon(new XmlEncodedXML(encodedCredentials),new SearchPathSingleObject[] {});

    BiBusHeader bibus = null;

    SOAPHeaderElement SourceHeader=((Stub)binding).getResponseHeader(BIB US_NS, BIBUS_HDR);

    try {
    bibus = (BiBusHeader)SourceHeader.getValueAsType(new QName(BIBUS_NS, BIBUS_HDR));

    } catch (Exception e) {
    e.printStackTrace();
    }

    if (!(bibus == null))
    {
    ((Stub)binding).clearHeaders();
    ((Stub)binding).setHeader(BIBUS_NS, BIBUS_HDR, bibus);
    }

    BaseClass bc[];
    QueryOptions qop = new QueryOptions();
    bc = binding.query(new SearchPathMultipleObject("//report"), new PropEnum[]{PropEnum.searchPath}, new Sort[]{},new QueryOptions());
    if (bc.length > 0)
    {
    for(int i = 0; i < bc.length; i ++)
    {
    Report rep = (Report)bc[i];
    String encoded_path = xmlEncodeHelper(rep.getSearchPath().getValue());
    xml += "<row><value>" + encoded_path + "</value></row>";
    }
    }
    }
    catch(Exception e)
    {
    xml += "<row>";
    xml += "<value>no data available</value>";
    xml += "</row>";
    }
    xml += "</data>";
    xml += "</dataset>";
    try
    {
    response.getWriter().print(xml);
    response.getWriter().flush();
    }
    catch (IOException e)
    {
    System.out.println(e);
    }
    }


    public String xmlEncodeHelper( String creds )
    {
    StringBuffer encoded = new StringBuffer( creds.length() );

    for( int idx = 0; idx < creds.length(); idx++ )
    {
    switch( creds.charAt( idx ) )
    {
    case '&':
    encoded.append( "&amp;" );
    break;
    case '<':
    encoded.append( "&lt;" );
    break;
    case '>':
    encoded.append( "&gt;" );
    break;
    case '\'':
    encoded.append( "&apos;" );
    break;
    case '"':
    encoded.append( "&quot;" );
    break;
    default:
    encoded.append( creds.charAt( idx ) );
    break;
    }
    }

    return encoded.toString();
    }
    }

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Java to read in Service Account information

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Account information problem
    By ostkanten in forum New To Java
    Replies: 2
    Last Post: 09-14-2012, 07:13 PM
  2. Replies: 1
    Last Post: 01-10-2012, 01:49 PM
  3. How to read information from Bluetooth GPS receiver
    By NModern in forum New To Java
    Replies: 2
    Last Post: 12-21-2011, 09:52 PM
  4. Replies: 0
    Last Post: 11-15-2011, 10:13 PM
  5. can a program read information from the internet?
    By brycepower1 in forum New To Java
    Replies: 1
    Last Post: 08-17-2011, 09:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •