How to retreive tomcat parameters in a servlet

Hi guys&girls,
I need to get username and password used to connect to a jsp application from a servlet. Is it possible? The application uses the standard j_security_check configuration on Tomcat (with the tomcat-users.xml file, containing users)
I have to do it from the init method and not from doGet or doPost method.
I know that could be a very simple answer (and I hope too...), but I couldn't find anything on the net :( (and those forum too, of course).
Thanks in advance
Claudio

Because in the Init method the connection to database is performed.
Now it is done using a .properties file, but I need to change it to use the same user/password of the tomcat application.
Do you know if it is possible?It sounds like a really bad idea to me, for a variety of reasons.
Ignoring for the moment the idea of tightly coupling your application security to a plaintext config file in your container, I'd reiterate that the servlet's init() method only gets called once. It sounds like you're asking how to use a single user's credentials (init() is called once, so you don't get a second chance at this) to connect to a database for the whole application. If that doesn't raise a gigantic red flag with you, it should. If you're using a service account to connect, I don't see any reason why you would find it necessary to specify those credentials in a container-specific config file.
You may want to look into something like the Acegi framework to help you manage your application security.
~

Similar Messages

  • How to hide the parameters passed into servlet or make it read only

    Hi,
    I am calling a servlet to downlaod files, using
    <a href="../servlet/DownloadFile?directory=<%=attachmentPath%>&fileName=<%=fileName%>">But this will display all the paramters passed , of course as I am using hyper link. However I can not use
    <form> to call the servlet because otherwise I got nested form anyway.
    So the users would be able to change the directory and file names to download files I do not like them to download. Somebody would suggest hardcode the directory and filename, but these two parameters are dynamic, so I have to pass them into the servlet everytime I call it.
    Any advice to disable the users to change or even view the two parameters on the address bar?
    Thanks
    </a>

    Here some code snippets to give you an idea of what I do.
    Let's say you want to retrieve a file from your server, and you need to pass the full directory path info in your URL. You might have code as follows:
    String fileName = "/server/SomeUltraSecretHiddenDirectory/ImportantSecretFile.doc";
    Click <a href="/fileservlet?fileName=<%=URLEncoder.encode(fileName)%>">HERE</a> to download file.Using the above code, ANYONE can retrieve this file if they know the URL. Also, they could try to change the URL paths to find other files. In other words, it's NOT SECURE.
    Now, try it this way (all exception handling is left out):
    private static final byte[] salt = { (byte)0xd4, (byte)0xa3, (byte)0xff, (byte)0x9e,
    (byte)0x12, (byte)0xc7, (byte)0xd0, (byte)0x84 };     
    String fileName = "/server/SomeUltraSecretHiddenDirectory/ImportantSecretFile.doc";
    base64Encoder = new BASE64Encoder();
    base64Decoder = new BASE64Decoder();
    // get key object
    SecretKey key = null;               
    PBEKeySpec keySpec = new PBEKeySpec("somesecretkeystring");
    SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    key = kf.generateSecret(keySpec);     
    // get parameter spec
    PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 1000);
    // create cipher
    Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
    c.init(Cipher.ENCRYPT_MODE, key, paramSpec);     
    // take string and get encrypt it (base-64 encode it to get rid of non-printable characters
    byte[] aResult = c.doFinal(fileName.getBytes("UTF-8"));
    String strResult = base64Encoder.encodeBuffer(aResult);
    // print the link
    Click <a href="/fileservlet?fileName=<%=URLEncoder.encode(strResult)%>">HERE</a> to download file.
    // on the server side, do the following to decrypt the link
    String encryptedFileName = request.getParameter("fileName");
    // create decryption cipher (i'm skipping a lot of the init code this time - see above for code example)
    Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
    c.init(Cipher.DECRYPT_MODE, key, paramSpec);
    // decrypt string
    byte[] aResult = c.doFinal(base64Decoder.decodeBuffer(encryptedFileName));
    String strResult = new String(aResult, "UTF-8");Now you have the decrypted String. Your link will be unreadable and unbreakable. 100% safe as long as your key password is safe. I hope that gives you an idea of what you can do with cryptography!
    A few notes:
    - Most of the above code is in separate methods that can be easily reused (especially encrypt() and decrypt())
    - All exception handling has been left out
    - The above code was patched together from memory, so don't expect it to work as is (that's my disclaimer :)
    - You'll need the JCE libraries to use this functionality.
    - For REALLY sensitive data (such as passwords), make sure you use one-way encryption (hashes) if you don't ever need to decrypt it again.
    Michael

  • How to get checked parameters in a servlets or Action's?

    i am using a for loop for creating Checkboxes in my JSP and i am finding it difficult to get the set of checked values into my next servlet or jsp i.e. to which ever my request is forwarded..
    the logic i used in my jsp for creating my Check boxes is
    <%for(int i=0;i<10;i++){%>
    <input type=checkbox name="<%=i%>" value="check box <%=i%> selected">
    <%}%>
    and i want to get all the check boxes i checked in my next Action..
    any one plz help me on this..

    You may want to try this other approach:
    On the JSP
    <%for(int i=0;i<10;i++){%>
        <input type=checkbox name="checkbox" value="check box <%=i%> selected">
    <%}%>On the servlet
    String[] checkboxes = request.getParameterValues("checkbox");
    for(int i = 0; i < checkboxes.length; i++){
       //whatever you need the values to
    }And in case you're keeping your existing code:
    on the servlet
    String checkbox;
    for(int i = 0; (checkbox = request.getParameter(String.valueOf(i)) != null; i++){
       //whatever you need the values to
    }

  • How to retreive out parameters from function in sql statement

    hi dear,
    Suppose i have a fuction with two "out" parameters, i want to show the values of these paramenters in sql stm.
    like
    select my_function() from dual;
    Thanx

    Can't be done. To use a function in SQL it can only have a single return value.
    Try something like this changing the data types appropriately.
    var x number
    var y number
    var z number
    exec :x := my_function(:y, :z)
    print

  • How to retreive textformat parameters

    Hello Forum,
    I am using the setStyle to set the text label on some buttons
    in flash. AS3.
    Set font to bold and color to red.
    myButton.setStyle("textFormat", redBoldFormat);
    I do this on as part of a function when the button is
    clicked.
    Is there a way to retreive the textformat settings (like
    bold, etc) so I can un-set the format?
    I have 5 buttons, when one is clicked, it goes bold and red.
    When a different button is clicked, I would like the previously
    clicked button to go back to "not bold" and "not red"
    and so on,
    thanks
    eholz1

    eholz1can you try to do this:
    myPreviousButton.setStyle("textFormat", notBoldFormat);
    You don't "unset" the format u can "reset" it.

  • How does one set databse parameters in Tomcat to run a servlet?

    Hi, I am trying to run a applet-servlet code, downloaded from the web. According to the installation instructions, the following is stated:
    Database Parameters. You can provide different database parameters to the servlet. These parameters are set during the administration of the servlet.
    dbDriver - name of the database driver class name (default = sun.jdbc.odbc.JdbcOdbcDriver)
    dbURL - complete database URL (default = jdbc:odbc:StudentDatabase)
    userid - user id (default = <none>)
    passwd - password (default = <none>)
    I am running TOMCAT on a Windows2000 machine. My question is how to does one set the parameters in TOMCAT. What is the default userid and password for TOMCAT.
    Any help/advise is appreciated in advance. Thanks.Regards.

    May be parameters must be set in web.xml in your war

  • How to pass parameters/atrributes to Servlet from ALBPM

    HI Friends,
    I am invoking servlet from bpm using server configuration, i am able to invoke servlet, but not able to pass parameters dynamically,
    Also I like to receive response parameters/attributes from servlets?
    Can any body help me on this?
    Look forward for response.
    Cheers

    Some helpful Docs on the WebServer component for you:
    The WebServer component is used to send HTTP requests to an HTTP server and capture the responses. It supports HTTP methods GET and POST.
    The body of the HTTP response is available in the WebServer.response attribute (String).
    Note: This component is superseded by the Fuego.NetX.AdvancedWebServer component, which provides better performance and more functionality like support for proxies and for more HTTP methods (like PUT and DELETE).
    Example: Get Oracle's website home page and save it to a file.
    getFrom(WebServer, url : "http://oracle.com", args : null)
    binaryResponse = Binary(text: WebServer.response,
    encoding: "UTF8")
    BinaryFile.writeFromBinaryTo(data : binaryResponse,
    name : "/tmp/oracle_index.html",
    append : false)

  • How to retreive and display output list from BAPI

    Hello
    I am making an applcation using SUP 2.0, and this application make an user to get leave history using a Mobile System from SUP.
    I've created the MBO as Attributes using the BAPI: BAPI_LEAVE_HISTORY.
    This BAPI has some parameters IN and OUT.
    Input parameters are Employee Id and date.
    The parameter OUT is a List that retreives the employee leave history.
    Anyone has an Idea or example how to retreive the output from BAPI and displaying the output on a screen.
    Any tips or blogs that can help me?
    Thanks all!
    Satish

    Hi David Brandow,
    I have tried your solution where I just created a MBO for my 'operation' and I'm using sync parameters to execute the RFC.
    The problem I'm facing is, for example, if I create a record it gets saved in the MBO table and the record successfully gets created in SAP as well after a sync. But when I create another record and sync, the previously saved record in MBO table also gets executed so I'm getting duplicate entries in SAP.
    Have you or anyone faced this problem?
    Any response is appreciated. Please let me know if I'm not clear, I realized its a complicated scenario.
    Thanks,
    Sandeep

  • How to Embbed Tomcat in Java Application

    Hi
    At the moment i have the basic setup of applicatoin like this
    first i run the file "Tomcat.bat" that start the tomcat server, in a specific directory and also the webservice is enabled.
    Secondly then i run the Program.java that uses the web service started in the first step.
    However, now i want to start the webservice (Apache Tomcat) from with in the Java Application. So that whenever, i need to i can start it. I also need the control over ports, so as to which port should the tomcat run on...
    So at the end of the my simple question is how to run tomcat from with in a java application. At the moment i can not use the Runtime.exec() since this is a real time application and using Runtime.exec() causes some problems over the locking of threads...
    Any Help would be greatly appreciated.
    Thanks for looking.

    i looked at the my catalina.sh script file and see that java runs "org.apache.catalina.startup.Bootstrap" class first so that i think by instaitating that class and preparing the parameters that needed will start the tomcats "org.apache.catalina.startup.Bootstrap" class and that class will load all the needed parts and start serving request.
    and how to change starting port ? i thought that you can generate the server.xml on fly and after creating that file you can start tomcat.
    these are my opinion but i think these are true,i have no time to try this if i can i will write here.or if somebody can try write here.

  • Passing Runtime initialization parameters to a Servlet

    Hi all.
    Plz.let me know, how do you pass runtime initialization parameters to a Servlet. Also, when do we need this approach. Thank You.

    Global parameters that may change should be passed as parameters so that the servlet doesn't have to be recompiled to make the change.
    Here a global parameter is used to store a timeOut value. This value is written to every web page to force the page to refresh.
    <web-app>
        <servlet>
            <servlet-name>
                KioskServlet
            </servlet-name>
            <servlet-class>
                KioskServlet
            </servlet-class>
            <init-param>
                <!-- number of seconds of inactivity until timing out -->
                <!-- 300 = 5 minutes -->
                <param-name>timeoutValue</param-name>
                <param-value>300</param-value>
            </init-param>
         </servlet>
    </webapp>

  • How to implement a connection pooling in servlet

    hi all,
    how to implement a connection pooling in servlet.i want to know how to implement it in tomcat in a struts based environment.
    any input to the topic is appreciated.
    Thanks
    Sudha

    Take a look at JNDI
    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

  • How to make tomcat 5 support SSL (https)?

    Hi,
    is there a way to make tomcat support SSL (https)?
    i using: Apache 1.3.33
    with : Tomcat 5.0.28-1.00RC2
    and : jakarta-tomcat-connectors-jk-1.2.6
    JDK: j2sdk1.4.0_04
    Many thanks
    Anatolia

    Thanks very much Sherbir,
    But JSSE is integrated into the Java 2 SDK, Standard Edition, v 1.4 and above!
    here is what i'm facing:
    the documentation says:
    >
    It is important to note that configuring Tomcat to take advantage of secure sockets is usually only necessary when running it as a stand-alone web server. When running Tomcat primarily as a Servlet/JSP container behind another web server, such as Apache or Microsoft IIS, it is usually necessary to configure the primary web server to handle the SSL connections from users. Typically, this server will negotiate all SSL-related functionality, then pass on any requests destined for the Tomcat container only after decrypting those requests. Likewise, Tomcat will return cleartext responses, that will be encrypted before being returned to the user's browser. In this environment, Tomcat knows that communications between the primary web server and the client are taking place over a secure connection (because your application needs to be able to ask about this), but it does not participate in the encryption or decryption itself.
    I'm running running Tomcat as a Servlet/JSP container behind Apache 1.3.33 web server.
    So all SSL requests are handled by apache web server, but the problem I'm facing is that if i request any jsp page using https (ssl) i get plain text and it's not handled by tomcat!
    i have a test page called test.jsp:
    <html>
    <head>
    <title>JSP test page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <p>2 x 2 = <%= 2 + 2 %>
    </p>
    </body>
    </html> If I request this page using normal http request I get my results fine:
    2 x 2 = 4
    but if i request the page using https (ssl) I get a clear plain text of my jsp file content like this:
    <html>
    <head>
    <title>JSP test page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <p>2 x 2 = <%= 2 + 2 %>
    </p>
    </body>
    </html> Now how do I fix this problem and make apache passes the jsp file to tomcat if the request was https (ssl) and not send me cleartext of my file content!
    Many thanks
    Anatolia

  • How good is Tomcat ....

    Hi, just curious to know how well the Tomcat app-server performs in comparison to other servers. Can it handle large amounts of simultaneous users, and what would be the main differences between Tomcat and ones like SunONE, WebLogic, Websphere(besides price).
    Thanks

    Tomcat is a servlet/JSP engine. All the others that you mentioned are J2EE app servers that run EJBs in addition to servlets and JSPs.
    Benchmarks are dicey things: they can be manipulated.
    But with that in mind, Google turned these up for a search on "servlet engine performance benchmarks":
    http://www.webperformanceinc.com/library/ServletReport/
    http://www.intelliware.ca/individualmessages/2002/11/408.html
    http://www.theserverside.com/reviews/index.jsp
    MOD

  • Parameterized constructor in servlets

    why can't we use parameterized constructor in servlets?
    please describe it briefly?

    Why should you use parametrized constructor with servlet? If you want to pass any parameter then use <init-param> in web.xml. Even if you make parameterized constructor, how it would be invoked? Servlet container creates instance of servlet by invoking common constructor.
    So do you intent to rewrote container to invoke parameterized constructor?
    Please refer servlet documentation for more information on servlets and it would help you.

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

Maybe you are looking for

  • Return Purchase Orders- CESS ACCOUNT NOT GET Debited in MIGO

    Dear Expert, We are implementing Return PO procedure for Materials. Business scenario : Goods received from vendor during Material receipt Stock Account debited and GR/IR Clearing account Credited and Cess account Credited further during Invoice Post

  • Ipod not recognized when using an external hardrive, please help me!

    I have a 4 gig ipod mini, I have been using it for over a year with no problems. recently, my computer will not recognize my ipod when it is plugged in with my external hardrive. I have chosen to keep all of my music on a 100 gig external hardrive, b

  • PSE10 - Keyword tags not all showing when tagging faces?

    When I import a new picture, if I manually add a face tagging box, then click on the text box and type the first letter of a name, only certain of my keyword tag names show up? Some do not??? For instance, if I have the names Bella, Bill and Bess alr

  • Script to Copy preference file to all users profiles and to the default template

    I have build a package using Apple PackageMaker, this will install an application and a preference (plist) file to the current logged in user. Now I wanted to build a postflight script, which can copy a plist (ex com.test.plist) form an current logge

  • BPC 7.5 MS END OF MAINSTREAM MAINTENANCE

    Dear BPC Friends As you know the end of mainstream maintenance for the version SAP BPC 7.5 MS  is 31.03.2016. What does it mean? Which will be the risk involved if we don't upgrade and we continue to work on this version in the next years until 2018?