Java Send Email (In a Jar)

| Posted by watashii | Filed under Java, Programming

Step 1

Download the JavaMail and Activation Framework library .jar files

• If using Java SE, you’ll need to download JavaMail, eg mail-1.4.3.jar

• If using below Java SE 6, you’ll need to download and include Activation Framework, eg activation-1.1.1.jar
Read the rest of this entry »

Tags: , , ,

Start & Stop Weblogic Without Username & Password

| Posted by watashii | Filed under Database, Web

In a Weblogic Server domain running in production mode, username and password is always prompted during startup and shutdown (admin server and managed servers).  To bypass this manual step, we can store the username and password credentials in the boot.properties file (although this is somewhat the same as development mode)…

Read the rest of this entry »

Tags: , , ,

Weblogic Portal Authorization – Get and Check User’s Roles

| Posted by watashii | Filed under Java, Programming, Web

The Authorization class provides runtime methods for security policies and roles checks.  The following code fragment obtains the set of roles the logged-in user belongs to.  Note the user must be authenticated first, see Authentication class.

String entAppName = ApplicationHelper.getNonVersionedAppName();
String webAppName = ApplicationHelper.getWebAppName(request);
EnterpriseRoleResource resource = new EnterpriseRoleResource(entAppName,webAppName,EntitlementConstants.P13N_ROLE_POLICY_POOL,"");
Map userRoles = Authorization.getRoles((P13nResource) resource);
if (Authorization.isUserInRole("Admin", userRoles)) {
	return true;
}

Global and Enterprise Application roles are obtained using EnterpriseRoleResource.  For Global, Enterprise, and Web Application roles, use WebappRoleResource.

com.bea.p13n.security.Authentication

Tags: , , , ,

Getting the HttpServletRequest from PortletRequest Object

| Posted by watashii | Filed under Java, Programming, Web

In my JSF / icefaces based portlet running on Weblogic Portal, I got the following error:
com.icesoft.faces.webapp.http.portlet.PortletExternalContext cannot be cast to javax.servlet.http.HttpServletRequest

It turned out I cannot simply obtain the HTTPServletRequest object like this:

FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest portletRequest = (HttpServletRequest) ctx.getCurrentInstance().getExternalContext().getRequest();

In a portlet environment, to get the request/response objects, we must obtain the javax.portlet.PortletRequest/PortletResponse objects instead (which inherits methods from java.servlet.HTTPServletRequest/HTTPServletResponse):

FacesContext ctx = FacesContext.getCurrentInstance();
PortletRequest portletReq = (PortletRequest) ctx.getExternalContext().getRequest();

However sometimes we may require the HttpServletRequest / HttpServletResponse object.  To obtain this, we must extract an attribute from the PortletRequest / PortletResponse object:

FacesContext ctx = FacesContext.getCurrentInstance();
PortletRequest portletReq = (PortletRequest) ctx.getExternalContext().getRequest();
HttpServletRequest httpServletReq = (HttpServletRequest) portletReq.getAttribute("javax.servlet.request");

Tags: , , , , , ,

Reading Portlet Preferences in Weblogic Portal

| Posted by watashii | Filed under Programming, Web

Portlet preferences enables portlets to be associated with external application data.  This data should generally be used to store (or update) configuration data in a portlet.  For example, to store/update dynamic stock codes in a stock quotes portlet.  A portlet preference is basically a name-value pair data structure.

Portlet preferences can be added/updated in the following ways:

  1. During design-time on Workshop for Weblogic Portal (screenshot above)
  2. Invoked programmatically at request-time using javax.portlet.* API
  3. Manually during run-time of a portal (via Portal Administration Console when a portal desktop is created)

When we have added our preferences, we can read them using using the Weblogic Portal API’s.  The following sample code fragments are for JSP Portlets, and JSF Portlets:

Read the rest of this entry »

Tags: , , , , ,

Encrypt Passwords With Weblogic Server

| Posted by watashii | Filed under Database, Web

In a Weblogic Server environment, sometimes passwords must be unavoidably stored in text files, for example database connection details within JDBC configuration files.  When running Weblogic in production mode, only encrypted password is accepted to ensure that the password is never exposed as clear text.  To generate the encrypted password, the weblogic.security.Encrypt utility can be used, which generates a hashed password with a “{3DES}” prepended.

In Unix environment:

$ cd /opt/bea/user_projects/domains/mydomain/bin
$ . setDomainEnv.sh
$ java weblogic.security.Encrypt mycleartextpasswordhere
{3DES}xLLwrOm7asb4imZOYYwxz5TcBqDBEe6S

In Windows environment:

C:\>cd c:\bea\domains\mydomain\bin
C:\bea\domains\mydomain\bin>setDomainEnv.cmd
C:\bea\domains\mydomain\bin>java weblogic.security.Encrypt mycleartextpasswordhere
{3DES}lieJgIkTqg1xSBBoy3YxnHbPuz+tMxhY

Note that running the same command on different environment (or different Weblogic server installation) will produce a different password.

Tags: , , , ,

Disable Google Reader’s Social Features (Antisocial Mode)

| Posted by watashii | Filed under Web

If you like reading your feeds on Google Reader however dont use the social features (eg sharing items and following other people), there is a way to turn off this feature.

Read the rest of this entry »

Tags: , , ,

Simple Content Repository Search Example

| Posted by watashii | Filed under Java, Programming, Web


Here is a simple code fragment to perform search on the Weblogic Portal 10 Content Repository using the search api.  The important part is the query string to extract the content, and the sort order. Some examples here.
Read the rest of this entry »

Tags: , , , ,

Using JSF 1.2 on Oracle Workshop for Weblogic (Portal 10.3)

| Posted by watashii | Filed under Java, Programming, Web

When choosing facets during the creation of a new portal web project, the built-in Sun RI JSF 1.2 (together with JSTL 1.2)  facets cannot be selected.  Here are the recommended (by Oracle) steps to get around this problem.  Note that this is because Apache Beehive Page Flow has a dependecy with  JSF 1.2, therefore only follow this if not using the page flow integration components provided by Beehive.

Read the rest of this entry »

Tags: , , , ,

Oracle Timezone Conversions – GMT to localtime (and back)

| Posted by watashii | Filed under Database, Programming

clock

GMT to Local Time

Convert a datetime value (which has no timezone info, but assumed as GMT/UTC) to a local datetime (based on timezone parameter as set by SESSIONTIMEZONE, eg ‘+11:00′):

SELECT CAST((FROM_TZ(CAST(TO_DATE('1999-12-01 11:00:00',
'YYYY-MM-DD HH24:MI:SS') AS TIMESTAMP), 'GMT')
AT LOCAL) AS DATE) "Local Time"
FROM DUAL;

Local Time
--------------------------------------------------
1/12/1999 10:00:00 PM

Read the rest of this entry »

Tags: , , , ,