Showing posts with label Weblogic. Show all posts
Showing posts with label Weblogic. Show all posts

Monday, June 21, 2010

Configuring a New Oracle SOA Domain on Oracle Enterprise Linux

Introduction

With the current trend of having 64 bit as the new desktop standard, then you would most likely come into a situation where you have a hard time deciding what OS to buy that can support your software development tasks, while not being left behind. That OS selection decision is made simpler by the advent of Virtualization wherein you can have multiple OS on a single hardware machine.
In this series, I will share with you how I was able to set-up and run Oracle SOA Suite on my Windows 7 Professional 64 bit OS through Oracle VM VirtualBox.

This is Part V of the following series:
  1. Setting-up Oracle Enterprise Linux on Oracle VM VirtualBox 3.2.4
  2. Installing Java 1.6 on Oracle Enterprise Linux
  3. Installing Weblogic 10.3.3 on Oracle Enterprise Linux
  4. Installing Oracle SOA Suite 11.1.1.3 on Oracle Enterprise Linux
  5. Configuring a New Oracle SOA Domain on Oracle Enterprise Linux

Prerequisites

  1. Installed Oracle VM VirtualBox.
  2. Installed Oracle Enterprise Linux (OEL) on VirtualBox as described in the Part I of this series.
  3. Installed Java 1.6.0_20 on OEL as described in Part II of this series.
  4. Installed WebLogic 10.3.3 as described in Part III of this series.
  5. Installed Oracle SOA Suite 11.1.1.3 as described in the Part IV of this series.
  6. You should have a valid database somewhere which is properly configured with the Repository Creation Utility (RCU).

Configuration Steps

Navigate to "MIDDLEWARE_HOME/Oracle_SOA1/common/bin" directory.
Right-click inside the directory and select "Open in Terminal".
Enter "./config.sh".
Select "Create a new WebLogic domain" and Next.
Check the appropriate products as shown in the screenshot.
Accept default domain name and directories.
Next.
Enter your password for weblogic.
Ensure that the Java 1.6 64 bit that we installed in the Part II of this series is available and selected in the list.
Next.
Select all the schema and provide the appropriate values for the following:
  • Service Name
  • Hostname
  • Password
  • Port

Next.
Next.
Next.
Create.
Done.

Running and Testing the Servers

Navigate to "MIDDLEWARE_HOME/user_projects/domains/base_domain/bin".
Right-click then select "Open in Terminal".
To start the Admin Server, enter "./startWebLogic.sh". (Note: Case-sensitive)
To start the SOA Server, Click File>Open Tab to open a new terminal tab on the same directory.
Enter "./startManagedWebLogic.sh soa_server1".
Enter username: "weblogic" and the password you entered in the steps above.
The SOA Server is already running when you see in the log "SOA Platform is running and accepting request".
If you are connected to a network then you can test logging-in to enterprise manager from a remote pc or from your host OS. But before so, we need to know the ip of our Oracle Enterprise Linux virtual machine.
To know the ip, in a terminal window, enter "/sbin ifconfig".
Get the ip information for use in the step below.
Open a new browser and enter "http://the_ip_above:7001/em"
Successfully log-in to enterprise manager from remote pc.

Tuesday, April 13, 2010

ADF Security: Playing with Weblogic APIs on Authentication Providers

As promised in my last post, in this post I will share with you how to play with the Weblogic API through JMX to handle tasks such as creating users, creating roles, assigning users to roles, and letting users change their own password. This post will clear out the gray areas in implementing user subscription or registration forms and the generation of salted-hashed passwords that can be recognized by weblogic. This post assumes that you have already properly set-up your SQLAuthenticator provider in weblogic.

Though this post is specific to SQLAuthenticator, the concept demonstrated herein is applicable to the Weblogic API as a whole. Just changing the MBEAN_INTERFACE constant to "weblogic.security.providers.authentication.DefaultAuthenticatorMBean", this post already applies to the DefaultAuthenticator.

Prerequisites

  • Setup the SQLAuthenticator required schema
  • Create a Datasource in weblogic console that points to the schema in step 1.
  • Setup SQLAuthenticator provider in weblogic console.

Implementation

The key to playing with Weblogic APIs is through JMX (Java Management Extensions). I cant tell through experience that understanding JMX is not for the faint-hearted, but if you got it, you will realize how simple it is. Below is a sample adapter class that I device so that I will deal with JMX only once, and the rest of my application that needs to access the weblogic API will just point to my adapter class.
package soadev.adapters;

import java.io.Serializable;
import java.io.IOException;
import java.util.Hashtable;
import javax.management.Descriptor;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

