Monday, June 4, 2012

Selective tracing for Oracle SOA Suite


Selective tracing for Oracle SOA Suite:

In a production system, setting the trace at a fine-grained level can result in a large amount of output that must be diagnosed. You can alternately use selective tracing that provides a way to get a detailed, on-disk trace selectively (for example, by user name, thereby eliminating trace output for other users).

In Oracle SOA Suite 11g:

Activate the selective tracing:

  • Right-click the domain under WebLogic Domain and choose Logs > Selective Tracing.



Sunday, June 3, 2012

Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 11g


Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 11g

Sometimes we may need to restrict the access to the SOA composite service based on the user role.
HTTP basic authentication and an authorization policy can be used to ensure that access is only granted to users who are members of a particular role.

This blog will explain the steps to enable authorization to our composite service. 

Configure the Users and Group:

  • Login to the Weblogic console ('http://<host>:<port>/console')
  • In the left menu select 'Security Realms'
  • Select the realm where you want to create the users and groups.  The default is 'myrealm'
  • At the top select the 'Users and Groups' tab
  • Select User tab and Click 'New' and enter your user name and pwd.  Here am creating the user albin and albin1, create as many users as you want
  • Select ‘Groups’ tab and create a new group.  Here I am creating  ‘IntegrationGroup’
  • Go back to the users and click on  'Albin'
  • Select the 'Groups' tab and add ‘IntegrationGroup’.  The user albin1 will not be part of this group.

Configure the Application Role:

  • Login to EM console
  • Right Click on WebLogic Domain -- >Select Security and Click on Application Roles

  •  Click on 'Create' to configure a new Application Role



Invoking a web service from the composite with HTTP Basic authentication – Oracle SOA Suite

Invoking a web service from the composite with HTTP Basic authentication  – Oracle SOA Suite 11g

Sometimes we may need to invoke the HTTP Basic authentication enabled web service from the  Oracle SOA Suite composite.
This blog will explain the steps to invoke the web service with the HTTP basic authentication enabled.

Configure the credential store:

The credential should be configured in the credential store to invoke the web service with the HTTP Basic authentication enabled.

If the credential store is not configured already then follow the below steps to do the same.
  • Login to EM
  • Right Click on WebLogic Domain - Select Security and Click on Credentials


The same will work in Oracle SOA Suite 12c but the screens will be little different.

oracle_soa_12c_credential_map


  • Click on Create Map


Saturday, June 2, 2012

Enabling the HTTP Basic authentication to the Composite Service (Invoking a composite with HTTP authentication) – Oracle SOA Suite 11g

Enabling the HTTP Basic authentication to the Composite Service (Invoking a composite with HTTP authentication) – Oracle SOA Suite 11g

Sometimes we may need to enable the security like HTTP basic authentication to the composite service, so that the client can securely invoke our services providing the username/password.
This blog will explain the steps to enable HTTP basic authentication to our composite service. 

Configure the Authentication policy to the Composite Service:

  • Open the composite.xml   
  • Right click on the client service and click on Configure WS Polices


  •  Add the security Policy oracle/wss_http_token_service_policy for authentication in the security section.




Tuesday, May 29, 2012

Some handy JSF utility methods

Some handy JSF utility methods:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.faces.application.*;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import javax.servlet.http.HttpSession;
import oracle.adf.view.faces.model.UploadedFile;


public class JSFUtils {

    private static final String NO_RESOURCE_FOUND = "Missing resource: ";

    /**
       * Method for taking a reference to a JSF binding expression and returning
       * the matching object (or creating it)     
       */
    public static Object resolveExpression(FacesContext ctx,
                                           String expression) {
        Application app = ctx.getApplication();
        ValueBinding bind = app.createValueBinding(expression);
        return bind.getValue(ctx);
    }

    /**
       * Convenience method for resolving a reference to a managed bean by name
       * rather than by expression
       */
    public static Object getManagedBeanValue(FacesContext ctx,
                                             String beanName) {
        StringBuffer buff = new StringBuffer("#{");
        buff.append(beanName);
        buff.append("}");
        return resolveExpression(ctx, buff.toString());
    }

