Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic, Containers Expo Blog

Weblogic: Article

How to Secure a Web Application

How to Secure a Web Application

While security is a concern throughout an application, it is especially important for Web application components. An insecure Web application leaves a Web site vulnerable to many attacks, some that require nothing more than an Internet browser and a small amount of knowledge.

The global and anonymous nature of the Internet means that a Web application can be attacked from anywhere in the world by individuals who frequently cannot be traced. Even if they are found, international law often makes prosecution all but impossible.

Java 2 Enterprise Edition (J2EE) provides many security features. Understanding when and how to use these features is complex and error prone. Furthermore, J2EE security falls short of satisfying many of the needs of Web application developers. BEA WebLogic Server implements all of the J2EE Web application security features and extends them to help complete some tasks that are impossible using J2EE APIs alone.

Web Application Security
J2EE provides two basic mechanisms for securing a Web application.

  • Encryption: There is a mechanism for specifying whether SSL (secure sockets layer) must be used when accessing a specific URL. When SSL is used, it ensures that the communication between the user's browser and the server can neither be viewed nor modified by intermediaries. SSL also allows users to verify that they are sending the (presumably confidential) information to the intended destination and not to an imposter.
  • Role-based security: Roles, a collection of permissions granted to users, allow a site to permit certain users access to different parts of the site. There is a declarative means of restricting specific URLs to users who belong to a set of roles, as well as a programmatic interface to determine if the current user is in a specific role.

    Sample Web Application
    Throughout this article, a sample application is developed. A skeleton of the application is available at www.sys-con.com/weblogic/sourcec.cfm. The skeleton contains all of the Web pages and deployment descriptors for the Web application but omits all content not directly pertinent to security.

    The application has been tested on BEA WebLogic Server 8.1. Besides deploying the Web application, two things must be done to enable it to run:

  • You must create a "Customers" group. This can be done under the Security >Realms >myrealm> Groups tab in the console. There is no need to populate the group, it just needs to be created. The application will populate it as needed.
  • You must create a user named "weblogic" and put it in the "Administrators" group. This can be done under the Security >Realm>myrealm >Users tab in the console.

    Why these actions are required will be explained as they arise.

    Encryption (SSL)
    In order to guarantee confidentiality while interacting with users, sites generally use SSL to perform encryption of sensitive pages. In the browser, SSL is signified by a URL beginning with "https" instead of "http".

    Unfortunately, as is the case with many security technologies, using encryption adversely affects performance. For this reason, SSL is typically enabled only for sensitive pages. A sensitive page is any page that contains confidential data, either outbound from the server or inbound from the user's browser via a form. There are a few exceptions to this rule.

    Non-sensitive pages that are in the middle of an otherwise secure conversation should generally be encrypted (e.g., an advertisement in the middle of a purchasing transaction). Besides being convenient for the developer, many browsers notify users with a prompt when the browser changes from an encrypted conversation to a clear-text conversation. To avoid these potentially confusing prompts, use encryption for these nonsecure pages.

    Also, pages that contain forms should be encrypted if the data to be filled in by the user will contain sensitive information. For example, consider a form that requires you to enter your name and credit card number. When the form is submitted it must use encryption to protect the confidential information, but the form itself, even if it does not contain confidential information, should be encrypted as well. This is needed because browsers generally display a lock in their bottom margin when a page has been encrypted. Some users will not enter secure data into a form if they don't see the lock. Note that this lock is irrelevant to whether the form data, the information the user actually wishes to secure, will be encrypted. The lock only signifies that the form has been encrypted. So, despite the lock usually being irrelevant, encryption should be used to ease users' concerns. You can require a page to be encrypted by specifying a transport guarantee of either "INTEGRAL" or "CONFIDENTIAL" (see for details).

    For a concrete example, consider a very simple Web application that allows online shopping. It contains the following files:

  • catalog.jsp: Allows browsing and searching of the catalog. Items can be added to the shopping cart from the catalog.
  • shoppingcart.jsp: Displays contents and allows manipulation of the shopping cart. Users can either purchase the cart's contents or shop further.
  • billinginfo.jsp: Gathers shipping address and billing information and POSTs it to orderstatus.jsp.
  • orderstatus.jsp: Executes the order. If successful, it displays a success message; if not, it returns to billinginfo to display the error and allow the user to correct it.

    Figure 1 shows the flow for this site as well as the required use of encryption. Only the orderstatus.jsp page requires the use of encryption, as the post of the form from billinginfo.jsp contains sensitive data. That being said, it is recommended that billinginfo. jsp be encrypted as well so that users see the lock on their browser's toolbar. Listing 1 shows a fragment of a web.xml that would be used to establish these encryption requirements.

     

     
    Figure 1: Site flow requiring encryption

    When you specify a <transport-guarantee> that requires encryption, BEA WebLogic Server will not allow a non-SSL connection to occur. If a non-SSL connection is attempted, WebLogic Server will send a redirection to the browser to cause it to access the page via SSL. This provides a convenient means of converting to SSL. That is, shoppingcart.jsp does not need to specify that SSL should be used for billinginfo. jsp. The application server will automatically ensure this. For example, in our example Web application, the link in shoppingcart. jsp to go to billinginfo.jsp is:

    <a href="billinginfo.jsp"> Checkout </a>

    It does not specify HTTPS. WebLogic Server will ensure that HTTPS is being used. Two issues that arise from this behavior are:
    1.  You should never rely on this automatic conversion from SSL for secure form data. Once the data is sent to the server unencrypted, it doesn't matter if it is resent encrypted. By making the form page encrypted, as the sample Web application does, it ensures that this problem doesn't occur. The request for the form may be sent twice, first unencrypted and then encrypted, but the secure information in the form data will only be sent encrypted.
    2.  There is no way to automatically go back to non-encrypted communication. If you never specify a protocol, once SSL is selected it will be used for the remainder of the interaction. In our example, all links back to the catalog explicitly specify HTTP. Due to its frequent use and large amount of data (especially pictures), encrypting the catalog would be a performance nightmare. In our example Web application, we explicitly specify HTTP whenever linking to the catalog, as in the following:

    <a
    href="http://<%=request.getServerName()%>:
    <%=request.getServerPort()%><%=request.getContextPath()%>
    /catalog.jsp"> Continue Shopping </a>

    Role-Based Security
    While encryption ensures that data that is being transmitted over the network is neither being read nor tampered with by intermediaries, it does this universally for all users. Role-based security, on the other hand, is used to break users up into classifications based on their intended permissions and then to grant access to Web pages based on these classifications.

    Role-based security should be used in one of two circumstances. First, when you have parts of the site that you wish to restrict to a subset of all users. In our example we will show how to restrict part of the site to the "Customer" role, but other roles are possible. For example, one can imagine adding more functionality, such as the ability to search orders, to the site to support customer support employees.

    The second circumstance where rolebased security should be used is when you need to know the identity of the user. The username might be needed for complex tasks such as maintaining statistics about which pages a user visits but also for simple tasks such as having a welcome message that includes the user name.

    The username can be obtained by calling

    request.getRemoteUser()

    This method only returns the username after the user has logged in. Prior to logging in, the user is anonymous and getRemoteUser() returns null. The simplest way to force a user to log in is to have them access a protected page. This forces the container to execute the login process, after which getRemoteUser() will return a valid username.

    In our example, shoppingcart.jsp requires login so that we can use the customer's username to look up their shopping cart in the database. While our sample does not actually access a database, it does print the username out in the header.

    To add role-based security to the above sample, we will add the ability to maintain a permanent record of all customers' shopping carts and purchases. To accomplish this, the Web application must ensure that only authenticated users are allowed to access the shopping cart. Once the users are authenticated, the shopping cart and order information can be stored in a database associated with the user. Figure 2 illustrates the new Web application and the use of role-based security in it. Listing 2 is a fragment of the web.xml used to configure this security. One feature to note is that there is no need to add an explicit link to the login.jsp page from catalog.jsp. Simply link to shoppingcart.jsp and, due to the <security- constraint> and <login-config> tags, the servlet container presents the login.jsp page for you. Precisely, it will interpose the login.jsp form whenever shoppingcart.jsp is referenced (or any protected page for that matter) and the current user has not logged in. Furthermore, if the current user turns out not to be a Customer, then they will receive an access-denied error page (i.e., HTTP error code 403).

     

     
    Figure 2: New Web application using role-based security

    Declarative vs Programmatic Security
    Specifying security in the deployment descriptor in this manner is called "declarative security." This is compared to "programmatic security," where the security is embedded in your code. Declarative security has some major advantages over programmatic security:

  • Simplicity: Security code tends to be difficult to write and error prone. Declarative security allows you to avoid writing security code and simply "declare" your security requirements, the servlet container takes care of the rest.
  • Ease of maintenance: When security is embedded in your program (i.e., programmatic security), a change in security means that code must be rewritten. With declarative security, frequently only the deployment descriptor needs to be altered. In our example, for instance, if the business requirements change such that only registered customers can access the catalog, the only change required would be to modify the tag in the deployment descriptor.
  • Separation of responsibility: Programming is typically done by engineers. Security is typically done by engineers, business analysts, application deployers, and others. If the application's security is embedded in the code, then only engineers can alter it. By embedding the security in the deployment descriptor, the security can be modified post-development without an engineer's involvement.

    Online User Registration
    Taking this example further, we can add pages to allow a new user to register. This flow is described in Figure 3. There is a "New User" link on the login.jsp form that takes the user to the newuser.jsp page. On this page, the user enters a username and password and then submits the form to the userstatus.jsp. If the user creation is unsuccessful, the userstatus.jsp will redirect back to the newuser.jsp page, displaying an appropriate error message at the top of the page. If the user creation is successful, userstatus.jsp logs the user in, prints a success message, and provides a link for the user to continue to their original destination.

     

     
    Figure 3: New user registration

    One thing to keep in mind as we extend this sample further is that while Figure 3 shows the login.jsp (and hence the newuser.jsp) page only being executed between catalog.jsp and shoppingcart.jsp, it is possible that it will appear in other places. Any time an unauthenticated user accesses a secure page, the login.jsp page can appear. Even if there are no links to the other pages (e.g., billinginfo.jsp), a user can type the URLs into a browser or they can bookmark the pages.

    After starting out with some argument processing, userstatus.jsp then creates a user. J2EE provides no standard mechanism for user creation but BEA WebLogic Server does via the UserEditorMBean interface. Once a UserEditorMBean is acquired, all that is needed is to call

    userEditorMBean.createUser(username, password, "");

    (The third argument is descriptive text about the user and not used in this example.) This operation is protected and is available only to users in the Admin role. To allow userstatus.jsp to execute correctly, it needs to have a run-as tag to cause it to be run as an Admin user. The deployment descriptor code is:

    <servlet>
    <servlet-name> userstatus </servlet-name>
    <jsp-file> /userstatus.jsp </jsp-file>
    <run-as>
    <role-name> weblogic </role-name>
    </run-as>
    </servlet>

    Remember to be sure to have created the "weblogic" user and put it in the "Administrators" group as described earlier to ensure this works.

    Once the user is created, the servlet logs the new user in. Programmatically logging in a user is not supported by J2EE either, but WebLogic Server allows this via the following lines:

    SimpleCallbackHandler callbackHandler =
    new SimpleCallbackHandler(username, password);
    ServletAuthentication
    .authenticate(callbackHandler, request);

    Finally, userstatus.jsp displays a success message and a link to continue. The difficulty here is that the destination of the link could be any protected page and is not limited to shoppingcart. jsp. This is because the authentication process can begin any time a protected page is accessed. While J2EE provides no mechanism for discovering the destination URL, WebLogic Server gives access to this via the following call:

    ServletAuthentication.getTargetURLForFormAuthentication
    (request.getSession())

    One thing to note here is that to make this work, the new user must be put into the Customer role. This is accomplished in a two-step process. First, the Customer role is mapped to the Customers group (a group is a collection of users – be sure this has been created as described above). This mapping is done in the weblogic.xml file with the following lines:

    <security-role-assignment>
    <role-name>Customer</role-name>
    <principal-name>Customers</principal-name>
    </security-role-assignment>

    Next, the Web application utilizes the WebLogic extension to put the new user into the Customers group in userstatus.jsp immediately after it is created by calling:

    groupEditorMBean.addMemberToGroup("Customers", username);

    Programmatic Security
    Programmatic security, while supported by J2EE, is risky business. It tends to lead to inflexible and error-prone code. One good use of the programmatic security APIs, though, is for personalization. Imagine extending our example above to include a link off the catalog page that allows you to update the catalog entry via updateentry.jsp. This link is applicable only to users in the CatalogAdmin role. The following code in catalog.jsp would introduce a conditional link for updateentry.jsp. This link will be visible only to users in the CatalogAdmin role in much the way the "Logout" link is visible only when a user is logged in.

    <% if (request.isUserInRole("CatalogAdmin")) { %>
    <a href="updateentry.jsp?productid=<%=getProductID()%>">
    Update Catalog Entry</a>
    <% } %>

    This code assumes that updateentry.jsp takes a productid argument and that a getProductID() method exists to return the ID of the product currently being displayed.

    Bringing It All Together
    Figure 4 illustrates the completed application's flow describing both encryption and role-based security. While encryption and role-based security must be combined to ensure security in a Web application, they are used for different purposes. Encryption is used to ensure security of data on the network. Role-based security is used to categorize users and grant permissions to them based on their categories. J2EE provides mechanisms of enabling both of these security features via the Web application's web.xml file. Furthermore, J2EE provides some standard mechanisms for programmatic security, such as accessing the user's name.

     

     
    Figure 4: Completed application's flow

    BEA webLogic Server's security extensions, such as the UserEditorMBean and the GroupEditorMBean, can be used for user management. User management features are not included in the J2EE standard. In our example, we used these user management features to implement online user registration, a feature common to many Web sites.

    BEA WebLogic Server also extends programmatic security, enabling a programmatic mechanism of logging into the server. By using ServletAuthentication.authenticate() and ServletAuthentication. getTargetURLForFormAuthentication(), our sample demonstrated how a user could be programmatically logged in and redirected to their original destination.

    These WebLogic Server extensions are designed to dovetail with the security features available for Web applications in J2EE. They fill gaps in the standard J2EE security functionality, allowing the implementation of richer and more functional Web applications.

    REPRODUCED WITH PERMISSION FROM BEA SYSTEMS.

  • More Stories By Neil Smithline

    Neil Smithline's main focus has been in optimizing the software life cycle from a product's initial concept through its retirement. This has included tools that affect development, programming techniques, software patterns, development processes, developer training, internal and external. For the past nine years he has directed these efforts almost exclusively to application security. He was the BEA Security Architect for over eight years. In this position Smithline co-designed the security framework for WebLogic Server that is now incorporated into most BEA products and becoming part of many Oracle products. During his tenure at BEA, he had the opportunity to interact with hundreds of customers; helping them develop their security architecture, processes, and strategies.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    @ThingsExpo Stories
    With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices t...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
    "Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
    @DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
    Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
    SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
    SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
    SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
    SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
    SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.