public class SQLAuthenticatorAdapter implements Serializable {
    private static final String MBEAN_INTERFACE = "weblogic.security.providers.authentication.SQLAuthenticatorMBean";
    private MBeanServerConnection connection;
    private JMXConnector connector;
    private ObjectName providerON;
    
    
    public void createUser(String username, String password,
                           String description) throws Exception {
        connection.invoke(providerON, "createUser",
                          new Object[] { username, password, description },
                          new String[] { "java.lang.String",
                                         "java.lang.String",
                                         "java.lang.String" });
    }
    
    public void createGroup(String groupName, String description) throws Exception {
        connection.invoke(providerON, "createGroup",
                          new Object[] { groupName, description },
                          new String[] { "java.lang.String",
                                         "java.lang.String" });
    }
    
    public void addMemberToGroup(String groupName, String username)throws Exception{
        connection.invoke(providerON, "addMemberToGroup",
                          new Object[] { groupName, username },
                          new String[] { "java.lang.String", "java.lang.String" });
    }

    public void changeUserPassword(String username, String oldPassword,
                                   String newPassword) throws Exception {
        connection.invoke(providerON, "changeUserPassword",
                          new Object[] { username, oldPassword, newPassword },
                          new String[] { "java.lang.String",
                                         "java.lang.String",
                                         "java.lang.String" });
    }
    
    public boolean isMember(String parentGroupName, String memberUserOrGroupName, boolean recursive)throws Exception{
        return (Boolean) connection.invoke(providerON, "isMember",
                          new Object[] { parentGroupName, memberUserOrGroupName, recursive },
                          new String []{"java.lang.String", "java.lang.String", "java.lang.Boolean"});
    }
    
    private ObjectName getAuthenticationProviderObjectName(String type)throws Exception{
       
            ObjectName defaultRealm = getDefaultRealm();
            ObjectName[] atnProviders =
                (ObjectName[])connection.getAttribute(defaultRealm,
                                                      "AuthenticationProviders");
            ObjectName MBTservice =
                new ObjectName("com.bea:Name=MBeanTypeService,Type=weblogic.management.mbeanservers.MBeanTypeService");
            for (int p = 0; atnProviders != null && p < atnProviders.length;
                 p++) {
                ObjectName provider = atnProviders[p];
                ModelMBeanInfo info =
                    (ModelMBeanInfo)connection.getMBeanInfo(provider);
                Descriptor desc = info.getMBeanDescriptor();
                String className =
                    (String)desc.getFieldValue("interfaceClassName");
                String[] mba =
                    (String[])connection.invoke(MBTservice, "getSubtypes",
                                                new Object[] { type },
                                                new String[] { "java.lang.String" });
                for (int i = 0; i < mba.length; i++) {
                    if (mba[i].equals(className)) {
                        return provider;
                    }
                }
            }
            return null;
    }
    private ObjectName getDefaultRealm() throws Exception {
        ObjectName service =
            new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
        ObjectName domainMBean =
            (ObjectName)connection.getAttribute(service, "DomainConfiguration");
        ObjectName securityConfiguration =
            (ObjectName)connection.getAttribute(domainMBean,
                                                "SecurityConfiguration");
        ObjectName defaultRealm =
            (ObjectName)connection.getAttribute(securityConfiguration,
                                                "DefaultRealm");
        return defaultRealm;
    }
    public void connect(){
        String hostname = "localhost";
        String username = "weblogic";
        String password = "weblogic1";
        int port = 7101;
        connect(hostname, username, password, port);
    }
    