    /**
       * Method for setting a new object into a JSF managed bean
       * Note: will fail silently if the supplied object does
       * not match the type of the managed bean
      */
    public static void setExpressionValue(FacesContext ctx, String expression,
                                          Object newValue) {
        Application app = ctx.getApplication();
        ValueBinding bind = app.createValueBinding(expression);
       
        Class bindClass = bind.getType(ctx);
        if (bindClass.isPrimitive()||bindClass.isInstance(newValue)) {
            bind.setValue(ctx, newValue);
        }
    }

    /**
       * Convenience method for setting the value of a managed bean by name
       * rather than by expression
       */
    public static void setManagedBeanValue(FacesContext ctx, String beanName,
                                           Object newValue) {
        StringBuffer buff = new StringBuffer("#{");
        buff.append(beanName);
        buff.append("}");
        setExpressionValue(ctx, buff.toString(), newValue);
    }


    /**
       * Convenience method for setting Session variables
      */
    public static

    void storeOnSession(FacesContext ctx, String key, Object object) {
        Map sessionState = ctx.getExternalContext().getSessionMap();
        sessionState.put(key, object);
    }

    /**
       * Convenience method for getting Session variables
      */
    public static Object getFromSession(FacesContext ctx, String key) {
        Map sessionState = ctx.getExternalContext().getSessionMap();
        return sessionState.get(key);
    }


    /**
       * Pulls a String resource from the property bundle that
       * is defined under the application &lt;message-bundle&gt; element in
       * the faces config. Respects Locale
       */
    public static String getStringFromBundle(String key) {
        ResourceBundle bundle = getBundle();
        return getStringSafely(bundle, key, null);
    }


    /**
       * Convenience method to construct a <code>FacesMesssage</code>
       * from a defined error key and severity
      */
    public static FacesMessage getMessageFromBundle(String key,
                                                    FacesMessage.Severity severity) {
        ResourceBundle bundle = getBundle();
        String summary = getStringSafely(bundle, key, null);
        String detail = getStringSafely(bundle, key + "_detail", summary);
        FacesMessage message = new FacesMessage(summary, detail);
        message.setSeverity(severity);
        return message;
    }

    /*
       * Internal method to pull out the correct local
       * message bundle
       */

    private static ResourceBundle getBundle() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        UIViewRoot uiRoot = ctx.getViewRoot();
        Locale locale = uiRoot.getLocale();
        ClassLoader ldr = Thread.currentThread().getContextClassLoader();
        return ResourceBundle
        .getBundle(ctx.getApplication().getMessageBundle(), locale, ldr);
    }

    /*
       * Internal method to proxy for resource keys that don't exist
       */

    private static String getStringSafely(ResourceBundle bundle, String key,
                                          String defaultValue) {
        String resource = null;                                         
        try {                                         
            resource = bundle.getString(key);
        }
        catch (MissingResourceException mrex) {
            if (defaultValue != null) {
                resource = defaultValue;
            } else {
                resource = NO_RESOURCE_FOUND + key;
            }
        }
        return resource;
    }
    /**
     *
     * @param msg
     */
    public static void addFacesErrorMessage(String msg) {
        FacesContext ctx = getFacesContext();
        FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,msg,null);
        ctx.addMessage(getRootViewComponentId(),fm);
      }
      /**
     *
     * @return
     */
    public static FacesContext getFacesContext() {
         return FacesContext.getCurrentInstance();
       }
       /**
     *
     * @return
     */
    public static String getRootViewComponentId() {
         return getFacesContext().getViewRoot().getId();
       } 
       /**
     *
     * @param beanname
     * @return
     */
       public static Object getBeanByName(String beanname) {
           FacesContext ctx = getFacesContext();
           Application app = ctx.getApplication();    
           return app.getVariableResolver().resolveVariable(ctx,beanname);
       }
      
       
     
    public static void  addValuesToSession(String key,String value) {
   
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        session.setAttribute(key, value);
       
    }
   
 
}