    public void connect(String hostname, String username, String password, int port){
        try {       
            String protocol = "t3";
            String jndi =
                "/jndi/weblogic.management.mbeanservers.domainruntime";
            JMXServiceURL serviceURL =
                new JMXServiceURL(protocol, hostname, port, jndi);
            Hashtable env = new Hashtable();
            env.put(Context.SECURITY_PRINCIPAL, username);
            env.put(Context.SECURITY_CREDENTIALS, password);
            env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                    "weblogic.management.remote");
            env.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
            connector = JMXConnectorFactory.connect(serviceURL, env);
            connection = connector.getMBeanServerConnection();
            providerON = getAuthenticationProviderObjectName(MBEAN_INTERFACE);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    public void close(){
        try {
            connector.close();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
}

Please update the connect() method with your own credentials and port information if necessary.

Below is a sample java client that utilize this adapter:
package soadev.client;

import soadev.adapters.SQLAuthenticatorAdapter;

public class SQLAuthenticatorAdapterClient {
    private SQLAuthenticatorAdapter adapter = new SQLAuthenticatorAdapter();
    public static void main(String[] args) {
    SQLAuthenticatorAdapterClient client = new SQLAuthenticatorAdapterClient();
       try {
           client.connect();
            client.testCreateUser();
            client.testCreateGroup();
            client.testAddMemberTopGroup();
            client.close();
        } catch (Exception e) {
            // TODO: Add catch code
            client.close();
            e.printStackTrace();
        }
    }
    
    public void testCreateUser()throws Exception{
        String username = "pino";
        String password = "password1";
        String displayName = "Pino SOADEV";
        adapter.createUser(username, password, displayName);
    }
    
    public void testCreateGroup()throws Exception{
        String groupName = "SOADevGroup";
        String description = "This is a especial group created through SQLAuthenticatorAdapter";
        adapter.createGroup(groupName, description);
    }
    
    public void testAddMemberTopGroup()throws Exception{
        String username = "pino";
        String groupName = "SOADevGroup";
        adapter.addMemberToGroup(groupName, username);
    }
    
    public void close(){
        adapter.close();
    }
    public void connect(){
        adapter.connect();
    }
}

Be sure that "Weblogic 10.3 Thin-Client" is included in the libraries and classpath of your client project.

After running the client above, you will see that user "pino", group "SOADevGroup, and the assignment of user "pino" to group "SOADevGroup" were persisted respectively in the USERS, GROUPS, and GROUPMEMBERS tables.

Prototype

//TODO

Conclusion

This post demonstrates how easy it is to play with Weblogic API so that you have something as reference to jump-start your own implementation. More interfaces can be implemented by referring to the resources below. Be wary the examples above do not exemplify proper exception and concurrency handling.

Cheers!

Pino

Resources

Sunday, February 28, 2010

Setting Proxy Authentication in Java (weblogic.net.http.HttpUnauthorizedException: Proxy or Server Authentication Required)

weblogic.net.http.HttpUnauthorizedException: Proxy or Server Authentication Required
 at weblogic.net.http.HttpURLConnection.getAuthInfo(HttpURLConnection.java:284)
 at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:455)
 at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:36)
 at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:112)
 ... 45 more
I encountered the above error while attempting to test my Oracle ADF sample application that integrates with the Google Translate behind a proxy. I believe this error applies when your application tries to access the internet while behind a firewall that requires proxy authentication.

Below are the steps that resolved the issue above:
  1. Extend java.net.Authenticator class and override the getPasswordAuthentication() method.
  2. Set System properties for the http:proxyHost, http:proxyPort
  3. Set your custom authenticator above as the default authenticator.
  4. Modify the instantiation of the URL
Below is my custom authenticator:
package soadev.blogspot.googletranslateapi.common;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class MyAuthenticator extends Authenticator {
    private String username;
    private String password;
    public MyAuthenticator(String username, String password){
        this.username = username;
        this.password = password;
    }
    public PasswordAuthentication getPasswordAuthentication () {
        return new PasswordAuthentication (username, password.toCharArray());
    }

}
Below are the code snippets (as it applies to my case) that illustrates the steps above:
    System.setProperty("http.proxyHost", "myproxy");             
    System.setProperty("http.proxyPort", "8080");
    Authenticator.setDefault (new MyAuthenticator("XXXXXX\\username","password"));
Below is how I instantiate the external URL to be accessed:
...
final URL url = new URL(null, "http://your_external_URL", new sun.net.www.protocol.http.Handler());
notes for readers of my blogpost on leveraging the google translate api: To run your test behind proxy, you need to modify the execute() method of the Translate class to reflect the proper way of instantiating the URL.

Cheers!
pino

Sunday, January 10, 2010

Error: CFGFWK-60184: Configuring WebLogic Domain : Multiple dependency matches

Error: CFGFWK-60184: The template you selected can't be applied because the following dependencies have not been satisfied:
Unresolved ORs:
Or for Oracle SOA Suite:11.1.1.0
[C:\Oracle\Middleware\Oracle_SOA1\common\templates\applications\oracle.soa_template_11.1.1.jar] 
Multiple dependency matches: 
Oracle SOA Management Extension:11.1.1.0
[C:\Oracle\Middleware\jdeveloper\common\templates\applications\oracle.soa.mgmt_template_11.1.1.jar]
 Oracle SOA Management Extension:11.1.1.0
[C:\Oracle\Middleware\oracle_common\common\templates\applications\oracle.soa.mgmt_template_11.1.1.jar]

Screen shot reference:

To resolve such issue, delete or relocate the file oracle.soa.mgmt_template_11.1.1.jar from %MiddlewareHome%\jdeveloper\common\templates directory to a folder outside of the middleware home and make some note in your notebook so you can put it back if needed. :)
Please see the following discussion in otn forums for your perusal. http://forums.oracle.com/forums/message.jspa?messageID=4016709#4016709

Update: I believe I came to this issue because I invoked the configuration wizard bundled with the integrated WLS of JDeveloper. I should have invoked the configuration wizard of the installed stand-alone weblogic server.
In Windows XP:
Start > All Programs > Oracle SOA 11g Home > Configure application server