Quantcast
Channel: DevOps tips & tricks
Viewing all 181 articles
Browse latest View live

Java Authentication and Authorization Service (JAAS)

$
0
0

Functional x Imperative ?

$
0
0
http://rosettacode.org/wiki/Roman_numerals/Decode#Java

[dave@dave lisp]$ clisp 
i
. i i i I i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I I I 8 8 8 8 8 o 8 8
I I \ `+' / I I 8 8 8 8 8 8
I \ `-+-' / I 8 8 8 ooooo 8oooo
\ `-__|__-' / 8 8 8 8 8
`--___|___--' 8 o 8 8 o 8 8
| ooooo 8oooooo ooo8ooo ooooo 8
--------+--------

Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>




Code ( taken from Object Oriented Common Lisp )
defun roman-to-decimal  (num-list)
(if ( endp num-list)
0
(+ (or
(and (cdr num-list)
(< (numeral-to-decimal (car num-list))
(numeral-to-decimal (cadr num-list)))
(- (numeral-to-decimal (car num-list))))
(numeral-to-decimal (car num-list)))
(roman-to-decimal (cdr num-list)))))

(load "roman-to-decimal.lisp")

[7]> (roman-to-decimal '(M C M L X I X ))
1969
[8]> (trace roman-to-decimal)
;; Tracing function ROMAN-TO-DECIMAL.
(ROMAN-TO-DECIMAL)
[9]> (roman-to-decimal '(M C M L X I X ))
1. Trace: (ROMAN-TO-DECIMAL '(M C M L X I X))
2. Trace: (ROMAN-TO-DECIMAL '(C M L X I X))
3. Trace: (ROMAN-TO-DECIMAL '(M L X I X))
4. Trace: (ROMAN-TO-DECIMAL '(L X I X))
5. Trace: (ROMAN-TO-DECIMAL '(X I X))
6. Trace: (ROMAN-TO-DECIMAL '(I X))
7. Trace: (ROMAN-TO-DECIMAL '(X))
8. Trace: (ROMAN-TO-DECIMAL 'NIL)
8. Trace: ROMAN-TO-DECIMAL ==> 0
7. Trace: ROMAN-TO-DECIMAL ==> 10
6. Trace: ROMAN-TO-DECIMAL ==> 9
5. Trace: ROMAN-TO-DECIMAL ==> 19
4. Trace: ROMAN-TO-DECIMAL ==> 69
3. Trace: ROMAN-TO-DECIMAL ==> 1069
2. Trace: ROMAN-TO-DECIMAL ==> 969
1. Trace: ROMAN-TO-DECIMAL ==> 1969
1969



Haskell
http://www.haskell.org/haskellwiki/Roman_numerals#More-than-one_liner
http://www.cs.york.ac.uk/ftpdir/pub/haskell/contrib/Roman.hs
[dave@dave haskell]$ ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :l Roman.hs
[1 of 1] Compiling Main ( Roman.hs, interpreted )
Ok, modules loaded: Main.
*Main> fromRoman "MCMLXIX"
1969




Simple Java implementation
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RomanToDecimal {

public static Map<String, Integer> romanNumberMap = new HashMap<String, Integer>();
static {
// ( (I 1) (V 5) (X 10) (L 50) (C 100) (D 500) (M 1000)))
romanNumberMap.put("I", 1);
romanNumberMap.put("V", 5);
romanNumberMap.put("X", 10);
romanNumberMap.put("L", 50);
romanNumberMap.put("C", 100);
romanNumberMap.put("D", 500);
romanNumberMap.put("M", 1000);
}

public static void main(String[] args) {

roman2dec("IV");

roman2dec("LXIV");

roman2dec("XCVIII");

roman2dec("MCMLXIX");

}

private static int roman2dec(String roman) {

int out = 0;

List<Integer> list = new ArrayList<Integer>();

for (int i = 0; i < roman.length(); i++) {
list.add(romanNumberMap.get(String.valueOf(roman.charAt(i))));
}

System.out.println("list=" + list);

while (list.size() > 0) {
if ((list.size() > 1) && (list.get(0) < list.get(1))) {
out -= list.remove(0);
} else {
out += list.remove(0);
}
System.out.println(" list=" + list + " out=" + out);
}

System.out.println("roman=" + roman + " dec=" + out);

return out;

}

}



list=[1, 5]
list=[5] out=-1
list=[] out=4
roman=IV dec=4
list=[50, 10, 1, 5]
list=[10, 1, 5] out=50
list=[1, 5] out=60
list=[5] out=59
list=[] out=64
roman=LXIV dec=64
list=[10, 100, 5, 1, 1, 1]
list=[100, 5, 1, 1, 1] out=-10
list=[5, 1, 1, 1] out=90
list=[1, 1, 1] out=95
list=[1, 1] out=96
list=[1] out=97
list=[] out=98
roman=XCVIII dec=98
list=[1000, 100, 1000, 50, 10, 1, 10]
list=[100, 1000, 50, 10, 1, 10] out=1000
list=[1000, 50, 10, 1, 10] out=900
list=[50, 10, 1, 10] out=1900
list=[10, 1, 10] out=1950
list=[1, 10] out=1960
list=[10] out=1959
list=[] out=1969
roman=MCMLXIX dec=1969

Weblogic auto login with boot properties file

$
0
0
Weblogic requires JVM property -Dweblogic.system.BootIdentityFile to locate boot.properties file
How a Server Uses a Boot Identity File at Startup
http://docs.oracle.com/cd/E14571_01/web.1111/e13708/overview.htm#START132


# create boot properties file
${DOMAIN_HOME}/bin/createBootProperties.sh

#use boot.properties from AdminServer dir - this is necessary for weblogic.Admin to run without password
JAVA_OPTIONS="${JAVA_OPTIONS} -Dweblogic.system.BootIdentityFile=${DOMAIN_HOME}/servers/${SERVER_NAME}/security/boot.properties"

# add trust key store
SSL_ARGS="${JAVA_OPTIONS} -Dweblogic.security.SSL.trustedCAKeyStore=/weblogic/weblogic10.3/wlserver_10.3/server/lib/DemoTrust.jks -Dweblogic.security.SSL
.ignoreHostnameVerification=true"

# check if admin server is not already running
echo "Checking if admin server is not already running..."
${JAVA_HOME}/bin/java ${SSL_ARGS} weblogic.Admin -url t3s://localhost:7001 PING



Without JVM property attempt to call Weblogic without password returns following error

WebLogic server requires a valid username and password for the command that you are trying to execute. Please try again


Password and username can be encrypted by weblogic.security.Encrypt which is using domain key /app/domains/base_domain/security/SerializedSystemIni.dat
http://docs.oracle.com/cd/E21764_01/web.1111/e13749/utils.htm#ADMRF142
http://docs.oracle.com/cd/E13222_01/wls/docs92/admin_ref/utils.html#wp1209592

#!/bin/bash

WL_HOME=/app/weblogic122/wlserver_12.1
DOMAIN_HOME=/app/domains/base_domain

. $WL_HOME/server/bin/setWLSEnv.sh

BOOT_PROPERTIES_DIR=$DOMAIN_HOME/servers/AdminServer/security
BOOT_PROPERTIES_FILE=$BOOT_PROPERTIES_DIR/boot.properties

mkdir -p $BOOT_PROPERTIES_DIR

printf "username=" > $BOOT_PROPERTIES_FILE
java -Dweblogic.RootDirectory=/app/domains/base_domain weblogic.security.Encrypt weblogic >> $BOOT_PROPERTIES_FILE
printf "password=" >> $BOOT_PROPERTIES_FILE
java -Dweblogic.RootDirectory=/app/domains/base_domain weblogic.security.Encrypt weblogic123 >> $BOOT_PROPERTIES_FILE


[dave@dave java]$ more /app/domains/base_domain/servers/AdminServer/security/boot.properties 
username={AES}DG3YOrSwfkK0YrxUM+4cMf+wF91eYhhHpF4wFbsydp0=
password={AES}pkaZZGMqSWQwFEMJSj+FO0aY9LatGJTkz4CZ0Un5v64=




Domain Configuration Files
http://docs.oracle.com/cd/E14571_01/web.1111/e13716/config_files.htm#i1091725
servers/server-name/security
This directory holds security-related files that can be or must be different for each Oracle WebLogic Server instance. The file boot.properties is an example of a file that resides here because it can differ from one server to the next. This directory also maintains files related to SSL keys.

Tree traversal

$
0
0
http://en.wikipedia.org/wiki/Tree_traversal
http://en.wikipedia.org/wiki/Breadth-first_search
http://en.wikipedia.org/wiki/Depth-first_search

Tree traversal in various languages
http://rosettacode.org/wiki/Tree_traversal#Java

Algorithms
http://algs4.cs.princeton.edu/home/
Graphs
http://algs4.cs.princeton.edu/40graphs/
Directed Graphs

http://algs4.cs.princeton.edu/42directed/

Java Data Structure: A Generic Tree

http://sujitpal.blogspot.com/2006/05/java-data-structure-generic-tree.html


Generic Node
public class Node<T> {

public T data;
public List<Node<T>> children;
public List<Node<T>> parents;


Non-generic node
package dave;

/**
* Non-generic subclass of Node<String>
*/
public class DaveNode extends Node<String> {
public DaveNode() {
super();
}
}



Walk using stack
 /**
*
* @param element
* @return set of all nodes
*/
public List<Node<T>> walk(Node<T> element){

List<Node<T>> out = new ArrayList<Node<T>>();

Queue<Node<T>> q = new LinkedList<Node<T>>();
q.add(element);

while(!q.isEmpty()){
Node<T> x = q.poll();
out.add(x);

for(Node<T> child : x.getChildren()){
q.add(child);
}
}

return out;

}


Walk from bottom up
  /**
*
* @param element
* @return set of all upper nodes
*/
public Collection<Node<T>> pathBottomUp(Node<T> element){

Set<Node<T>> out = new LinkedHashSet<Node<T>>();

Queue<Node<T>> q = new LinkedList<Node<T>>();
q.add(element);

while(!q.isEmpty()){
Node<T> x = q.poll();
out.add(x);

for(Node<T> parent : x.getParents()){
q.add(parent);
}
}

return out;

}


Construct tree
package dave;


public class WalkTree {

public static void main(String[] args) {

DaveTree daveTree = new DaveTree();

DaveNode daveNode = getDaveNode("1");

DaveNode daveNode11 = getDaveNode("1.1");
DaveNode daveNode12 = getDaveNode("1.2");
DaveNode daveNode13 = getDaveNode("1.3");

DaveNode daveNode131 = getDaveNode("1.3.1");
DaveNode daveNode132 = getDaveNode("1.3.2");

daveNode.addChild(daveNode11);
daveNode.addChild(daveNode12);
daveNode.addChild(daveNode13);

daveNode12.addChild(daveNode131);

daveNode13.addChild(daveNode131);
daveNode13.addChild(daveNode132);


daveTree.setRootElement(daveNode);

System.out.println(daveTree.toList());

Node<String> root = daveTree.getRootElement();

System.out.println("walk:" + daveTree.walk(root));

System.out.println("pathBottomUp:" +daveTree.pathBottomUp(daveNode131));

}

private static DaveNode getDaveNode(String profileName){

DaveNode daveNode = new DaveNode();

daveNode.setData(profileName);

return daveNode;

}

}



Program output
[{1,[1.1,1.2,1.3]}, {1.1,[]}, {1.2,[1.3.1]}, {1.3.1,[]}, {1.3,[1.3.1,1.3.2]}, {1.3.1,[]}, {1.3.2,[]}]
walk:[{1,[1.1,1.2,1.3]}, {1.1,[]}, {1.2,[1.3.1]}, {1.3,[1.3.1,1.3.2]}, {1.3.1,[]}, {1.3.1,[]}, {1.3.2,[]}]
pathBottomUp:[{1.3.1,[]}, {1.2,[1.3.1]}, {1.3,[1.3.1,1.3.2]}, {1,[1.1,1.2,1.3]}]

Start ANTLR project with Maven

$
0
0
http://www.antlr.org/wiki/display/ANTLR3/Building+ANTLR+Projects+with+Maven

http://www.eclipse.org/m2e/
Download m2e
http://www.eclipse.org/m2e/download/





dave@dave antlr-maven]$ mvn archetype:generate -B -DarchetypeGroupId=org.antlr
-DarchetypeArtifactId=antlr3-maven-archetype
-DarchetypeVersion=3.3-1
-DgroupId=dave.antlr
-DartifactId=java-tree-walker
-Dversion=1.0
-Dpackage=dave.antlr
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository missing. Using the one from [org.antlr:antlr3-maven-archetype:3.4] found in catalog remote
Downloading: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.jar
Downloaded: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.jar (11 KB at 34.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.pom
Downloaded: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.pom (3 KB at 6.0 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: antlr3-maven-archetype:3.3-1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: davedave@dave antlr-maven]$ mvn archetype:generate -B -DarchetypeGroupId=org.antlr -DarchetypeArtifactId=antlr3-maven-archetype -DarchetypeVersion=3.3-1 -DgroupId=dave.antlr -DartifactId=java-tree-walker -Dversion=1.0 -Dpackage=dave.antlr
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository missing. Using the one from [org.antlr:antlr3-maven-archetype:3.4] found in catalog remote
Downloading: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.jar
Downloaded: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.jar (11 KB at 34.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.pom
Downloaded: http://repo1.maven.org/maven2/org/antlr/antlr3-maven-archetype/3.3-1/antlr3-maven-archetype-3.3-1.pom (3 KB at 6.0 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: antlr3-maven-archetype:3.3-1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave.antlr
[INFO] Parameter: artifactId, Value: java-tree-walker
[INFO] Parameter: version, Value: 1.0
[INFO] Parameter: package, Value: dave.antlr
[INFO] Parameter: packageInPathFormat, Value: dave/antlr
[INFO] Parameter: package, Value: dave.antlr
[INFO] Parameter: version, Value: 1.0
[INFO] Parameter: groupId, Value: dave.antlr
[INFO] Parameter: artifactId, Value: java-tree-walker
[INFO] project created from Archetype in dir: /usr/app/project/antlr-maven/java-tree-walker
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.303s
[INFO] Finished at: Sun Feb 26 10:40:25 CET 2012
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------



[dave@dave java-tree-walker]$ cat >dave.dmo
Keyser Soze ;
2 + 3;



java -jar target/java-tree-walker-1.0-jar-with-dependencies.jar dave.dmo

java -jar target/java-tree-walker-1.0-jar-with-dependencies.jar -dot dave.dmo




Schedule jobs with WorkManager

$
0
0
Leveraging EJB Timers for J2EE Concurrency
http://www.devx.com/Java/Article/33694/1954

The Work Manager API: Parallel Processing Within a J2EE Container
http://www.devx.com/Java/Article/28815/0


Using Work Managers to Optimize Scheduled Work
http://docs.oracle.com/cd/E14571_01/web.1111/e13701/self_tuned.htm#CNFGD112

Using CommonJ With WebLogic Server
http://docs.oracle.com/cd/E14571_01/web.1111/e13701/self_tuned.htm#i1069944


JBoss WorkManagerTaskExecutor
http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.html

Package commonj.work

http://docs.oracle.com/cd/E14571_01/apirefs.1111/e13941/commonj/work/package-summary.html

commonj.work.WorkManager

The WorkManager is the abstraction for dispatching and monitoring asynchronous work and is a factory for creating application short or long lived Works.

WorkManagers are created by the server administrator. The vendor specific systems management console allows the administrator to create one or more WorkManagers and associate a JNDI name with each one. The administrator may specify implementation specific information such as min/max Works for each WorkManager. An application that requires a WorkManager should declare a resource-ref in the EJB or webapp that needs the WorkManager. The vendor descriptor editor or J2EE IDE can be used to bind this resource-ref to a physical WorkManager at deploy or development time. An EJB or servlet can then get a reference to a WorkManager by looking up the resource-ref name in JNDI and then casting it. For example, if the resource-ref was called wm/WorkManager:
<resource-ref>
<res-ref-name>wm/WorkManager</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>


The Java code to look this up would look like:
  InitialContext ic = new InitialContext();
WorkManager wm = (WorkManager)ic.lookup("java:comp/env/wm/WorkManager");


The res-auth and res-sharing scopes are ignored in this version of the specification. The EJB or servlet can then use the WorkManager as it needs to.
When a Work is scheduled, the declared context that is present on the thread (the J2EE context) will be saved and propagated to the asynchronous methods that are executed. This J2EE context at minimum will contain the java:comp namespace and ClassLoader of the scheduler unless specified otherwise. Other J2EE contexts such as security or a transactional context may be optionally added by the application server vendor. Global transactions are always available using the java:comp/UserTransaction JNDI name and are used in the same fashion as they are used in servlets and bean-managed transaction Enterprise Java Beans.

A WorkManager can also be a pinned WorkManager. This is a WorkManager obtained using the RemoteWorkItem.getWorkManager method. This allows subsequent scheduleWorks to be send to the same remote WorkManager as the one that is associated with the RemoteWorkItem. Pinned WorkManagers are only supported on vendor implementations that support remote Works. However, applications that follow the programming model will work on all implementations however serializable Works will be executed within the local JVM only on those implementations.

If the scheduled Work is a daemon Work, then the life-cycle of that Work is tied to the application that scheduled it. If the application is stopped, the Work.release() method will be called.


Using the Job Scheduler
http://docs.oracle.com/cd/E14571_01/web.1111/e13733/toc.htm#i1058048

WorkManagerService
package dave;

import java.util.Collection;

import javax.ejb.Remote;

@Remote
public interface WorkManagerService {

public void processJob();

public void processTask(Task task);

public Collection<Task> processTasks(Collection<Task> tasks);

}




CommonJWorkManager
package dave;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import weblogic.work.ExecuteThread;

import commonj.work.Work;
import commonj.work.WorkEvent;
import commonj.work.WorkException;
import commonj.work.WorkItem;
import commonj.work.WorkManager;

/**
* Session Bean implementation class CommonJWorkManager
*/
@Stateless(mappedName = "WorkManagerService")
@LocalBean
public class CommonJWorkManager implements WorkManagerService {

@Resource(name = "daveWM")
WorkManager wm;

/**
* Default constructor.
*/
public CommonJWorkManager() {
// TODO Auto-generated constructor stub
}

public void processJob() {

try {
System.out.println("## [CommonJWorkManager] executing in: "
+ ((ExecuteThread) Thread.currentThread()).getWorkManager()
.getName());
wm.schedule(new Work() {
public void run() {
ExecuteThread th = (ExecuteThread) Thread.currentThread();
System.out
.println("## [CommonJWorkManager] self-tuning workmanager: "
+ th.getWorkManager().getName());
}

public void release() {
}

public boolean isDaemon() {
return false;
}
});

} catch (WorkException e) {
e.printStackTrace();
}

}

public void processTask(Task task) {

System.out.println("Plan task " + task.getName());

try {
System.out.println("## [CommonJWorkManager] executing in: "
+ ((ExecuteThread) Thread.currentThread()).getWorkManager()
.getName());

wm.schedule(new FibWork(task));

} catch (WorkException e) {
e.printStackTrace();
}

}

@Override
public Collection<Task> processTasks(Collection<Task> tasks) {

Collection<WorkItem> workItems = new ArrayList<WorkItem>();
Collection<Task> out = new ArrayList<Task>();

try {
System.out.println("## [CommonJWorkManager] executing in: "
+ ((ExecuteThread) Thread.currentThread()).getWorkManager()
.getName());

for (Task task : tasks) {
System.out.println("Plan task " + task.getName());
WorkItem workItem = wm.schedule(new FibWork(task));
workItems.add(workItem);
}
System.out.println("wm.waitForAll");
wm.waitForAll(workItems, 60000);
for (WorkItem workItem : workItems) {
System.out.println("workItem.result=" + workItem.getStatus());
if (workItem.getStatus() == WorkEvent.WORK_COMPLETED
|| workItem.getStatus() == WorkEvent.WORK_REJECTED) {
FibWork work = (FibWork) workItem.getResult();
if (work != null) {
out.add(work.getTask());
System.out.println("workItem task"
+ work.getTask().getName() + " result="
+ ((FibonacciTask) work.getTask()).getResult());
}
}
}

} catch (WorkException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}

return out;

}

}



FibWork
package dave;

import weblogic.work.ExecuteThread;
import commonj.work.Work;

public class FibWork implements Work {

Task task;

public Task getTask() {
return task;
}

public void setTask(Task task) {
this.task = task;
}

public FibWork(Task task) {
this.task = task;
}

@Override
public void run() {

ExecuteThread th = (ExecuteThread) Thread.currentThread();
System.out.println("## [FibWork] self-tuning workmanager: "
+ th.getWorkManager().getName());
System.out.println("Running task " + task.getName());
task.run();

}

@Override
public boolean isDaemon() {
return false;
}

@Override
public void release() {
// TODO Auto-generated method stub

}

}



FibonacciCalculatorBean
package dave;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
* Session Bean implementation class FibonacciCalculatorBean
*/
@Stateless(mappedName = "FibonacciCalculator")
public class FibonacciCalculatorBean implements FibonacciCalculator {

@EJB(mappedName = "WorkManagerService")
private WorkManagerService workManagerService;


public void calculateFibonacci(int[] numbers) {
long initialTime = System.currentTimeMillis();
List<Task> tasks = new ArrayList<Task>();
for (int i = 1; i < numbers.length; i++){
FibonacciTask fibonacciTask = new FibonacciTask(numbers[i]);
tasks.add(fibonacciTask);
}
Collection<Task> resultTasks = workManagerService.processTasks(tasks);
long elapsedTime = System.currentTimeMillis() - initialTime;
printFibonacciResults(resultTasks, elapsedTime);
}

private void printFibonacciResults(Collection<Task> tasks, long elapsedTime) {
System.out.println("** Completed Fibonacci Computations in " + elapsedTime
+ "ms **");
for (Task task : tasks) {
FibonacciTask ft = (FibonacciTask) task;
System.out.println("Fibonacci(" + ft.getN() + ") = " + ft.getResult());
}
}

}



weblogic-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.3/weblogic-ejb-jar.xsd">
<!--weblogic-version:12.1.1-->
<wls:weblogic-enterprise-bean>
<wls:ejb-name>CommonJWorkManager</wls:ejb-name>
<wls:stateless-session-descriptor></wls:stateless-session-descriptor>
<wls:transaction-descriptor>
<wls:trans-timeout-seconds>300</wls:trans-timeout-seconds>
</wls:transaction-descriptor>
<wls:dispatch-policy>daveWM</wls:dispatch-policy>
</wls:weblogic-enterprise-bean>

<wls:work-manager>
<wls:name>daveWM</wls:name>

<wls:max-threads-constraint>
<wls:name>MaxThreadsCountTen</wls:name>
<wls:count>10</wls:count>
</wls:max-threads-constraint>
</wls:work-manager>
</wls:weblogic-ejb-jar>


Client
package dave;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;

public class FibonacciClient {

public static void main(String[] args)

{
try

{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
env.put(Context.SECURITY_CREDENTIALS, "weblogic123");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(env);
System.out.println("Initial Context created");

/*TimerSession timerSession = (TimerSession) ctx
.lookup("TimerSession#dave.TimerSession");
timerSession.createTimer(100000);*/

FibonacciCalculator fibonacciCalculator = (FibonacciCalculator) ctx
.lookup("FibonacciCalculator#dave.FibonacciCalculator");
System.out.println("lookup successful");
System.out.println("Calling EJB method . . .");
int fibMax = 10;
int[] numbers =new int[fibMax];
for(int i = 1; i< fibMax; i++){
numbers[i] = i;
}
fibonacciCalculator.calculateFibonacci(numbers);
}

catch (Exception e) {
e.printStackTrace();
}
}
}



Output
## [CommonJWorkManager] executing in: default
Plan task FibonacciTask 1
Plan task FibonacciTask 2
Plan task FibonacciTask 3
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 1
Plan task FibonacciTask 4
## [FibWork] self-tuning workmanager: daveWM
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 2
Running task FibonacciTask 3
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 4
Plan task FibonacciTask 5
Plan task FibonacciTask 6
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 5
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 6
Plan task FibonacciTask 7
Plan task FibonacciTask 8
## [FibWork] self-tuning workmanager: daveWM
Plan task FibonacciTask 9
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 8
## [FibWork] self-tuning workmanager: daveWM
Running task FibonacciTask 9
Running task FibonacciTask 7
wm.waitForAll
workItem.result=4
workItem taskFibonacciTask 1 result=1
workItem.result=4
workItem taskFibonacciTask 2 result=1
workItem.result=4
workItem taskFibonacciTask 3 result=2
workItem.result=4
workItem taskFibonacciTask 4 result=3
workItem.result=4
workItem taskFibonacciTask 5 result=5
workItem.result=4
workItem taskFibonacciTask 6 result=8
workItem.result=4
workItem taskFibonacciTask 7 result=13
workItem.result=4
workItem taskFibonacciTask 8 result=21
workItem.result=4
workItem taskFibonacciTask 9 result=34
** Completed Fibonacci Computations in 17ms **
Fibonacci(1) = 1
Fibonacci(2) = 1
Fibonacci(3) = 2
Fibonacci(4) = 3
Fibonacci(5) = 5
Fibonacci(6) = 8
Fibonacci(7) = 13
Fibonacci(8) = 21
Fibonacci(9) = 34



WorkItems not finished on timeout - result 3
workItem.result=4
workItem taskFibonacciTask 41 result=165580141
workItem.result=4
workItem taskFibonacciTask 42 result=267914296
workItem.result=4
workItem taskFibonacciTask 43 result=433494437
workItem.result=3
workItem.result=3
workItem.result=3
workItem.result=3
workItem.result=3
workItem.result=3
** Completed Fibonacci Computations in 60115ms **
Fibonacci(1) = 1
Fibonacci(2) = 1
Fibonacci(3) = 2
Fibonacci(4) = 3
Fibonacci(5) = 5
Fibonacci(6) = 8
Fibonacci(7) = 13
Fibonacci(8) = 21
Fibonacci(9) = 34
Fibonacci(10) = 55
Fibonacci(11) = 89
Fibonacci(12) = 144
Fibonacci(13) = 233






Requests waiting for processing


All threads


Threads used
## [CommonJWorkManager] executing in: default
Plan task FibonacciTask 1
Plan task FibonacciTask 2
## [FibWork][ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 1
Plan task FibonacciTask 3
Plan task FibonacciTask 4
## [FibWork][ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 3
## [FibWork][ACTIVE] ExecuteThread: '31' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 2
Plan task FibonacciTask 5
## [FibWork][ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 4
## [FibWork][ACTIVE] ExecuteThread: '29' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 5
Plan task FibonacciTask 6
Plan task FibonacciTask 7
## [FibWork][ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 6
## [FibWork][ACTIVE] ExecuteThread: '30' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 7
Plan task FibonacciTask 8
Plan task FibonacciTask 9

Monitoring with jconsole

$
0
0
Managing WebLogic servers with JConsole
https://blogs.oracle.com/WebLogicServer/entry/managing_weblogic_servers_with

Java Management Extensions (JMX)
http://docs.oracle.com/javase/6/docs/technotes/guides/jmx/index.html

Tutorial: Java Management Extensions (JMX)
http://docs.oracle.com/javase/tutorial/jmx/TOC.html

jconsole usage
Usage: jconsole [ -interval=n ] [ -notile ] [ -pluginpath <path> ] [ -version ] [ connection ... ]

-interval Set the update interval to n seconds (default is 4 seconds)
-notile Do not tile windows initially (for two or more connections)
-pluginpath Specify the path that jconsole uses to look up the plugins
-version Print program version

connection = pid || host:port || JMX URL (service:jmx:<protocol>://...)
pid The process id of a target process
host A remote host name or IP address
port The port number for the remote connection

-J Specify the input arguments to the Java virtual machine
on which jconsole is running



Command line
[dave@dave app]$ jconsole -J-Djava.class.path=$JAVA_HOME/lib/jconsole.jar:$JAVA_HOME/lib/tools.jar:$WL_HOME/server/lib/wlfulclient.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote -debug



Plan task FibonacciTask 94
Plan task FibonacciTask 95
Plan task FibonacciTask 96
Plan task FibonacciTask 97
Plan task FibonacciTask 98
Plan task FibonacciTask 99
wm.waitForAll
## [FibWork][ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 36
## [FibWork][ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 38
## [FibWork][ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 39
## [FibWork][ACTIVE] ExecuteThread: '19' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 40
## [FibWork][ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 41
## [FibWork][ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 42
## [FibWork][ACTIVE] ExecuteThread: '22' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 43
## [FibWork][ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 44
## [FibWork][ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 45
## [FibWork][ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 46
## [FibWork][ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 47
## [FibWork][ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 48
## [FibWork][ACTIVE] ExecuteThread: '19' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 49
## [FibWork][ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 50
## [FibWork][ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 51
## [FibWork][ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)' self-tuning workmanager: daveWM
Running task FibonacciTask 52



Thread dump
Name: [ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'
State: RUNNABLE
Total blocked: 98 Total waited: 120

Stack trace:
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.fibonacci(FibonacciTask.java:19)
dave.FibonacciTask.run(FibonacciTask.java:13)
dave.FibWork.run(FibWork.java:29)
weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:184)
weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
weblogic.work.ExecuteThread.run(ExecuteThread.java:221)


Processes
op - 08:37:09 up 10:55, 10 users,  load average: 10.68, 9.80, 5.91
Tasks: 177 total, 1 running, 176 sleeping, 0 stopped, 0 zombie
Cpu(s): 96.1%us, 3.9%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1533932k total, 1411044k used, 122888k free, 13200k buffers
Swap: 2514100k total, 76348k used, 2437752k free, 369768k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4219 dave 20 0 902m 235m 16m S 171.1 15.7 25:34.98 java
1951 dave 9 -11 160m 4832 4116 S 8.5 0.3 6:55.87 pulseaudio
3824 dave 20 0 530m 208m 24m S 6.2 13.9 6:08.51 firefox
3856 dave 20 0 317m 68m 11m S 6.2 4.6 7:35.17 plugin-containe
4273 dave 20 0 494m 139m 19m S 3.3 9.3 1:03.21 jconsole
1633 root 20 0 137m 22m 14m S 2.6 1.5 9:10.48 Xorg
2402 dave 20 0 124m 13m 9328 S 2.0 0.9 1:02.39 gnome-terminal
1155 root 20 0 0 0 0 S 0.3 0.0 0:34.19 kondemand/0
4337 dave 20 0 1001m 327m 29m S 0.3 21.9 1:14.09 eclipse
4575 dave 20 0 2728 1012 756 R 0.3 0.1 0:00.23 top
1 root 20 0 2888 1032 916 S 0.0 0.1 0:01.66 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.20 ksoftirqd/0
4 root RT 0 0 0 0 S 0.0 0.0 0:00.90 migration/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
6 root RT 0 0 0 0 S 0.0 0.0 0:01.11 migration/1
7 root 20 0 0 0 0 S 0.0 0.0 0:00.86 ksoftirqd/1



Stuck thread
<Mar 4, 2012 8:39:35 AM CET> <Error> <WebLogicServer> <BEA-000337> <[STUCK] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "717" seconds working on the request "Workmanager: daveWM, Version: 1, Scheduled=true, Started=true, Started time: 717593 ms
", which is more than the configured time (StuckThreadMaxTime) of "600" seconds. Stack trace:



JVM overview


Application attributes


Weblogic process threads

Profile with jvisualvm

$
0
0
http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/

http://docs.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html

Here is how to configure Eclipse IDE launcher
http://visualvm.java.net/eclipse-launcher.html


jvisualvm is part of JDK
[dave@dave ~]$ cd /app/jdk160_29/bin
[dave@dave bin]$ ls
appletviewer java jcontrol jstack policytool unpack200
apt javac jdb jstat rmic wsgen
ControlPanel javadoc jhat jstatd rmid wsimport
extcheck javah jinfo jvisualvm rmiregistry xjc
HtmlConverter javap jmap keytool schemagen
idlj java-rmi.cgi jps native2ascii serialver
jar javaws jrunscript orbd servertool
jarsigner jconsole jsadebugd pack200 tnameserv



Simple program comparing methods to create large string
package dave;

public class StringService {

int STRING_COUNT = 10000;

public String createString(String token) {

String out = "";

for (int i = 0; i < 1000; i++) {
out += token;
}

return out;

}

public String createStringWithStringBuffer(String token) {

StringBuffer out = new StringBuffer();

for (int i = 0; i < STRING_COUNT; i++) {
out.append(token);
}

return out.toString();
}

public String createStringWithStringBuilder(String token) {

StringBuilder out = new StringBuilder();

for (int i = 0; i < STRING_COUNT; i++) {
out.append(token);
}

return out.toString();

}

}




package dave;

public class TestProfiler {

public static void main(String[] args) {

String token = "dave";

StringService stringService = new StringService();

String result = null;

for (int i = 0; i < 10000; i++) {

result = stringService.createString(token);

result = stringService.createStringWithStringBuffer(token);

result = stringService.createStringWithStringBuilder(token);
}

}

}





Profiler with settings to select package


Sampler

Weblogic login module test - Firefox plugin to modify HTTP request header (also possible with Opera cookie editor)

$
0
0
Modify Headers Firefox plugin
https://addons.mozilla.org/en-US/firefox/addon/modify-headers/


Modify HTTP header


Capture HTTP headers




Weblogic Identity Assertion Concepts
http://docs.oracle.com/cd/E21764_01/web.1111/e13718/ia.htm#autoId0

Weblogic log of test Identity Asserter
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@f99f26
userName = dave



weblogic.xml assigns role to group
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">

<security-role-assignment>
<role-name>SamplePerimeterAtnRole</role-name>
<principal-name>SamplePerimeterAtnUsers</principal-name>
</security-role-assignment>

</weblogic-web-app>


web.xml configures web resource as secured
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<!-- Specifies the security settings for the SamplePerimeterAtn web app.

This webapp is used to demonstrate how to use identity assertion to
perform perimeter authentication (where someone outside WLS is
responsible for authenticating the user).

Copyright (c) 2005 by BEA Systems, Inc. All Rights Reserved.
-->

<security-constraint>

<!-- all the pages in this webapp are secured -->
<web-resource-collection>
<web-resource-name>SecuredPages</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>

<!-- only users in the SamplePerimeterAtnRole will
be granted access to the pages in this webapp
-->
<auth-constraint>
<role-name>
SamplePerimeterAtnRole
</role-name>
</auth-constraint>

<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>

</security-constraint>

<!-- Use weblogic.xml to map the SamplePerimeterAtnRole
to the SamplePerimeterAtnUsers group. As a result,
"SamplePerimterAtnUsers" will be granted the role
for this webapp (thus be able to access its pages)
-->
<security-role>
<role-name>
SamplePerimeterAtnRole
</role-name>
</security-role>

<!-- turn on identity assertion

The webapp only specifies that identity assertion should be
used. It does not dictate what kind of tokens to use. Rather,
the client and the identity asserter have to agree on the token
type and format.

- the client is responsible sending in a token that identifies the user

- the identity asserter is responsible for converting that token
to a user name.

- the authenticators are responsible for putting that user
and its groups into the subject

The realm name is not used so set it to "NoSuchRealm". It
has nothing to do with the realm names in the console.

Set the auth method to CLIENT-CERT to turn on identity
assertion for this webapp.
-->
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>NoSuchRealm</realm-name>
</login-config>

</web-app>




Error without modified header

Error 401--Unauthorized
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.2 401 Unauthorized

The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.46) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity MAY include relevant diagnostic information. HTTP access authentication is explained in section 11.



Result page with added header
SamplePerimeterAtn.jsp Subject: Principal: dave Principal: SamplePerimeterAtnUsers Private Credential: dave 


Authorized access with configured Identity Asserter


Modify SimpleSampleIdentityAsserter - set Base64DecodingRequired to false
http://docs.oracle.com/cd/E21764_01/web.1111/e13718/ia.htm#autoId15


<MBeanAttribute
Name = "Base64DecodingRequired"
Type = "boolean"
Writeable = "false"
Default = "false"
Description = "See MyIdentityAsserter-doc.xml."
/>


Capture HTTP headers
http://localhost:7001/samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp

GET /samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp HTTP/1.1
Host: localhost:7001
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: ADMINCONSOLESESSION=0X41P3rh1pbcCGhBn8nJ5yB55R9zds3v6fjD68QMjT5F6cYZqFGJ!-863651884; JSESSIONID=WVJXP3rJnc1tpjTn5SHW4TC5tRLGhgDBgBDTvZqTQGSR67r88XDR!-863651884
SamplePerimeterAtnToken: username=dave

HTTP/1.1 200 OK
Date: Sat, 31 Mar 2012 16:17:46 GMT
Content-Length: 116
Content-Type: text/html; charset=ISO-8859-1
X-Powered-By: Servlet/3.0 JSP/2.2



To change user it is necessary to remove cookie with JSESSIONID

Cookie: JSESSIONID=pZrFP3yQQpFLnJvPLGSTpcgnGRqCQtYJfdfpySLYJG1gd3QCTGWz!-863651884


In Firefox this is done using about:permissions


Opera allows to edit existing cookies
Cookie Information


Cookie Manager



IdentityAsserter MBean in WLS Admin console


All Weblogic users are assigned to group users. This can be used to allow access to authorized application for all authenticated users by mapping role to users principal in web.xml


 weblogic.security.Security.getCurrentSubject()


returns
SamplePerimeterAtn.jsp Subject: Principal: dave Private Credential: dave 



weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">

<security-role-assignment>
<role-name>authusers</role-name>
<principal-name>users</principal-name>
</security-role-assignment>

</weblogic-web-app>



web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<!-- Specifies the security settings for the SamplePerimeterAtn web app.

This webapp is used to demonstrate how to use identity assertion to
perform perimeter authentication (where someone outside WLS is
responsible for authenticating the user).

Copyright (c) 2005 by BEA Systems, Inc. All Rights Reserved.
-->

<security-constraint>

<!-- all the pages in this webapp are secured -->
<web-resource-collection>
<web-resource-name>SecuredPages</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>

<!-- all authenticated users in the authusers will
be granted access to the pages in this webapp
-->
<auth-constraint>
<role-name>authusers</role-name>
</auth-constraint>

<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>

</security-constraint>

<!-- Use weblogic.xml to map the authusers
to the users group. As a result,
"users" will be granted the role
for this webapp (thus be able to access its pages)
-->
<security-role>
<role-name>
authusers
</role-name>
</security-role>

<!-- turn on identity assertion

The webapp only specifies that identity assertion should be
used. It does not dictate what kind of tokens to use. Rather,
the client and the identity asserter have to agree on the token
type and format.

- the client is responsible sending in a token that identifies the user

- the identity asserter is responsible for converting that token
to a user name.

- the authenticators are responsible for putting that user
and its groups into the subject

The realm name is not used so set it to "NoSuchRealm". It
has nothing to do with the realm names in the console.

Set the auth method to CLIENT-CERT to turn on identity
assertion for this webapp.
-->
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>NoSuchRealm</realm-name>
</login-config>

<servlet>
<description></description>
<display-name>AuthenticationSnoop</display-name>
<servlet-name>AuthenticationSnoop</servlet-name>
<servlet-class>dave.AuthenticationSnoop</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthenticationSnoop</servlet-name>
<url-pattern>/AuthenticationSnoop</url-pattern>
</servlet-mapping>

</web-app>

Mock Weblogic Login module - Identity Asserter and Authenticator

$
0
0
This module is strictly for testing as it does not validate user.

Based on this log http://weblogic-wonders.com/weblogic/2010/03/15/custom-identity-asserter-for-weblogic-server/

Oracle® Fusion Middleware Developing Security Providers for Oracle WebLogic Server
http://docs.oracle.com/cd/E14571_01/web.1111/e13718/atn.htm#i115061
Identity Assertion Providers
http://docs.oracle.com/cd/E14571_01/web.1111/e13718/ia.htm#i1156163


Steps to create login module
1. Create MBean definition file SimpleSampleIdentityAsserter.xml
<?xml version="1.0" ?>
<!DOCTYPE MBeanType SYSTEM "commo.dtd">

<!-- MBean Definition File (MDF) for the Simple Sample Identity Asserter.

Copyright (c) 2002 by BEA Systems, Inc. All Rights Reserved.
-->

<!-- Declare your mbean.

Since it is for an identity asserter, it must extend the
weblogic.management.security.authentication.IdentityAsserter mbean.

The Name and DisplayName must be the same.
They specify the name that will appear on the
console for this provider.

Set the PeristPolicy to "OnUpdate" so that if an attribute
value is changed, the new value is written to disk immediately.
See the "Developing Security Services" manual for more info.

Note that since this is an xml document, you can't use double
quotes directly. Instead you need to use &quot;

Note that setting "Writeable" to "false" on an attribute
makes the attribute read-only. The default is read-write.
-->

<MBeanType
Name = "SimpleSampleIdentityAsserter"
DisplayName = "SimpleSampleIdentityAsserter"
Package = "examples.security.providers.identityassertion.simple"
Extends = "weblogic.management.security.authentication.IdentityAsserter"
PersistPolicy = "OnUpdate"
>

<!-- You must set the value of the ProviderClassName attribute
(inherited from the weblogic.management.security.Provider mbean)
to the name of the java class you wrote that implements the
weblogic.security.spi.AuthenticationProvider interface.

You can think of the provider's mbean as the factory
for your provider's runtime implementation.
-->
<MBeanAttribute
Name = "ProviderClassName"
Type = "java.lang.String"
Writeable = "false"
Preprocessor = "weblogic.management.configuration.LegalHelper.checkClassName(value)"
Default = "&quot;examples.security.providers.identityassertion.simple.SimpleSampleIdentityAsserterProviderImpl&quot;"
/>

<!-- You must set the value of the Description attribute
(inherited from the weblogic.management.security.Provider mbean)
to a brief description of your provider.
It is displayed in the console.
-->
<MBeanAttribute
Name = "Description"
Type = "java.lang.String"
Writeable = "false"
Default = "&quot;WebLogic Simple Sample Identity Asserter Provider&quot;"
/>

<!-- You must set the value of the Version attribute
(inherited from the weblogic.management.security.Provider mbean)
to your provider's version. There is no required format.
-->
<MBeanAttribute
Name = "Version"
Type = "java.lang.String"
Writeable = "false"
Default = "&quot;1.0&quot;"
/>

<!-- You must set the value of the SupportedTypes attribute
(inherited from the
weblogic.management.security.authentication.IdentityAsserter mbean)
to the list of token types that your identity asserter supports.

Whoever is initiating the identity assertion (eg. a client sending
a perimeter authentication token via an HTTP request header), must
use the same token type.
-->
<MBeanAttribute
Name = "SupportedTypes"
Type = "java.lang.String[]"
Writeable = "false"
Default = "new String[] { &quot;SamplePerimeterAtnToken&quot; }"
/>
<!-- The ActiveTypes attribute (a settable attribute inherited from the
weblogic.management.security.authentication.IdentityAsserter mbean)
contains the subset of your mbean's SupportedTypes that are active
in the realm.

Which way you should default the active types attribute depends
on your token types. The basic rule is that for any token
type, there must only be one identity asserter in the realm with
that token type as an active type. In short, you can only have
one identity asserter turned on for a given type.

If your token types are commonly implemented by other identity
asserters (eg. X509 certificates), then you should not set them
as default active types. Otherwise, it would be very easy for
an administrator to configure an invalid realm where more than
one identity asserter has the same type turned on. Best
practice is that all the identity asserters turn off the type
by default then the administrator manually turns on the
type in one of the identity asserters that support it.
Look at the weblogic.security.spi.IdentityAsserter javadoc
for some standard token types.

On the other hand, if you have a custom token type that no
other identity asserter will ever implement, you may default the
active types attribute to include your token type. If you do,
then the adminstrator doesn't have to manually turn on your token
type.

Since the simple sample identity asserter's token type is very specific
to the sample (instead of a common type like X509), turn on the
token type by default.
-->
<MBeanAttribute
Name = "ActiveTypes"
Type = "java.lang.String[]"
Default = "new String[] { &quot;SamplePerimeterAtnToken&quot; }"
/>

<!-- Add any custom attributes for your provider here.

The simple sample identity asserter does not have any custom attributes.

Note: custom attributes do not appear in the
console in WLS 7.0. Use the admin command line tool
(java weblogic.Admin) to view and set their values.

Refer to the "Developing Security Services" manual
for more info on defining custom attributes.
-->

<MBeanAttribute
Name = "Base64DecodingRequired"
Type = "boolean"
Writeable = "false"
Default = "false"
Description = "See MyIdentityAsserter-doc.xml."
/>

</MBeanType>



2. copy commo.dtd from WLS installation
[dave@dave src]$ find /app/weblogic121/ -name commo.dtd
/app/weblogic121/wlserver_12.1/server/lib/commo.dtd
/app/weblogic121/wlserver_12.1/server/lib/mbeantypes/commo.dtd
[dave@dave src]$ cp /app/weblogic121/wlserver_12.1/server/lib/mbeantypes/commo.dtd .




3. modify classes for IdentityAsserter, LoginModule and CallbackHandler - only 3 classes have to be provided , rest is generated
[dave@dave src]$ ls -1
build.xml
commo.dtd
SimpleSampleCallbackHandlerImpl.java
SimpleSampleIdentityAsserterImpl.java
SimpleSampleIdentityAsserter.jar
SimpleSampleIdentityAsserterProviderImpl.java
SimpleSampleIdentityAsserter.xml
SimpleSampleLoginModuleImpl.java
test



This is main Provider class which drives the process SimpleSampleIdentityAsserterProviderImpl.
It provides IdentityAsserter and it calls SimpleSampleLoginModule
package examples.security.providers.identityassertion.simple;

import java.util.HashMap;

import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;

import weblogic.management.security.ProviderMBean;
import weblogic.security.provider.PrincipalValidatorImpl;
import weblogic.security.service.ContextHandler;
import weblogic.security.spi.AuthenticationProviderV2;
import weblogic.security.spi.IdentityAsserterV2;
import weblogic.security.spi.IdentityAssertionException;
import weblogic.security.spi.PrincipalValidator;
import weblogic.security.spi.SecurityServices;

/**
* The simple sample identity asserter's runtime implementation.
*
* It looks for tokens of type "SamplePerimeterAtnToken"
* whose matching token is an array of bytes containing a
* string in the form "username=someusername".
*
* It extracts the username from the token and stores it
* in a SimpleSampleCallbackHandlerImpl. This is returned to the
* security framework who hands it to the authenticators'
* login modules. The login modules can use a NameCallback
* to retrieve the user name from the simple sample identity
* asserter's callback handler.
*
* Since it is an identity asserter, it must implement
* the weblogic.security.spi.AuthenticationProvider and
* the weblogic.security.spi.IdentityAsserter interfaces.
*
* It can either implement two classes, and use the
* provider implementation as the factory as the
* factory for the identity asserter, or it can implement
* both interfaces in one class. The simple sample identity
* asserter implments both interfaces in one class.
*
* Note: The simple sample identity asserter's mbean's ProviderClassName
* attribute must be set the the name of this class.
*
* @author Copyright (c) 2002 by BEA Systems. All Rights Reserved.
*/
public final class SimpleSampleIdentityAsserterProviderImpl implements AuthenticationProviderV2, IdentityAsserterV2
{
final static private String TOKEN_TYPE = "SamplePerimeterAtnToken"; // the kind of token's we handle
final static private String TOKEN_PREFIX = "username="; // the token contains a string in the form "username=someusername"

private String description; // a description of this provider
private LoginModuleControlFlag controlFlag; // how this provider's login module should be used during the JAAS login


/**
* Initialize the simple sample identity asserter.
*
* @param mbean A ProviderMBean that holds the simple sample identity asserter's
* configuration data. This mbean must be an instance of the simple sample
* identity asserter's mbean.
*
* @param services The SecurityServices gives access to the auditor
* so that the provider can to post audit events.
* The simple sample role mapper doesn't use this parameter.
*
* @see SecurityProvider
*/
public void initialize(ProviderMBean mbean, SecurityServices services)
{
System.out.println("SimpleSampleIdentityAsserterProviderImpl.initialize");
SimpleSampleIdentityAsserterMBean myMBean = (SimpleSampleIdentityAsserterMBean)mbean;
description = myMBean.getDescription() + "\n" + myMBean.getVersion();

controlFlag = LoginModuleControlFlag.SUFFICIENT;
/* String flag = myMBean.getControlFlag();
if (flag.equalsIgnoreCase("REQUIRED")) {
controlFlag = LoginModuleControlFlag.REQUIRED;
} else if (flag.equalsIgnoreCase("OPTIONAL")) {
controlFlag = LoginModuleControlFlag.OPTIONAL;
} else if (flag.equalsIgnoreCase("REQUISITE")) {
controlFlag = LoginModuleControlFlag.REQUISITE;
} else if (flag.equalsIgnoreCase("SUFFICIENT")) {
controlFlag = LoginModuleControlFlag.SUFFICIENT;
} else {
throw new IllegalArgumentException("invalid flag value" + flag);
}*/
}

/**
* Get the simple sample identity asserter's description.
*
* @return A String containing a brief description of the simple sample identity asserter.
*
* @see SecurityProvider
*/
public String getDescription()
{
return description;
}

/**
* Shutdown the simple sample identity asserter.
*
* A no-op.
*
* @see SecurityProvider
*/
public void shutdown()
{
System.out.println("SimpleSampleIdentityAsserterProviderImpl.shutdown");
}

/**
* Gets the simple sample identity assertion provider's identity asserter object.
*
* @return The simple sample identity assertion provider's IdentityAsserter object.
*
* @see AuthenticationProvider
*/
public IdentityAsserterV2 getIdentityAsserter()
{
return this;
}

/**
* Assert identity given a token that identifies the user.
*
* @param type A String containing the token type. The simple sample identity
* asserter only supports tokens of type "SamplePerimeterAtnToken".
* Also, the simple sample identity asserter's mbean's "ActiveTypes" attribute
* must be set to "SamplePerimeterAtnToken" (which is done by default
* when the mbean is created).
*
* @param token An Object containing the token that identifies the user.
* The simple sample identity asserter's token must be an array of bytes
* containing a String of the form "username=someusername".
*
* @param handler A ContextHandler object that can optionally
* be used to obtain additional information that may be used in
* asserting the identity. If the caller is unable to provide additional
* information, a null value should be specified. This sample
* ignores the handler.
*
* While, for simplicity, this sample does not validate the
* contents of the token, identity asserters typically should do
* this (to prevent someone from forging a token). For
* example, when using Kerberos, the token may be generated
* and "signed" by a Kerberos server and the identity asserter
* hands the token back to the Kerberos server to get it
* validated. Another example: when asserting identity from
* X509 certificates, then identity asserter should validate the
* certificate - that it hasn't been tampered, that it's been
* signed by a trusted CA, that it hasn't expired or revoked, etc.
*
* @return a CallbackHandler that stores the username from the token.
* The username can only be retrieved from the callback handler by
* passing in a NameCallback. The sample returns an instance of
* its CallbackHandler implementation (SimpleSampleCallbackHandlerImpl).
*
* @throws IdentityAssertionException if another token type is passed
* in or the token doesn't have the correct form.
*/
public CallbackHandler assertIdentity(String type, Object token, ContextHandler context) throws IdentityAssertionException
{
System.out.println("SimpleSampleIdentityAsserterProviderImpl.assertIdentity");
System.out.println("\tType\t\t= " + type);
System.out.println("\tToken\t\t= " + token);

// check the token type
if (!(TOKEN_TYPE.equals(type))) {
String error =
"SimpleSampleIdentityAsserter received unknown token type \"" + type + "\"." +
" Expected " + TOKEN_TYPE;
System.out.println("\tError: " + error);
throw new IdentityAssertionException(error);
}

// make sure the token is an array of bytes
if (!(token instanceof byte[])) {
String error =
"SimpleSampleIdentityAsserter received unknown token class \"" + token.getClass() + "\"." +
" Expected a byte[].";
System.out.println("\tError: " + error);
throw new IdentityAssertionException(error);
}

// convert the array of bytes to a string
byte[] tokenBytes = (byte[])token;
if (tokenBytes == null || tokenBytes.length < 1) {
String error =
"SimpleSampleIdentityAsserter received empty token byte array";
System.out.println("\tError: " + error);
throw new IdentityAssertionException(error);
}

String tokenStr = new String(tokenBytes);

// make sure the string contains "username=someusername
if (!(tokenStr.startsWith(TOKEN_PREFIX))) {
String error =
"SimpleSampleIdentityAsserter received unknown token string \"" + type + "\"." +
" Expected " + TOKEN_PREFIX + "username";
System.out.println("\tError: " + error);
throw new IdentityAssertionException(error);
}

// extract the username from the token
String userName = tokenStr.substring(TOKEN_PREFIX.length());
System.out.println("\tuserName\t= " + userName);

// store it in a callback handler that authenticators can use
// to retrieve the username.
return new SimpleSampleCallbackHandlerImpl(userName);
}

/**
* Create a JAAS AppConfigurationEntry (which tells JAAS
* how to create the login module and how to use it) when
* the simple sample authenticator is used to authenticate (vs. to
* complete identity assertion).
*
* @return An AppConfigurationEntry that tells JAAS how to use the simple sample
* authenticator's login module for authentication.
*/
public AppConfigurationEntry getLoginModuleConfiguration()
{
// Don't pass in any special options.
// By default, the simple sample authenticator's login module
// will authenticate (by checking that the passwords match).
HashMap options = new HashMap();
return getConfiguration(options);
}

/**
* Create a JAAS AppConfigurationEntry (which tells JAAS
* how to create the login module and how to use it).
* This helper method is used both for authentication mode
* and identity assertion mode.
*
* @param options A HashMap containing the options to pass to the
* simple sample authenticator's login module. This method adds the
* "database helper" object to the options. This allows the
* login module to access the users and groups.
*
* @return An AppConfigurationEntry that tells JAAS how to use the simple sample
* authenticator's login module.
*/
private AppConfigurationEntry getConfiguration(HashMap options)
{
System.out.println("SimpleSampleIdentityAsserterProviderImpl: getConfiguration");
// make sure to specify the simple sample authenticator's login module
// and to use the control flag from the simple sample authenticator's mbean.
return new
AppConfigurationEntry(
"examples.security.providers.authentication.simple.SimpleSampleLoginModuleImpl",
controlFlag,
options
);
}

/**
* Create a JAAS AppConfigurationEntry (which tells JAAS
* how to create the login module and how to use it) when
* the simple sample authenticator is used to complete identity
* assertion (vs. to authenticate).
*
* @return An AppConfigurationEntry that tells JAAS how to use the simple sample
* authenticator's login module for identity assertion.
*/
public AppConfigurationEntry getAssertionModuleConfiguration()
{
System.out.println("SimpleSampleIdentityAsserterProviderImpl: getAssertionModuleConfiguration");
// Pass an option indicating that we're doing identity
// assertion (vs. authentication) therefore the login module
// should only check that the user exists (instead of checking
// the password)
HashMap options = new HashMap();
options.put("IdentityAssertion","true");
return getConfiguration(options);
}

/**
* Return the principal validator that can validate the
* principals that the authenticator's login module
* puts into the subject.
*
* Since the simple sample authenticator uses the built in
* WLSUserImpl and WLSGroupImpl principal classes, just
* returns the built in PrincipalValidatorImpl that knows
* how to handle these kinds of principals.
*/
public PrincipalValidator getPrincipalValidator()
{
return new PrincipalValidatorImpl();
}
}



SimpleSampleLoginModule - set as SUFFICIENT

package examples.security.providers.authentication.simple;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Vector;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.spi.LoginModule;
import weblogic.management.utils.NotFoundException;
import weblogic.security.principal.WLSGroupImpl;
import weblogic.security.principal.WLSUserImpl;

/**
* The simple sample authenticator's login module implementation.
*
* It is used in one of two modes:
* - authentication where it validates the user's password
* then populates the subject with the user and the user's groups.
* - identity assertion where it checks that the user exists,
* then populates the subject with the user and the user's groups.
*
* The SimpleSampleAuthenticationProviderImpl creates an options hash map
* that is passed to this login module. It contains one entry,
* named "database", that is an object that manages the
* user and group definitions. It optionally contains another entry,
* named "IdentityAssertion", that puts the login module in
* "identity assertion" mode (vs. the default which is "authenticadtion"
* mode).
*
* It uses the built in WLSUserImpl and WLSGroupImpl classes to
* populate the subject with users and groups.
*
* @author Copyright (c) 2002 by BEA Systems. All Rights Reserved.
*/
final public class SimpleSampleLoginModuleImpl implements LoginModule
{
private Subject subject; // the subject for this login
private CallbackHandler callbackHandler; // where to get user names, passwords, ... for this login

private boolean isIdentityAssertion; // are we in authentication or identity assertion mode?

// Authentication status
private boolean loginSucceeded; // have we successfully logged in?
private boolean principalsInSubject; // did we add principals to the subject?
private Vector principalsForSubject = new Vector(); // if so, what principals did we add to the subject
// (so we can remove the principals we added if the login is aborted)
/**
* Initialize a login attempt.
*
* @param subject the Subject this login attempt will populate.
*
* @param callbackhandler the CallbackHandler that can be used to
* get the user name, and in authentication mode, the user's password
*
* @param sharedState A Map containing data shared between login
* modules when there are multiple authenticators configured. This
* simple sample does not use this parameter.
*
* @param options A Map containing options that the authenticator's
* authentication provider impl wants to pass to its login module impl.
* For example, it can be used to pass in configuration data (where
* is the database holding user and group info) and to pass in whether
* the login module is used for authentication or to complete identity
* assertion.
* The SimpleSampleAuthenticationProviderImpl adds an option named "database".
* The value is a SimpleSampleAuthenticatorDatabase object. It gives the
* login module access to the user and group definitions.
* When the authenticator is being used in identity assertion mode,
* the SimpleSampleAuthenticationProviderImpl also adds an option named
* "IdentityAssertion". It indicates that the login module should only
* verify that the user exists (vs. checking the password too). If
* this option is not specified (or is set to false), then the
* login module checks the user's password too (that is, it assumes
* authentication mode).
*/
public void
initialize(
Subject subject,
CallbackHandler callbackHandler,
Map sharedState,
Map options
)
{
// only called (once!) after the constructor and before login

System.out.println("SimpleSampleLoginModuleImpl.initialize");
this.subject = subject;
this.callbackHandler = callbackHandler;

// Determine if we're in identity assertion or authentication mode
isIdentityAssertion =
"true".equalsIgnoreCase((String)options.get("IdentityAssertion"));

}

/**
* Attempt to login.
*
* If we're in authentication mode, extract the user name and password
* from the callback handler. If the user exists and the password matches,
* then populate the subject with the user and the user's group. Otherwise,
* the login fails.
*
* If we're in identity assertion mode, extract the user name (only)
* from the callback handler. If the user exists, then populate the
* subject with the user and the user's groups. Otherwise, the
* login fails.
*
* @return A boolean indicating whether or not the login for
* this login module succeeded.
*/
public boolean login() throws LoginException
{
// only called (once!) after initialize

System.out.println("SimpleSampleLoginModuleImpl.login");

// loginSucceeded should be false
// principalsInSubject should be false

// Call a method to get the callbacks.
// For authentication mode, it will have one for the
// username and one for the password.
// For identity assertion mode, it will have one for
// the user name.
Callback[] callbacks = getCallbacks();

// Get the user name.
String userName = getUserName(callbacks);

if (userName.length() > 0) {
// We have a user name
System.out.println("\tuserName=" + userName);
} else {
// anonymous login.
System.out.println("\tempty userName");
}

loginSucceeded = true;

// since the login succeeded, add the user and its groups to the
// list of principals we want to add to the subject.
principalsForSubject.add(new WLSUserImpl(userName));
addGroupsForSubject(userName);

return loginSucceeded;
}

/**
* Completes the login by adding the user and the user's groups
* to the subject.
*
* @return A boolean indicating whether or not the commit succeeded.
*/
public boolean commit() throws LoginException
{
// only called (once!) after login

// loginSucceeded should be true or false
// principalsInSubject should be false
// user should be null if !loginSucceeded, null or not-null otherwise
// group should be null if user == null, null or not-null otherwise

System.out.println("SimpleSampleLoginModule.commit");
if (loginSucceeded) {
// put the user and the user's groups (computed during the
// login method and stored in the principalsForSubject object)
// into the subject.
subject.getPrincipals().addAll(principalsForSubject);
principalsInSubject = true;
return true;
} else {
return false;
}
}

/**
* Aborts the login attempt. Remove any principals we put
* into the subject during the commit method from the subject.
*
* @return A boolean indicating whether or not the abort succeeded.
*/
public boolean abort() throws LoginException
{
// only called (once!) after login or commit
// or may be? called (n times) after abort

// loginSucceeded should be true or false
// principalsInSubject should be false if user is null, otherwise true or false

System.out.println("SimpleSampleLoginModule.abort");
if (principalsInSubject) {
subject.getPrincipals().removeAll(principalsForSubject);
principalsInSubject = false;
}
return true;
}

/**
* Logout. This should never be called.
*
* @return A boolean indicating whether or not the logout succeeded.
*/
public boolean logout() throws LoginException
{
// should never be called

System.out.println("SimpleSampleLoginModule.logout");
return true;
}

/**
* Throw an invalid login exception.
*
* @param msg A String containing the text of the LoginException.
*
* @throws LoginException
*/
private void throwLoginException(String msg) throws LoginException
{
System.out.println("Throwing LoginException(" + msg + ")");
throw new LoginException(msg);
}

/**
* Throws a failed login excception.
*
* @param msg A String containing the text of the FailedLoginException.
*
* @throws LoginException
*/
private void throwFailedLoginException(String msg) throws FailedLoginException
{
System.out.println("Throwing FailedLoginException(" + msg + ")");
throw new FailedLoginException(msg);
}

/**
* Get the list of callbacks needed by the login module.
*
* @return The array of Callback objects by the login module.
* Returns one for the user name and password if in authentication mode.
* Returns one for the user name if in identity assertion mode.
*/
private Callback[] getCallbacks() throws LoginException
{
if (callbackHandler == null) {
throwLoginException("No CallbackHandler Specified");
}

Callback[] callbacks;
if (isIdentityAssertion) {
callbacks = new Callback[1]; // need one for the user name
} else {
callbacks = new Callback[2]; // need one for the user name and one for the password

// add in the password callback
callbacks[1] = new PasswordCallback("password: ",false);
}

// add in the user name callback
callbacks[0] = new NameCallback("username: ");

// Call the callback handler, who in turn, calls back to the
// callback objects, handing them the user name and password.
// These callback objects hold onto the user name and password.
// The login module retrieves the user name and password from them later.
try {
callbackHandler.handle(callbacks);
} catch (IOException e) {
throw new LoginException(e.toString());
} catch (UnsupportedCallbackException e) {
throwLoginException(e.toString() + " " + e.getCallback().toString());
}

return callbacks;
}

/**
* Get the user name from the callbacks (that the callback handler
* has already handed the user name to).
*
* @param callbacks The array of Callback objects used by this login module.
* The first in the list must be the user name callback object.
*
* @return A String containing the user name (from the user name callback object)
*/
private String getUserName(Callback[] callbacks) throws LoginException
{
String userName = ((NameCallback)callbacks[0]).getName();
if (userName == null) {
throwLoginException("Username not supplied.");
}
System.out.println("\tuserName\t= " + userName);
return userName;
}

/**
* Add the user's groups to the list of principals to be added to the subject.
*
* @param A String containing the user name the user's name.
*/
private void addGroupsForSubject(String userName)
{
// Get the user's list of groups (recursively - so, if user1 is a member
// of group1 and group1 is a member of group2, then it returns group1 and
// group2). Iterate over the groups, adding each to the list of principals
// to add to the subject.
String groupName = "SamplePerimeterAtnUsers";
System.out.println("\tgroupName\t= " + groupName);
principalsForSubject.add(new WLSGroupImpl(groupName));
}

/**
* Get the password from the callbacks (that the callback handler
* has already handed the password to) - that is, the password from
* the login attempt. Must only be used for authentication mode, not
* for identity assertion mode.
*
* @param useName A String containing the name of the user
* (already retrieved from the callbacks). Only passed in
* so that we can print a better error message if the password
* is bogus.
*
* @param callbacks The array of Callback objects used by this login module.
* The second in the list must be the password callback object.
*
* @return A String containing the password from the login attempt
*
* @throws LoginException if no password was supplied in the login attempt.
*/
private String getPasswordHave(String userName, Callback[] callbacks) throws LoginException
{
PasswordCallback passwordCallback = (PasswordCallback)callbacks[1];
char[] password = passwordCallback.getPassword();
passwordCallback.clearPassword();
if (password == null || password.length < 1) {
throwLoginException("Authentication Failed: User " + userName + ". Password not supplied");
}
String passwd = new String(password);
System.out.println("\tpasswordHave\t= " + passwd);
return passwd;
}
}



CallbackHandler
package examples.security.providers.identityassertion.simple;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

/**
* The simple sample identity asserter's implementation of the
* CallbackHandler interface.
*
* It is used to make the name of the user from the identity
* assertion token available to the authenticators (who, in
* turn, will populate the subject with the user and the user's
* groups).
*
* This class is internal to the simple sample identity asserter.
* It is not a public class.
*
* @author Copyright (c) 2002 by BEA Systems. All Rights Reserved.
*/
/*package*/ class SimpleSampleCallbackHandlerImpl implements CallbackHandler
{
private String userName; // the name of the user from the identity assertion token

/**
* Create a callback handler that stores the user name.
*
* @param user A String containing the name of the user
* from the identity assertion token
*/
/*package*/ SimpleSampleCallbackHandlerImpl(String user)
{
userName = user;
}

/**
* Used by the authenticators' login modules to get the user name
* that the identity asserter extracted from the identity assertion token.
* This name can only be retrieved via a NameCallback.
*
* @param callbacks An array of Callback objects indicating what data
* the login module is trying to extract from this callback handler.
* It must only contain NameCallbacks.
*
* @exception UnsupportedCallbackException thrown if any of the callbacks
* aren't NameCallbacks.
*
* @see CallbackHandler
*/
public void handle(Callback[] callbacks) throws UnsupportedCallbackException
{
// loop over the callbacks
for (int i = 0; i < callbacks.length; i++) {

Callback callback = callbacks[i];

// we only handle NameCallbacks
if (!(callback instanceof NameCallback)) {
throw new UnsupportedCallbackException(callback, "Unrecognized Callback");
}

// send the user name to the name callback:
NameCallback nameCallback = (NameCallback)callback;
nameCallback.setName(userName);
}
}
}





4.Build jar with ant using build.xml
<project name="Expenselink Build" default="all" basedir=".">
<property name="fileDir" value="test" />

<target name="all" depends="build"/>

<target name="build" depends="clean,build.mdf,build.mjf"/>

<target name="clean">
<delete dir="${fileDir}" failonerror="false"/>
<delete file="SimpleSampleIdentityAsserter.jar" failonerror="false"/>
<echo message="Clean finish" />
</target>

<!-- helper to build an MDF (mbean definition file) -->
<target name="build.mdf">
<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-files ${fileDir}" />
<arg value="-createStubs" />
<arg line="-MDF SimpleSampleIdentityAsserter.xml" />
</java>
<echo message="Created Supporting Classes" />
</target>

<target name="build.mjf">

<copy todir="${fileDir}" flatten="true">
<fileset dir=".">
<include name="*.java" />
</fileset>
</copy>

<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-MJF SimpleSampleIdentityAsserter.jar" />
<arg line="-files ${fileDir}" />
</java>
<echo message="Created Mbean Jar" />
</target>

</project>



Set WLS environment

[dave@dave src]$ . /app/weblogic121/wlserver_12.1/server/bin/setWLSEnv.sh




[dave@dave src]$ ant
Buildfile: build.xml

clean:
[delete] Deleting directory /home/dave/workspace1211/testIdentityAsserter/src/test
[delete] Deleting: /home/dave/workspace1211/testIdentityAsserter/src/SimpleSampleIdentityAsserter.jar
[echo] Clean finish

build.mdf:
[java] Working directory ignored when same JVM is used.
[java] Parsing the MBean definition file: SimpleSampleIdentityAsserter.xml
[echo] Created Supporting Classes

build.mjf:
[copy] Copying 3 files to /home/dave/workspace1211/testIdentityAsserter/src/test
[java] Working directory ignored when same JVM is used.
[java] Creating an MJF from the contents of directory test...
[java] Compiling the files...
[java] Creating the list.
[java] Doing the compile.
[java] Note: /home/dave/workspace1211/testIdentityAsserter/src/test/SimpleSampleIdentityAsserterProviderImpl.java uses or overrides a deprecated API.
[java] Note: Recompile with -Xlint:deprecation for details.
[java] Note: Some input files use unchecked or unsafe operations.
[java] Note: Recompile with -Xlint:unchecked for details.
[java] WLMaker-SubProcess: : EXTRACT FROM /usr/app/weblogic121/wlserver_12.1/server/lib/mbeantypes/wlManagementMBean.jar
[java] WLMaker-SubProcess: : INTO wlMakerTempDir
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: : Generating the implementations for security MBeans
[java] WLMaker-SubProcess: : Generating for examples.security.providers.identityassertion.simple.SimpleSampleIdentityAsserterMBean to /home/dave/workspace1211/testIdentityAsserter/src/test/examples/security/providers/identityassertion/simple/SimpleSampleIdentityAsserterMBeanImpl.java
[java] WLMaker-SubProcess: : no annotation found for key [i]
[java] WLMaker-SubProcess: : no annotation found for key [velocityCount]
[java] WLMaker-SubProcess: : no annotation found for key [line]
[java] WLMaker-SubProcess: : no annotation found for key [f]
[java] WLMaker-SubProcess: : no annotation found for key [m]
[java] WLMaker-SubProcess: : no annotation found for key [p]
[java] WLMaker-SubProcess: : no annotation found for key [n]
[java] WLMaker-SubProcess: : done
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: : Generating the parsing binders for security MBeans
[java] WLMaker-SubProcess: : Generating for examples.security.providers.identityassertion.simple.SimpleSampleIdentityAsserterMBean to /home/dave/workspace1211/testIdentityAsserter/src/test/examples/security/providers/identityassertion/simple/SimpleSampleIdentityAsserterMBeanBinder.java
[java] WLMaker-SubProcess: : done
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: :
[java] WLMaker-SubProcess: : Generating the bean infos for security MBeans ...
[java] WLMaker-SubProcess: : Generating for examples.security.providers.identityassertion.simple.SimpleSampleIdentityAsserterMBean to /home/dave/workspace1211/testIdentityAsserter/src/test/examples/security/providers/identityassertion/simple/SimpleSampleIdentityAsserterMBeanImplBeanInfo.java
[java] WLMaker-SubProcess: : no annotation found for key [import]
[java] WLMaker-SubProcess: : no annotation found for key [property]
[java] WLMaker-SubProcess: : no annotation found for key [beanConfigurable]
[java] WLMaker-SubProcess: : no annotation found for key [beanIntfExclude]
[java] WLMaker-SubProcess: : no annotation found for key [propertyMethod]
[java] WLMaker-SubProcess: : no annotation found for key [method]
[java] WLMaker-SubProcess: : Generating Bean Factory Class to test/weblogic/management/security/SIMPLESAMPLEIDENTITYASSERTERBeanInfoFactory.java
[java] WLMaker-SubProcess: : done
[java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
[java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
[java] WLMaker-SchemaGen-SubProcess: Generating schema for security provider mbeans ...
[java] WLMaker-SchemaGen-SubProcess: MBEAN TYPES DIR : null
[java] WLMaker-SchemaGen-SubProcess: SET BASE LIB /usr/app/weblogic121/wlserver_12.1/server/lib/schema/weblogic-domain-binding.jar
[java] WLMaker-SchemaGen-SubProcess: Stopped draining WLMaker-SchemaGen-SubProcess
[java] WLMaker-SchemaGen-SubProcess: Stopped draining WLMaker-SchemaGen-SubProcess
[java] Creating the list.
[java] Doing the compile.
[java] Note: Some input files use or override a deprecated API.
[java] Note: Recompile with -Xlint:deprecation for details.
[java] Note: Some input files use unchecked or unsafe operations.
[java] Note: Recompile with -Xlint:unchecked for details.
[java] Creating the MJF...
[java] MJF is created.
[echo] Created Mbean Jar

build:

all:

BUILD SUCCESSFUL



5. copy provider to Weblogic installation dir
see http://docs.oracle.com/cd/E21764_01/web.1111/e13718/ia.htm#autoId18
Note:
WL_HOME\server\lib\mbeantypes is the default directory for installing MBean types.
(Beginning with 9.0, security providers can be loaded from ...\domaindir\lib\mbeantypes as well.)
However, if you want WebLogic Server to look for MBean types in additional directories, use the -Dweblogic.alternateTypesDirectory=<dir> command-line flag when starting your server,
where <dir> is a comma-separated list of directory names. When you use this flag, WebLogic Server will always load MBean types from WL_HOME\server\lib\mbeantypes first,
then will look in the additional directories and load all valid archives present in those directories (regardless of their extension).
For example, if -Dweblogic.alternateTypesDirectory = dirX,dirY, WebLogic Server will first load MBean types from WL_HOME\server\lib\mbeantypes, then any valid archives present in dirX and dirY.


[dave@dave src]$ cp  SimpleSampleIdentityAsserter.jar /app/weblogic121/wlserver_12.1/server/lib/mbeantypes/
[dave@dave src]$


6. configure new provider using WLS console



7. test using Modify HTTP headers plugin or cookie editor ( see previous blog entry)
user token is retrieved by this custom provider from HTTP request header or from cookie

Weblogic logs
SimpleSampleIdentityAsserterProviderImpl.initialize
SimpleSampleIdentityAsserterProviderImpl: getAssertionModuleConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
<Apr 1, 2012 10:44:29 AM CEST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
<Apr 1, 2012 10:44:32 AM CEST> <Notice> <LoggingService> <BEA-320400> <The log file /usr/app/domains/base_domain/servers/AdminServer/logs/access.log will be rotated. Reopen the log file if tailing has stopped. This can happen on some platforms, such as Windows.>
<Apr 1, 2012 10:44:32 AM CEST> <Notice> <LoggingService> <BEA-320401> <The log file has been rotated to /usr/app/domains/base_domain/servers/AdminServer/logs/access.log00029. Log messages will continue to be logged in /usr/app/domains/base_domain/servers/AdminServer/logs/access.log.>
<Apr 1, 2012 10:44:34 AM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY.>
<Apr 1, 2012 10:44:34 AM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <LoggingService> <BEA-320400> <The log file /usr/app/domains/base_domain/servers/AdminServer/logs/base_domain.log will be rotated. Reopen the log file if tailing has stopped. This can happen on some platforms, such as Windows.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <LoggingService> <BEA-320401> <The log file has been rotated to /usr/app/domains/base_domain/servers/AdminServer/logs/base_domain.log00032. Log messages will continue to be logged in /usr/app/domains/base_domain/servers/AdminServer/logs/base_domain.log.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <Server> <BEA-002613> <Channel
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <WebLogicServer> <BEA-000331> <Started the WebLogic Server Administration Server "AdminServer" for domain "base_domain" running in development mode.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
<Apr 1, 2012 10:44:37 AM CEST> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl: getAssertionModuleConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleLoginModuleImpl.initialize
SimpleSampleLoginModuleImpl.login
userName = dave
userName=dave
groupName = SamplePerimeterAtnUsers
SimpleSampleLoginModule.commit
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleLoginModuleImpl.initialize
SimpleSampleLoginModuleImpl.login
userName = weblogic
userName=weblogic
groupName = SamplePerimeterAtnUsers
SimpleSampleLoginModule.commit
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleIdentityAsserterProviderImpl.assertIdentity
Type = SamplePerimeterAtnToken
Token = [B@8393a
userName = dave
SimpleSampleIdentityAsserterProviderImpl: getAssertionModuleConfiguration
SimpleSampleIdentityAsserterProviderImpl: getConfiguration
SimpleSampleLoginModuleImpl.initialize
SimpleSampleLoginModuleImpl.login
userName = dave
userName=dave
groupName = SamplePerimeterAtnUsers
SimpleSampleLoginModule.commit



Domain config with new provider - default provider must be set to SUFFICIENT because mock users do not exist in WLS LPAP
<name>base_domain</name>
<domain-version>12.1.1.0</domain-version>
<security-configuration>
<name>base_domain</name>
<realm>
<sec:authentication-provider xsi:type="wls:default-authenticatorType">
<sec:control-flag>SUFFICIENT</sec:control-flag>
</sec:authentication-provider>
<sec:authentication-provider xsi:type="wls:default-identity-asserterType">
<sec:active-type>AuthenticatedUser</sec:active-type>
</sec:authentication-provider>
<sec:authentication-provider xmlns:ext="http://xmlns.oracle.com/weblogic/security/extension" xsi:type="ext:simple-sample-identity-asserterType">
<sec:name>SimpleSampleIdentityAserter</sec:name>
</sec:authentication-provider>
<sec:role-mapper xmlns:xac="http://xmlns.oracle.com/weblogic/security/xacml" xsi:type="xac:xacml-role-mapperType"></sec:role-mapper>
<sec:authorizer xmlns:xac="http://xmlns.oracle.com/weblogic/security/xacml" xsi:type="xac:xacml-authorizerType"></sec:authorizer>
<sec:adjudicator xsi:type="wls:default-adjudicatorType"></sec:adjudicator>
<sec:credential-mapper xsi:type="wls:default-credential-mapperType"></sec:credential-mapper>
<sec:cert-path-provider xsi:type="wls:web-logic-cert-path-providerType"></sec:cert-path-provider>
<sec:cert-path-builder>WebLogicCertPathProvider</sec:cert-path-builder>
<sec:name>myrealm</sec:name>
<sec:password-validator xmlns:pas="http://xmlns.oracle.com/weblogic/security/providers/passwordvalidator" xsi:type="pas:system-password-validatorType">
<sec:name>SystemPasswordValidator</sec:name>
<pas:min-password-length>8</pas:min-password-length>
<pas:min-numeric-or-special-characters>1</pas:min-numeric-or-special-characters>
</sec:password-validator>
</realm>
<default-realm>myrealm</default-realm>




Captured HTTP header using Firefox plugin Live HTTP headers
First run without added token in HTTP request header

http://localhost:7002/samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp

GET /samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp HTTP/1.1
Host: localhost:7001
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: ADMINCONSOLESESSION=GGfvP4VP5YBZbBcQXb4vQJVF1TRPTq1Qsn4b8yLx1m2H7Q8PlT8v!385259249

HTTP/1.1 401 Unauthorized
Date: Sun, 01 Apr 2012 09:10:09 GMT
Content-Length: 1468
Content-Type: text/html; charset=UTF-8
X-Powered-By: Servlet/3.0 JSP/2.2
----------------------------------------------------------
http://localhost:7001/samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp

GET /samplePerimeterAtnWebApp/SamplePerimeterAtn.jsp HTTP/1.1
Host: localhost:7001
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: ADMINCONSOLESESSION=GGfvP4VP5YBZbBcQXb4vQJVF1TRPTq1Qsn4b8yLx1m2H7Q8PlT8v!385259249
SamplePerimeterAtnToken: username=dave

HTTP/1.1 200 OK
Date: Sun, 01 Apr 2012 09:10:18 GMT
Content-Length: 90
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: JSESSIONID=x1yHP4bhj2RjFQL7Ph46hkysTmZC4LXm0gglyL3DsSh2hmTGhVt2!385259249; path=/; HttpOnly
X-Powered-By: Servlet/3.0 JSP/2.2
----------------------------------------------------------

WebLogic X509 Certificate Authentication

$
0
0
Securing Web Applications http://docs.oracle.com/cd/E14571_01/web.1111/e13711/thin_client.htm#i1044688

How to Set Up X509 Certificate Authentication for Oracle WebLogic Server http://www.oracle.com/technetwork/articles/damo-howto-091164.html

Installing and Configuring the Apache HTTP Server Plug-In
http://docs.oracle.com/cd/E14571_01/web.1111/e14395/apache.htm Certificate is send by Weblogic plugin in WL-Proxy-Client-Cert HTTP header

in weblogic.xml
client-cert-proxy-enabled The element default value is true. When set to true, WebLogic Server passes identity certificates from the clients to the backend servers. Also, WebLogic Server is notified whether to honor or discard the incoming WL-Proxy-Client-Cert header. A proxy-server plugin encodes each identity certification in the WL-Proxy-Client-Cert header and passes it to the backend WebLogic Server instances. Each WebLogic Server instance takes the certificate information from the header, ensures it came from a secure source, and uses that information to authenticate the user. For the background WebLogic Server instances, this parameter must be set to true (either at the cluster/server level or at the Web application level). If you set this element to true, use a weblogic.security.net.ConnectionFilter to ensure that each WebLogic Server instance accepts connections only from the machine on which the proxy-server plugin is running. If you specify true without using a connection filter, a potential security vulnerability is created because the WL-Proxy-Client-Cert header can be spoofed.

web.xmlhttp://docs.oracle.com/cd/E23943_01/web.1111/e13712/web_xml.htm

<security-constraint>
<web-resource-collection>
<web-resource-name>Faces Servlet</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>AppUser</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>NoSuchRealm</realm-name>
</login-config>
<security-role>
<role-name>AppUser</role-name>
</security-role>

</web-app>
weblogic.xml http://docs.oracle.com/cd/E14571_01/web.1111/e13712/weblogic_xml.htm

<wls:security-role-assignment>
<wls:role-name>AppUser</wls:role-name>
<wls:principal-name>AppUsers</wls:principal-name>
</wls:security-role-assignment>

Configure slf4j with log4j on Weblogic

$
0
0


It is neccessary to use filtering classloader to avoid discovery of Weblogic own version of slf4j jars. With prefer-application-packages option application classloader loads org.slf4j packages from application instead of Weblogic installation

Annoying SLF4J problem in Weblogic server 12c http://blog.terrencemiao.com/archives/annoying-slf4j-problem-in-weblogic-server-12c

 prefer-application-packages
Used for filtering ClassLoader configuration. Specifies a list of packages for classes that must always be loaded from the application.http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#autoId24

Weblogic log without prefer-application-packages and after redeploy with the option set in weblogic.xml
Aug 3, 2012 11:20:03 PM dave.TestSlf4jLogger doGet
INFO: Hello World- info
Aug 3, 2012 11:20:04 PM dave.TestSlf4jLogger doGet
INFO: Hello World- info
Aug 3, 2012 11:20:05 PM dave.TestSlf4jLogger doGet
INFO: Hello World- info
Aug 3, 2012 11:20:05 PM dave.TestSlf4jLogger doGet
INFO: Hello World- info
Aug 3, 2012 11:20:05 PM dave.TestSlf4jLogger doGet
INFO: Hello World- info
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/app/weblogic121/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:/home/dave/workspace38/testSLF4JWAR/WebContent/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j: Parsing for [root] with value=[DEBUG, file, stdout].
log4j: Level token is [DEBUG].
log4j: Category root set to DEBUG
log4j: Parsing appender named "file".
log4j: Parsing layout options for "file".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "file".
log4j: Setting property [file] to [/tmp/testSLF4j.log].
log4j: Setting property [maxBackupIndex] to [1].
log4j: Setting property [maxFileSize] to [1MB].
log4j: setFile called: /tmp/testSLF4j.log, true
log4j: setFile ended
log4j: Parsed "file" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "stdout".
log4j: Setting property [target] to [System.out].
log4j: Parsed "stdout" options.
log4j: Finished configuring.
23:23:07,943 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:07,949 INFO TestSlf4jLogger:42 - Hello World- info
23:23:08,590 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:08,592 INFO TestSlf4jLogger:42 - Hello World- info
23:23:09,386 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:09,387 INFO TestSlf4jLogger:42 - Hello World- info

log file created
[dave@dave testSLF4JWAR]$ more /tmp/testSLF4j.log 
23:23:07,943 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:07,949 INFO TestSlf4jLogger:42 - Hello World- info
23:23:08,590 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:08,592 INFO TestSlf4jLogger:42 - Hello World- info
23:23:09,386 DEBUG TestSlf4jLogger:41 - Hello World - debug
23:23:09,387 INFO TestSlf4jLogger:42 - Hello World- info

libraries in project
[dave@dave testSLF4JWAR]$ ls -1 WebContent/WEB-INF/lib/ 
log4j-1.2.16.jar
slf4j-api-1.6.6.jar
slf4j-log4j12-1.6.6.jar


slf4j libraries in Weblogic
[dave@dave testSLF4JWAR]$ find /app/weblogic121/ -name "*slf4j*"
/app/weblogic121/modules/org.slf4j.jdk14_1.6.1.0.jar
/app/weblogic121/modules/org.slf4j.ext_1.6.1.0.jar
/app/weblogic121/modules/org.slf4j.api_1.6.1.0.jar

log4j.properties
log4j.debug=true

# Root logger option
log4j.rootLogger=DEBUG, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/testSLF4j.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>testSLF4JWAR</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
Test servlet
package dave;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* Servlet implementation class TestSlf4jLogger
*/
@WebServlet("/TestSlf4jLogger")
public class TestSlf4jLogger extends HttpServlet {
private static final long serialVersionUID = 1L;

final Logger logger = LoggerFactory.getLogger(TestSlf4jLogger.class);

/**
* @see HttpServlet#HttpServlet()
*/
public TestSlf4jLogger() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
logger.debug("Hello World - debug");
logger.info("Hello World- info");

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

Weblogic log with added ejb module
LF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/app/weblogic121/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:/home/dave/workspace38/testSLF4jEAR/EarContent/APP-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:/home/dave/workspace38/testSLF4JWAR/WebContent/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j: Parsing for [root] with value=[DEBUG, file, stdout].
log4j: Level token is [DEBUG].
log4j: Category root set to DEBUG
log4j: Parsing appender named "file".
log4j: Parsing layout options for "file".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "file".
log4j: Setting property [file] to [/tmp/testSLF4j.log].
log4j: Setting property [maxBackupIndex] to [1].
log4j: Setting property [maxFileSize] to [1MB].
log4j: setFile called: /tmp/testSLF4j.log, true
log4j: setFile ended
log4j: Parsed "file" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "stdout".
log4j: Setting property [target] to [System.out].
log4j: Parsed "stdout" options.
log4j: Finished configuring.
00:07:24,873 DEBUG TestSlf4jLogger:46 - Hello World - debug
00:07:24,928 INFO TestSlf4jLogger:47 - Hello World- info
TestSLF4JService: Hello World
Aug 4, 2012 12:07:25 AM dave.TestSLF4JBean testLogger
INFO: TestSLF4JService: Hello World- info

Weblogic log after adding prefer-application-packages into weblogic-application.xml descriptor
00:14:48,273 DEBUG TestSlf4jLogger:46 - Hello World - debug
00:14:48,277 INFO TestSlf4jLogger:47 - Hello World- info
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/app/weblogic121/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:/home/dave/workspace38/testSLF4jEAR/EarContent/APP-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
TestSLF4JService: Hello World
00:14:48,297 DEBUG TestSLF4JBean:26 - TestSLF4JService: Hello World - debug
00:14:48,297 INFO TestSLF4JBean:27 - TestSLF4JService: Hello World- info

weblogic-application.xml descriptor
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
<!--weblogic-version:12.1.1-->
<wls:application-param>
<wls:param-name>webapp.encoding.default</wls:param-name>
<wls:param-value>UTF-8</wls:param-value>
</wls:application-param>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j</wls:package-name>
</wls:prefer-application-packages>
</wls:weblogic-application>
EAR content
dave@dave workspace38]$ ls testSLF4jEAR/EarContent/APP-INF/lib
log4j-1.2.16.jar slf4j-api-1.6.6.jar slf4j-log4j12-1.6.6.jar
[dave@dave workspace38]$ ls -1 testSLF4jEAR/EarContent/APP-INF/lib
log4j-1.2.16.jar
slf4j-api-1.6.6.jar
slf4j-log4j12-1.6.6.jar
[dave@dave workspace38]$ ls -1 testSLF4jEAR/EarContent/META-INF
weblogic-application.xml

test Session Bean
package dave;

import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Session Bean implementation class TestSLF4JService
*/
@Stateless
public class TestSLF4JBean implements TestSLF4JService {

final Logger logger = LoggerFactory.getLogger(TestSLF4JBean.class);

/**
* Default constructor.
*/
public TestSLF4JBean() {
// TODO Auto-generated constructor stub
}

public void testLogger(){

System.out.println("TestSLF4JService: Hello World");
logger.debug("TestSLF4JService: Hello World - debug");
logger.info("TestSLF4JService: Hello World- info");

}

}

injection of Session Bean in Servlet

@EJB
TestSLF4JService service;


/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
logger.debug("Hello World - debug");
logger.info("Hello World- info");

service.testLogger();

}

Debug Identity Assertion on Weblogic

$
0
0

Debug Identity Assertion on Weblogic 


Identity Assertion Providers
http://docs.oracle.com/cd/E21764_01/web.1111/e13718/ia.htm#autoId7

 Enable DebugSecurityAtn andRedirect stdout logging enabled inWeblogic console


[dave@dave logs]$ grep newuser *
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236861> <BEA-000000> <userName = newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236865> <BEA-000000> <com.bea.common.security.internal.service.IdentityAssertionCallbackServiceImpl.assertIdentity returning newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236865> <BEA-000000> <com.bea.common.security.internal.service.IdentityCacheServiceImpl.getCachedIdentity(newuser)>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236865> <BEA-000000> <com.bea.common.security.internal.service.IdentityCacheServiceImpl.getCachedIdentity(newuser) returning null>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236872> <BEA-000000> <com.bea.common.security.internal.service.CallbackHandlerWrapper.handle got username from callbacks[0], UserName=newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236872> <BEA-000000> <LDAP Atn Login username: newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236872> <BEA-000000> <userExists? user:newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236873> <BEA-000000> <getDNForUser search("ou=people,ou=myrealm,dc=base_domain", "(&(uid=newuser)(objectclass=person))", base DN& below)>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236874> <BEA-000000> <DN for user newuser: null>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236874> <BEA-000000> <user does not exist, user:newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236878> <BEA-000000> <javax.security.auth.login.LoginException: [Security:090300]Identity Assertion Failed: User newuser does not exist
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236887> <BEA-000000> <LoginModule: getUserName userName = newuser&gt;
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236888> <BEA-000000> <login: userName=newuser>
AdminServer.log: Principal: newuser
AdminServer.log: Principal = class weblogic.security.principal.WLSUserImpl("newuser")
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236892> <BEA-000000> <com.bea.common.security.internal.service.PrincipalValidationServiceImpl.sign(Principal) Principal=newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236893> <BEA-000000> <Generated signature and signed WLS principal newuser>
AdminServer.log: Principal = class weblogic.security.principal.WLSUserImpl("newuser")
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236897> <BEA-000000> <weblogic.security.service.internal.WLSJAASLoginServiceImpl$ServiceImpl.authenticate authenticate succeeded for user newuser, Identity=Subject: 3
AdminServer.log: Principal = class weblogic.security.principal.WLSUserImpl("newuser")

AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236897> <BEA-000000> <weblogic.security.service.internal.WLSJAASLoginServiceImpl$ServiceImpl.authenticate login succeeded and newuser was not previously locked out>
AdminServer.log: Principal = class weblogic.security.principal.WLSUserImpl("newuser")
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236900> <BEA-000000> <com.bea.common.security.internal.service.PrincipalValidationServiceImpl.validate(Principal) Principal=newuser>
AdminServer.log:####<Aug 6, 2012 11:23:56 PM CEST> <Debug> <SecurityAtn> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236901> <BEA-000000> <Validate WLS principal newuser returns true>
AdminServer.log: Principal = class weblogic.security.principal.WLSUserImpl("newuser")
AdminServer.log: Principal = weblogic.security.principal.WLSUserImpl("newuser")
AdminServer.log:####<Aug 6, 2012 11:23:57 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288237047> <BEA-000000> <23:23:57,047 INFO TestSlf4jLogger:53 - Hello World- principalnewuser>
AdminServer.log:####<Aug 6, 2012 11:23:57 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288237048> <BEA-000000> <23:23:57,048 INFO TestSlf4jLogger:57 - Hello World- subject[newuser, SamplePerimeterAtnUsers, DaveUsers]>
base_domain.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236861> <BEA-000000> <userName = newuser>
base_domain.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236887> <BEA-000000> <LoginModule: getUserName userName = newuser>
base_domain.log:####<Aug 6, 2012 11:23:56 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288236888> <BEA-000000> <login: userName=newuser>
base_domain.log:####<Aug 6, 2012 11:23:57 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288237047> <BEA-000000> <23:23:57,047 INFO TestSlf4jLogger:53 - Hello World- principalnewuser>
base_domain.log:####<Aug 6, 2012 11:23:57 PM CEST> <Notice> <Stdout> <dave> <AdminServer> <[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1344288237048> <BEA-000000> <23:23:57,048 INFO TestSlf4jLogger:57 - Hello World- subject[newuser, SamplePerimeterAtnUsers, DaveUsers]>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>testSLF4JWAR</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Specifies the security settings for the SamplePerimeterAtn web app.

This webapp is used to demonstrate how to use identity assertion to
perform perimeter authentication (where someone outside WLS is
responsible for authenticating the user).

Copyright (c) 2005 by BEA Systems, Inc. All Rights Reserved.
-->

<security-constraint>

<!-- all the pages in this webapp are secured -->
<web-resource-collection>
<web-resource-name>SecuredPages</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>

<!-- only users in the SamplePerimeterAtnRole will
be granted access to the pages in this webapp
-->
<auth-constraint>
<role-name>
SamplePerimeterAtnRole
</role-name>
</auth-constraint>

<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>

</security-constraint>

<!-- Use weblogic.xml to map the SamplePerimeterAtnRole
to the SamplePerimeterAtnUsers group. As a result,
"SamplePerimterAtnUsers" will be granted the role
for this webapp (thus be able to access its pages)
-->
<security-role>
<role-name>
SamplePerimeterAtnRole
</role-name>
</security-role>

<!-- turn on identity assertion

The webapp only specifies that identity assertion should be
used. It does not dictate what kind of tokens to use. Rather,
the client and the identity asserter have to agree on the token
type and format.

- the client is responsible sending in a token that identifies the user

- the identity asserter is responsible for converting that token
to a user name.

- the authenticators are responsible for putting that user
and its groups into the subject

The realm name is not used so set it to "NoSuchRealm". It
has nothing to do with the realm names in the console.

Set the auth method to CLIENT-CERT to turn on identity
assertion for this webapp.
-->
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>NoSuchRealm</realm-name>
</login-config>

</web-app>

weblogic.xml


<wls:weblogic -web-app="-web-app" xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic -version="-version">12.1.1</wls:weblogic>
<wls:context -root="-root">testSLF4JWAR</wls:context>
<wls:container -descriptor="-descriptor">
<wls:prefer -application-packages="-application-packages">
<wls:package -name="-name">org.slf4j</wls:package>
</wls:prefer>
</wls:container>
<wls:security -role-assignment="-role-assignment">
<wls:role-name=">SamplePerimeterAtnRole</wls:role-name>
<wls:principal-name="">SamplePerimeterAtnUsers</wls:principal-name>
</wls:security>
</wls:weblogic>
</div>

Mixed Java and Scala development in Eclipse

$
0
0
.classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.inter
nal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>

.project file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>testScala</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>


TestPerson.scala class
package dave

object TestPerson {
def main(args: Array[String]) {
val person = new Person("dave")

println(person)
}
}

Person.java class
package dave;

public class Person {

String name;

public Person() {}


public Person(String name) {
this.name= name;
}

public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


@Override
public String toString() {
return "Person [name=" + name + "]";
}



}
Eclipse with Scala plugin
Java buildpath
All files in project
[dave@dave testScala]$ ls -lRa
.:
total 32
drwxrwxr-x. 5 dave dave 4096 Oct 9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct 9 22:04 ..
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:41 bin
-rw-rw-r--. 1 dave dave 2222 Oct 9 22:51 .cache
-rw-rw-r--. 1 dave dave 376 Oct 9 22:04 .classpath
-rw-rw-r--. 1 dave dave 425 Oct 9 22:04 .project
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:40 .settings
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:04 src

./bin:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct 9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:51 dave

./bin/dave:
total 20
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:51 .
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:41 ..
-rw-rw-r--. 1 dave dave 821 Oct 9 22:41 Person.class
-rw-rw-r--. 1 dave dave 648 Oct 9 22:51 TestPerson.class
-rw-rw-r--. 1 dave dave 706 Oct 9 22:51 TestPerson$.class

./.settings:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:40 .
drwxrwxr-x. 5 dave dave 4096 Oct 9 22:41 ..
-rw-rw-r--. 1 dave dave 587 Oct 9 22:04 org.eclipse.jdt.core.prefs
-rw-rw-r--. 1 dave dave 847 Oct 9 22:40 org.scala-ide.sdt.core.prefs

./src:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:04 .
drwxrwxr-x. 5 dave dave 4096 Oct 9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:20 dave

./src/dave:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct 9 22:20 .
drwxrwxr-x. 3 dave dave 4096 Oct 9 22:04 ..
-rw-rw-r--. 1 dave dave 328 Oct 9 22:25 Person.java
-rw-rw-r--. 1 dave dave 131 Oct 9 22:51 TestPerson.scala
[dave@dave testScala]$

List classes from faces-config.xml which do not exist using sed

$
0
0
List classes from faces-config.xml which do not exist using sed

 Sed tutorial http://www.grymoire.com/Unix/Sed.html#uh-4
 
[dave@dave tmp]$ more faces-config.xml 
<managed-bean>
<managed-bean-name>x</managed-bean-name>
<managed-bean-class>com.dave.x</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>y</managed-bean-name>
<managed-bean-class>com.dave.y</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>z</managed-bean-name>
<managed-bean-class>com.dave.z</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

List classes
[dave@dave tmp]$  sed -n 's#.*<managed-bean-class>\([\.a-z]*\)</managed-bean-class>#\1#'p faces-config.xml 
com.dave.x
com.dave.y
com.dave.z

Create file names
[dave@dave tmp]$ sed s#\\.#/#g classes.txt 
com/dave/x
com/dave/y
com/dave/z


Change classes file
 sed -i  s#\\.#/#g classes.txt


Add .java
[dave@dave tmp]$ sed   s#\$#.java# classes.txt 
com/dave/x.java
com/dave/y.java
com/dave/z.java



List classes which do not exist
[dave@dave tmp]$ xargs ls < classes.txt 
ls: cannot access com/dave/y.java: No such file or directory
com/dave/x.java com/dave/z.java


[dave@dave tmp]$ ls -R com/*
com/dave:
x.java z.java





Weblogic Classloader Analysis Tool

$
0
0

Understanding WebLogic Server Application Classloading


http://docs.oracle.com/cd/E24329_01/web.1211/e24368/classloading.htm

http://blog.eisele.net/2011/01/using-new-weblogic-classloader-analysis.html

https://blogs.oracle.com/jeffwest/entry/weblogic_1034_classloader_analysis_tool

Using JSF and JSTL With Web Applications

http://docs.oracle.com/cd/E24329_01/web.1211/e21049/configurejsfandjtsl.htm
 


 Create new JSF2 test project using Eclipse OEPE


Deploy JSF project to WLS
Run CAT
WLS must not be in Production mode - disable in config.xml

  <production-mode-enabled>false</production-mode-enabled>



System Classloaders

 Type: sun.misc.Launcher$ExtClassLoader
HashCode: 27355241
Classpath:

    /opt/weblogic/jdk160_29/jre/lib/ext/dnsns.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/localedata.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/sunjce_provider.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/sunpkcs11.jar

Type: sun.misc.Launcher$AppClassLoader
HashCode: 13288040
Classpath:

    /opt/weblogic/jdk160_29/lib/tools.jar
    /opt/weblogic/modules/features/weblogic.server.modules_12.1.1.0.jar
    /opt/weblogic/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar
    /opt/weblogic/modules/org.apache.ant_1.7.1/lib/ant-all.jar
    /opt/weblogic/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/patch_oepe101/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/patch_wls1211/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/wlserver_12.1/common/derby/lib/derbyclient.jar
    /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
    /opt/weblogic/wlserver_12.1/server/lib/weblogic_sp.jar
    /opt/weblogic/wlserver_12.1/server/lib/webservices.jar
    /opt/weblogic/wlserver_12.1/server/lib/xqrl.jar

Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 33228044
Classpath:


Application classloaders

Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 22012742
Filter: []
Classpath: empty
Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 12339795
Classpath:

Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 30552408
Filter: []
Classpath: empty
Type: weblogic.utils.classloaders.ChangeAwareClassLoader
HashCode: 21104537
Classpath:

    /home/dave/domains/base_domain/servers/AdminServer/tmp/_WL_user/_auto_generated_ear_/7qcgwh
    /home/dave/workspace/testJSF2/build/classes



Add JSF 2.1 facet using OEPE

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
<application>
<message-bundle>resources.application</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>

</faces-config>

 

Run CAT on JSF2.1 application 


System Classloaders
Type: sun.misc.Launcher$ExtClassLoader
HashCode: 27355241
Classpath:

/opt/weblogic/jdk160_29/jre/lib/ext/dnsns.jar
/opt/weblogic/jdk160_29/jre/lib/ext/localedata.jar
/opt/weblogic/jdk160_29/jre/lib/ext/sunjce_provider.jar
/opt/weblogic/jdk160_29/jre/lib/ext/sunpkcs11.jar

Type: sun.misc.Launcher$AppClassLoader
HashCode: 13288040
Classpath:

/opt/weblogic/jdk160_29/lib/tools.jar
/opt/weblogic/modules/features/weblogic.server.modules_12.1.1.0.jar
/opt/weblogic/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar
/opt/weblogic/modules/org.apache.ant_1.7.1/lib/ant-all.jar
/opt/weblogic/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/patch_oepe101/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/patch_wls1211/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/wlserver_12.1/common/derby/lib/derbyclient.jar
/opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
/opt/weblogic/wlserver_12.1/server/lib/weblogic_sp.jar
/opt/weblogic/wlserver_12.1/server/lib/webservices.jar
/opt/weblogic/wlserver_12.1/server/lib/xqrl.jar

Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 33228044
Classpath:

Application Classloaders
Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 22012742
Filter: []
Classpath: empty
Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 12339795
Classpath:

Change JSF version to 1.2 

Using Weblogic 12c deployable libs
 

Add Weblogic shared libraries for JSF1


JSF 1 config file
<?xml version="1.0" encoding="UTF-8"?>

<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<application>
<message-bundle>resources.application</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>

</faces-config>

refer to JSF 1.2 shared library in weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>testJSF1</wls:context-root>
<wls:library-ref>
<wls:library-name>jsf</wls:library-name>
<wls:specification-version>1.2</wls:specification-version>
<wls:exact-match>true</wls:exact-match>
</wls:library-ref>
</wls:weblogic-web-app>

WebApplication 2.5 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>testJSF1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

CAT for JSF 1 project
System Classloaders
Type: sun.misc.Launcher$ExtClassLoader
HashCode: 27355241
Classpath:

/opt/weblogic/jdk160_29/jre/lib/ext/dnsns.jar
/opt/weblogic/jdk160_29/jre/lib/ext/localedata.jar
/opt/weblogic/jdk160_29/jre/lib/ext/sunjce_provider.jar
/opt/weblogic/jdk160_29/jre/lib/ext/sunpkcs11.jar

Type: sun.misc.Launcher$AppClassLoader
HashCode: 13288040
Classpath:

/opt/weblogic/jdk160_29/lib/tools.jar
/opt/weblogic/modules/features/weblogic.server.modules_12.1.1.0.jar
/opt/weblogic/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar
/opt/weblogic/modules/org.apache.ant_1.7.1/lib/ant-all.jar
/opt/weblogic/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/patch_oepe101/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/patch_wls1211/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/opt/weblogic/wlserver_12.1/common/derby/lib/derbyclient.jar
/opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
/opt/weblogic/wlserver_12.1/server/lib/weblogic_sp.jar
/opt/weblogic/wlserver_12.1/server/lib/webservices.jar
/opt/weblogic/wlserver_12.1/server/lib/xqrl.jar

Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 33228044
Classpath:

Application Classloaders
Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 30798826
Filter: []
Classpath: empty
Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 25758036
Classpath:

Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 11509600
Filter: [javax.faces.*, com.sun.faces.*, com.bea.faces.*]
Classpath: empty
Type: weblogic.utils.classloaders.ChangeAwareClassLoader
HashCode: 28974499
Classpath:

/home/dave/domains/base_domain/servers/AdminServer/tmp/_WL_user/_auto_generated_ear_/7qcgwi
/home/dave/domains/base_domain/servers/AdminServer/tmp/_WL_user/jsf/2ndlrw/WEB-INF/lib/glassfish-jsf_1.0.0.0_1-2-15.jar
/home/dave/workspace/testJSF1/build/classes
/opt/weblogic/modules/features/../glassfish.jsf_1.0.0.0_1-2-15.jar
/opt/weblogic/modules/features/../javax.jsf_1.2.0.0_1-2.jar
/opt/weblogic/modules/features/weblogic.server.modules.jsf_12.1.1.0.jar



Required libs for JSF 1.2 
 JSF 1.2 requires java 1.5 or later, JSP 2.1, JSTL 1.2 and a Java Servlet 2.5 implementation. http://myfaces.apache.org/core12/index.html 

Deploy JSF 1.2 shared libraries for WLS  ( already contains filtering classloader in descriptor)

http://docs.oracle.com/cd/E24329_01/web.1211/e21049/configurejsfandjtsl.htm

List of WLS 12.1.1 shared libs

[dave@dave bin]$ ls /opt/weblogic/wlserver_12.1/common/deployable-libraries/
active-cache-1.0.jar          jersey-bundle-1.1.5.1.war  jsr311-api-1.1.1.war  rome-1.0.war
jackson-core-asl-1.1.1.war    jettison-1.1.war           jstl-1.1.2.war        toplink-grid-1.0.jar
jackson-jaxrs-1.1.1.war       jsf-1.2.war                jstl-1.2.war          weblogic-sca-1.1.war
jackson-mapper-asl-1.1.1.war  jsf-2.0.war                pubsub-1.0.war
[dave@dave bin]$ cd /opt/weblogic/wlserver_12.1/common/deployable-libraries/
[dave@dave deployable-libraries]$ jar tvf jstl-1.1.2.war
     0 Thu May 11 22:59:30 CEST 2006 META-INF/
   385 Thu May 11 22:59:28 CEST 2006 META-INF/MANIFEST.MF
    75 Thu May 11 22:59:30 CEST 2006 META-INF/javadoc.mf
     0 Thu May 11 22:59:30 CEST 2006 WEB-INF/
 11356 Thu May 11 22:59:30 CEST 2006 WEB-INF/LICENSE
     0 Thu May 11 22:59:30 CEST 2006 WEB-INF/lib/
 20682 Thu May 11 22:59:30 CEST 2006 WEB-INF/lib/jstl.jar
393259 Thu May 11 22:59:30 CEST 2006 WEB-INF/lib/standard.jar
   202 Thu May 11 22:59:28 CEST 2006 WEB-INF/web.xml
   577 Tue Feb 15 14:16:18 CET 2011 WEB-INF/weblogic.xml
[dave@dave deployable-libraries]$ jar tvf jstl-1.2.war
     0 Wed Dec 07 08:45:48 CET 2011 META-INF/
   397 Wed Dec 07 08:45:46 CET 2011 META-INF/MANIFEST.MF
     0 Wed Dec 07 08:45:48 CET 2011 WEB-INF/
     0 Wed Dec 07 08:45:48 CET 2011 WEB-INF/lib/
    71 Wed Dec 07 08:45:48 CET 2011 META-INF/javadoc.mf
 23977 Wed Dec 07 08:45:48 CET 2011 WEB-INF/lib/glassfish-jstl_1.2.0.2.jar
   202 Wed Dec 07 08:45:48 CET 2011 WEB-INF/web.xml
[dave@dave deployable-libraries]$ jar tvf jsf-1.2.war
     0 Wed Dec 07 08:45:44 CET 2011 META-INF/
   416 Wed Dec 07 08:45:42 CET 2011 META-INF/MANIFEST.MF
     0 Wed Dec 07 08:45:44 CET 2011 WEB-INF/
     0 Wed Dec 07 08:45:44 CET 2011 WEB-INF/lib/
    66 Wed Dec 07 08:45:44 CET 2011 META-INF/javadoc.mf
 33554 Wed Dec 07 08:45:44 CET 2011 WEB-INF/lib/glassfish-jsf_1.0.0.0_1-2-15.jar
   202 Wed Dec 07 08:45:44 CET 2011 WEB-INF/web.xml
   758 Wed Dec 07 08:45:44 CET 2011 WEB-INF/weblogic.xml
[dave@dave deployable-libraries]$

Deploy JSF 1.1 application on Weblogic 12.1.1

$
0
0
Deploy JSF 1.1 application on Weblogic 12.1.1

http://docs.oracle.com/cd/E24329_01/web.1211/e21049/configurejsfandjtsl.htm

Classloading: Making Hibernate work on WebLogic


If your application includes JSF JARs that you want to reference instead of the WebLogic Server bundled JSF shared libraries, you can configure a filtering classloader inweblogic-application.xml (.ear) as shown below.
http://docs.oracle.com/cd/E24329_01/web.1211/e24368/app_xml.htm

WLS 12.1.1 docs says it can be used also in war it seems to be ignored when only war is deployed.
Note that in order to use prefer-application-packages or prefer-application-resources, prefer-web-inf-classes must be set to false.

http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm

weblogic.xml 

List of schema versions for http://xmlns.oracle.com/weblogic/weblogic-web-app
1.0 : Released with WLS v10.3.1.0
1.1 : Released with WLS v10.3.3.0
1.2 : Released with WLS v10.3.4.0
1.3 : Released with WLS v10.3.6.0
1.4 : Released with WLS v12.1.1.0

 

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>

<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
</prefer-application-resources>
</container-descriptor>
</weblogic-web-app>

weblogic-application.xml 

List of schema versions for http://xmlns.oracle.com/weblogic/weblogic-application
1.0 : Released with WLS v10.3.1.0
1.1 : Released with WLS v10.3.3.0
1.2 : Released with WLS v10.3.4.0
1.3 : Released with WLS v10.3.6.0
1.4 : Released with WLS v12.1.1.0

 

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
<!--weblogic-version:12.1.1-->
<wls:application-param>
<wls:param-name>webapp.encoding.default</wls:param-name>
<wls:param-value>UTF-8</wls:param-value>
</wls:application-param>
<wls:prefer-application-packages>
<wls:package-name>javax.faces.*</wls:package-name>
<wls:package-name>com.sun.faces.*</wls:package-name>
<wls:package-name>com.bea.faces.*</wls:package-name>
</wls:prefer-application-packages>

<wls:prefer-application-resources>
<wls:resource-name>javax.faces.*</wls:resource-name>
<wls:resource-name>com.sun.faces.*</wls:resource-name>
<wls:resource-name>com.bea.faces.*</wls:resource-name>

<wls:resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</wls:resource-name>
</wls:prefer-application-resources>
</wls:weblogic-application>


https://forums.oracle.com/forums/thread.jspa?messageID=10101558&tstart=0

In WLS 12.1.1  release, the weblogic.xml file in jsf-1.2.war configures a filtering classloader for your application's JSF classes and resources.

Which basically means that we have provided a pre-configured filtering classloader definition so that the server will load classes from the specified packages from libraries supplied or referenced by the application. Without this, you'll always get the JSF 2.x implementation that is now provided on the direct WLS classpath (a change in WLS 12c to make using JSF easier).

Is there a reason you're using that older "jsf-myfaces 1.1.7"library? This won't have the filtering classloader definition. If you want to use that, then in addition to making the library reference to it, you'll also need to add a filtering classloader defininition. Take a look at the weblogic.xml file inside the jsf-1.2.war and copy the stanzas to your own configuration
file.













JSF 1.1 tutorial





http://www.coreservlets.com/JSF-Tutorial/jsf1/



Blank JSF 1.1 project 

http://www.coreservlets.com/JSF-Tutorial/jsf1/code/jsf-blank-myfaces.zip






JSF versions



  • JSF 1.1 requires java 1.3 or later, JSP 1.2, JSTL 1.0, and a Java Servlet 2.3 implementation.



  • JSF 1.2 requires java 1.5 or later, JSP 2.1, JSTL 1.2 and a Java Servlet 2.5 implementation (Java EE 5)

  •  JSF 2.0 requires java 1.5 or later, JSP 2.1, JSTL 1.2 and a Java Servlet 2.5 implementation (Java EE 6)

  •  JSF 2.1 requires java 1.5 or later, JSP 2.1, JSTL 1.2 and a Java Servlet 2.5 implementation.


Create OEPE project



JSF 1.1 OEPE project libs ( optional - it is enough to put all libs into WEB-INF/lib )

http://myfaces.apache.org/core11/index.html









JSF 1.1 project configuration



 

JSF 1.1 faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
    <application>
        <message-bundle>resources.application</message-bundle>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
    </application>

</faces-config>

weblogic.xml  using filtering classloader

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.1</wls:weblogic-version>
    <wls:context-root>testJSF11</wls:context-root>
    <wls:container-descriptor>

        <wls:prefer-application-packages>
            <wls:package-name>org.apache.*</wls:package-name>
            <wls:package-name>javax.faces.*</wls:package-name>
            <wls:package-name>com.sun.faces.*</wls:package-name>
            <wls:package-name>com.bea.faces.*</wls:package-name>
        </wls:prefer-application-packages>

        <wls:prefer-application-resources>
            <wls:resource-name>javax.faces.*</wls:resource-name>
            <wls:resource-name>com.sun.faces.*</wls:resource-name>
            <wls:resource-name>com.bea.faces.*</wls:resource-name>
            <wls:resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</wls:resource-name>
        </wls:prefer-application-resources>

    </wls:container-descriptor>

</wls:weblogic-web-app>

JSF 1.1 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>testFSF11</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>

Add JSF 1.1 libraries into WEB-INF/lib
[dave@dave testFSF11]$ ls -lR
.:
total 12
drwxrwxr-x. 3 dave dave 4096 Feb 3 11:12 build
drwxrwxr-x. 3 dave dave 4096 Feb 3 11:12 src
drwxrwxr-x. 4 dave dave 4096 Feb 3 11:12 WebContent

./build:
total 4
drwxrwxr-x. 3 dave dave 4096 Feb 3 11:13 classes

./build/classes:
total 4
drwxrwxr-x. 2 dave dave 4096 Feb 3 11:13 resources

./build/classes/resources:
total 4
-rw-rw-r--. 1 dave dave 227 Feb 3 11:12 application.properties

./src:
total 4
drwxrwxr-x. 2 dave dave 4096 Feb 3 11:12 resources

./src/resources:
total 4
-rw-rw-r--. 1 dave dave 227 Feb 3 11:12 application.properties

./WebContent:
total 12
-rw-rw-r--. 1 dave dave 505 Feb 3 11:12 index.jsp
drwxrwxr-x. 2 dave dave 4096 Feb 3 11:12 META-INF
drwxrwxr-x. 3 dave dave 4096 Feb 3 11:17 WEB-INF

./WebContent/META-INF:
total 4
-rw-rw-r--. 1 dave dave 39 Feb 3 11:12 MANIFEST.MF

./WebContent/WEB-INF:
total 16
-rw-rw-r--. 1 dave dave 391 Feb 3 11:12 faces-config.xml
drwxrwxr-x. 2 dave dave 4096 Feb 3 11:34 lib
-rw-rw-r--. 1 dave dave 1406 Feb 3 11:33 weblogic.xml
-rw-rw-r--. 1 dave dave 3050 Feb 3 11:12 web.xml

./WebContent/WEB-INF/lib:
total 2300
-rw-rw-r--. 1 dave dave 188671 Oct 5 2009 commons-beanutils-1.7.0.jar
-rw-rw-r--. 1 dave dave 559366 Oct 5 2009 commons-collections-3.1.jar
-rw-rw-r--. 1 dave dave 143602 Oct 5 2009 commons-digester-1.8.jar
-rw-rw-r--. 1 dave dave 112341 Nov 17 2009 commons-el-1.0.jar
-rw-rw-r--. 1 dave dave 207723 Oct 5 2009 commons-lang-2.1.jar
-rw-rw-r--. 1 dave dave 60686 Oct 5 2009 commons-logging-1.1.1.jar
-rw-rw-r--. 1 dave dave 16923 Nov 28 2009 jstl-1.1.0.jar
-rw-rw-r--. 1 dave dave 350460 Apr 4 2012 myfaces-api-1.1.10.jar
-rw-rw-r--. 1 dave dave 693804 Apr 4 2012 myfaces-impl-1.1.10.jar
[dave@dave testFSF11]$


Application is accessed http://localhost:7001/testJSF11/faces/index.jsp

To use faces/index.jsp URL  redirect filter is required
/testFSF11/src/coreservlets/FacesRedirectFilter.java ( see CoreServlets tutorial)

Analyze classloading conficts using Weblogic CAT
 (Classloader Analysis Tool)

Conflicts Summary

There are potential conflicts detected and they do not seem to have been resolved. Please review the potential solutions below.

18 classes are in conflict
Those classes are found in the following main packages:
javax.servlet.jsp.*

Suggested Solution

<prefer-application-packages>
<package-name>javax.servlet.jsp.*</package-name>
</prefer-application-packages>



Conflicts
Resource: <select below>

Below is a list of classes that are marked as potential conflicts. By clicking on a class, further information about this class will be shown in this space. This information includes the alternative locations this class may be found and which classloader actually will load this class.
Classes:

javax.servlet.jsp.jstl.core.ConditionalTagSupport
javax.servlet.jsp.jstl.core.Config
javax.servlet.jsp.jstl.core.LoopTag
javax.servlet.jsp.jstl.core.LoopTagStatus
javax.servlet.jsp.jstl.core.LoopTagSupport
javax.servlet.jsp.jstl.core.LoopTagSupport$1Status
javax.servlet.jsp.jstl.fmt.LocaleSupport
javax.servlet.jsp.jstl.fmt.LocalizationContext
javax.servlet.jsp.jstl.sql.Result
javax.servlet.jsp.jstl.sql.ResultImpl
javax.servlet.jsp.jstl.sql.ResultSupport
javax.servlet.jsp.jstl.sql.SQLExecutionTag
javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV
javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV$1
javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV$PermittedTaglibsHandler
javax.servlet.jsp.jstl.tlv.ScriptFreeTLV
javax.servlet.jsp.jstl.tlv.ScriptFreeTLV$1
javax.servlet.jsp.jstl.tlv.ScriptFreeTLV$MyContentHandler



Classloader tree summary

Application Info

    Application: testJSF11
    Version: <Not Set>
    Module: testJSF11
    Annotation: _auto_generated_ear_@testJSF11


System Classloaders
Type: sun.misc.Launcher$ExtClassLoader
HashCode: 27355241
Classpath:

    /opt/weblogic/jdk160_29/jre/lib/ext/dnsns.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/localedata.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/sunjce_provider.jar
    /opt/weblogic/jdk160_29/jre/lib/ext/sunpkcs11.jar

Type: sun.misc.Launcher$AppClassLoader
HashCode: 13288040
Classpath:

    /opt/weblogic/jdk160_29/lib/tools.jar
    /opt/weblogic/modules/features/weblogic.server.modules_12.1.1.0.jar
    /opt/weblogic/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar
    /opt/weblogic/modules/org.apache.ant_1.7.1/lib/ant-all.jar
    /opt/weblogic/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/patch_oepe101/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/patch_wls1211/profiles/default/sys_manifest_classpath/weblogic_patch.jar
    /opt/weblogic/wlserver_12.1/common/derby/lib/derbyclient.jar
    /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
    /opt/weblogic/wlserver_12.1/server/lib/weblogic_sp.jar
    /opt/weblogic/wlserver_12.1/server/lib/webservices.jar
    /opt/weblogic/wlserver_12.1/server/lib/xqrl.jar

Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 33228044
Classpath:

Application Classloaders
Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 8915459
Filter: []
Classpath: empty
Type: weblogic.utils.classloaders.GenericClassLoader
HashCode: 10340792
Classpath:

Type: weblogic.utils.classloaders.FilteringClassLoader
HashCode: 12859001
Filter: [org.apache.*, javax.faces.*, com.sun.faces.*, com.bea.faces.*]
Classpath: empty
Type: weblogic.utils.classloaders.ChangeAwareClassLoader
HashCode: 12896305
Classpath:

    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-beanutils-1.7.0.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-collections-3.1.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-digester-1.8.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-el-1.0.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-lang-2.1.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/commons-logging-1.1.1.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/jstl-1.1.0.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/myfaces-api-1.1.10.jar
    /home/dave/app/myfaces-core-1.1.10-bin/lib/myfaces-impl-1.1.10.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-collections-3.1.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-digester-1.8.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-el-1.0.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-lang-2.1.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/jstl-1.1.0.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-api-1.1.10.jar
    /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-impl-1.1.10.jar
    /home/dave/workspace/testFSF11/build/classes



Application start log- using MyFaces

Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator feedStandardConfig
INFO: Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator feedWebAppConfig
INFO: Reading config /WEB-INF/faces-config.xml
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Artifact 'myfaces-api' was not found.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Artifact 'myfaces-impl' was not found.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Artifact 'tomahawk-sandbox' was not found.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Artifact 'tomahawk' was not found.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Artifact 'tobago-core' was not found.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS' found, using default value true
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_VIEWSTATE_ID' found, using default value true
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.STRICT_XHTML_LINKS' found, using default value true
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig getLongInitParameter
INFO: No context init parameter 'org.apache.myfaces.CONFIG_REFRESH_PERIOD' found, using default value 2
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig createAndInitializeMyFacesConfig
INFO: Tomahawk jar not available. Autoscrolling, DetectJavascript, AddResourceClass and CheckExtensionsFilter are disabled now.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.shared_impl.config.MyfacesConfig createAndInitializeMyFacesConfig
INFO: Starting up Tomahawk on the MyFaces-JSF-Implementation
Feb 3, 2013 11:45:31 AM org.apache.myfaces.webapp.StartupServletContextListener initFaces
INFO: ServletContext '/home/dave/workspace/testFSF11/WebContent' initialized.
Feb 3, 2013 11:45:31 AM org.apache.myfaces.webapp.StartupServletContextListener initFaces
INFO: MyFaces already initialized
Feb 3, 2013 11:45:31 AM org.apache.myfaces.webapp.StartupServletContextListener initFaces
INFO: ServletContext '/home/dave/workspace/testFSF11/WebContent' initialized.


 

Force precompilation of JSP  in weblogic.xml descriptor

 
    <jsp-descriptor>
         <precompile>true</precompile>
        <precompile-continue>true</precompile-continue>
        <keepgenerated>true</keepgenerated>
        <page-check-seconds>-1</page-check-seconds>
        <verbose>true</verbose>
    </jsp-descriptor>

 

JSP files precompilation with wlappc

Requires separate classpath for libs in WEB-INF/lib
<project name="Appc" default="appc" basedir="./">

<target name="appc" description="Packages the WAR file">
<!-- Precompile JSP pages using appc -->
<echo message="Precompile JSP pages using appc in ${assemble.war}" />
<path id="wlappc.classpath">
<fileset dir="${env.WL_HOME}/server/lib">
<include name="weblogic.jar" />
</fileset>
</path>
<path id="compile.classpath">
<fileset dir="${assemble.war}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>

<echo message="${toString:wlappc.classpath}" />
<taskdef name="wlappc" classname="weblogic.ant.taskdefs.j2ee.Appc"
classpathref="wlappc.classpath" />
<wlappc verbose="true" forcegeneration="true" source="${assemble.war}"
classpathref="compile.classpath">

</wlappc>

</target>


</project>

wlappc Ant Task Options

http://docs.oracle.com/cd/E13222_01/wls/docs81/programming/topics.html
 Ant task options specific to wlappc. For the most part, these options are the same as weblogic.appc options. However, there are a few differences.




          
Option



        

          
Description



        

          
print



        

          
Prints the standard usage message.



        

          
version



        

          
Prints appc version information.



        

          
output <file>



        

          
Specifies an alternate output archive or directory. If not set, the output is placed in the source archive or directory.



        

          
forceGeneration



        

          
Forces generation of EJB and JSP classes. Without this flag, the classes will not be regenerated unless a checksum indicates that it is necessary.



        

          
lineNumbers



        

          
Adds line numbers to generated class files to aid in debugging.



        

          
basicClientJar



        

          
Does not include deployment descriptors in client JARs generated for EJBs.



        

          
idl



        

          
Generates IDL for EJB remote interfaces.



        

          
idlOverwrite



        

          
Always overwrites existing IDL files.



        

          
idlVerbose



        

          
Displays verbose information for IDL generation.



        

          
idlNoValueTypes



        

          
Does not generate valuetypes and the methods/attributes that contain them.



        

          
idlNoAbstractInterfaces



        

          
Does not generate abstract interfaces and methods/attributes that contain them.



        

          
idlFactories



        

          
Generates factory methods for valuetypes.



        

          
idlVisibroker



        

          
Generates IDL somewhat compatible with Visibroker 4.5 C++.



        

          
idlOrbix



        

          
Generates IDL somewhat compatible with Orbix 2000 2.0 C++.



        

          
idlDirectory <dir>



        

          
Specifies the directory where IDL files will be created (default: target directory or JAR)



        

          
idlMethodSignatures <>



        

          
Specifies the method signatures used to trigger IDL code generation.



        

          
iiop



        

          
Generates CORBA stubs for EJBs.



        

          
iiopDirectory <dir>



        

          
Specifies the directory where IIOP stub files will be written (default: target directory or JAR)



        

          
keepgenerated



        

          
Keeps the generated .java files.



        

          
compiler <javac>



        

          
Selects the Java compiler to use.



        

          
debug



        

          
Compiles debugging information into a class file.



        

          
optimize



        

          
Compiles with optimization on.



        

          
nowarn



        

          
Compiles without warnings.



        

          
verbose



        

          
Compiles with verbose output.



        

          
deprecation



        

          
Warns about deprecated calls.



        

          
normi



        

          
Passes flags through to Symantec's sj.



        

          
runtimeflags



        

          
Passes flags through to Java runtime



        

          
classpath <path>



        

          
Selects the classpath to use during compilation.



        

          
advanced



        

          
Prints advanced usage options.



        

Precompile JSF 1.1 pages on Weblogic 12c

$
0
0
Even after adding only JSF 1.1 jars  on compile classpath of wlappc the generated java classes are not running correctly on Weblogic 12c. There seems to be problem with classpath of wlappc which is not respecting filtering classloader of weblogic.xml descriptor.

Problem can be solved by adding precompile to jsp-descriptor element of weblogic.xml 


precompile

When set to true, WebLogic Server automatically precompiles all modified JSPs when the Web application is deployed or re-deployed or when starting WebLogic Server


precompile-continue
When set to true, WebLogic Server continues precompiling all modified JSPs even if some of those JSPs fail during compilation. Only takes effect when precompile is set to true.



Weblogic appc
http://docs.oracle.com/cd/E24329_01/web.1211/e24973/appc_ejbc.htm

Add option to check class loading
 http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html

-verbose:class
Display information about each class loaded.


JSP page
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>
<f:loadBundle basename="resources.application" var="msg"/>
<html>
<head>
  <title><h:outputText value="#{msg.welcomeTitle}" /></title>
</head>
<body>

<h3><h:outputText value="#{msg.welcomeHeading}" /></h3>

<p><h:outputText value="#{msg.welcomeMessage}" /></p>

</body>
</html>
</f:view>



Compile using MyFaces libs in WEB-INF/lib
[dave@dave config]$ java weblogic.appc -verboseJavac -verbose ~/workspace/testFSF11/WebContent/
[JspcInvoker]Checking web app for compliance.
<Feb 6, 2013 11:39:24 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".>
<Feb 6, 2013 11:39:24 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".>
[jspc]  -webapp specified, searching . for JSPs
[jspc] Compiling /index.jsp
<Feb 6, 2013 11:39:29 PM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.>

Alternative ant script

<project name="Appc" default="appc" basedir="./">

    <property environment="env"/>

    <target name="appc" description="Packages the WAR file">
        <!-- Precompile JSP pages using appc -->
        <echo message="Precompile JSP pages using appc in WebContent" />
        <path id="wlappc.classpath">
            <fileset dir="${env.WL_HOME}/server/lib">
                <include name="weblogic.jar" />
            </fileset>
        </path>
        <path id="compile.classpath">
            <fileset dir="WebContent/WEB-INF/lib">
                <include name="*.jar" />
            </fileset>
        </path>

        <echo message="${toString:wlappc.classpath}" />
        <echo message="${toString:compile.classpath}" />
        <taskdef name="wlappc" classname="weblogic.ant.taskdefs.j2ee.Appc"
            classpathref="wlappc.classpath" />
        <wlappc verbose="true" keepGenerated="true" source="WebContent"
            verboseJavac="true"
            classpathref="compile.classpath">

        </wlappc>

    </target>


[dave@dave testFSF11]$ ant 
Buildfile: build.xml

appc:
     [echo] Precompile JSP pages using appc in WebContent
     [echo] /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar
     [echo] /home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-collections-3.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-digester-1.8.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-el-1.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-lang-2.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/jstl-1.1.0.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-api-1.1.10.jar:/home/dave/workspace/testFSF11/WebContent/WEB-INF/lib/myfaces-impl-1.1.10.jar
   [wlappc] [JspcInvoker]Checking web app for compliance.
   [wlappc] <Feb 6, 2013 11:51:12 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".>
   [wlappc] <Feb 6, 2013 11:51:12 PM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".>
   [wlappc] [jspc] Overriding descriptor option 'keepgenerated' with value specified on command-line 'true'
   [wlappc] [jspc]  -webapp specified, searching . for JSPs
   [wlappc] [jspc] Compiling /index.jsp
   [wlappc] <Feb 6, 2013 11:51:18 PM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.>

BUILD SUCCESSFUL
Total time: 10 seconds



Compile using JSF 1.2 deployable library

[dave@dave testJSF1]$ java weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war  WebContent/
<Feb 7, 2013 12:52:28 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jsf, Specification-Version: 1.2, Implementation-Version: 1.2.9.0 (WAR).>
Unresolved WebApp library references defined in weblogic.xml, of module 'WebContent' [Extension-Name: jstl, Specification-Version: 1.2, exact-match: true]
[dave@dave testJSF1]$ java weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war,/opt/weblogic/wlserver_12.1/common/deployable-libraries/jstl-1.2.war  WebContent/
<Feb 7, 2013 12:53:07 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jsf, Specification-Version: 1.2, Implementation-Version: 1.2.9.0 (WAR).>
<Feb 7, 2013 12:53:07 AM CET> <Info> <J2EE> <BEA-160151> <Registered library Extension-Name: jstl, Specification-Version: 1.2, Implementation-Version: 1.2.0.2 (WAR).>
[JspcInvoker]Checking web app for compliance.
<Feb 7, 2013 12:53:10 AM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Validating the servlet element with servlet-name named "Faces Servlet".>
<Feb 7, 2013 12:53:10 AM CET> <Info> <HTTP> <BEA-101047> <[ComplianceChecker] Checking servlet-mapping for servlet name : "Faces Servlet".>
[jspc] Overriding descriptor option 'keepgenerated' with value specified on command-line 'true'
[jspc]  -webapp specified, searching . for JSPs
[jspc] Compiling /index.jsp
<Feb 7, 2013 12:53:14 AM CET> <Info> <J2EE> <BEA-160220> <Compilation completed successfully.>

Difference between MyFaces and JSF 1.2 compilation

[dave@dave workspace]$ diff testJSF1/WebContent/WEB-INF/classes/jsp_servlet/__index.java testFSF11/WebContent/WEB-INF/classes/jsp_servlet/__index.java
32c32
< if (sci.isResourceStale("/index.jsp", 1359883373000L ,"12.1.1.0","Europe/Bratislava")) return true;
---
> if (sci.isResourceStale("/index.jsp", 1359886357000L ,"12.1.1.0","Europe/Bratislava")) return true;
105c105
< com.sun.faces.taglib.jsf_core.ViewTag __tag0 = null ;
---
> org.apache.myfaces.taglib.core.ViewTag __tag0 = null ;
109c109
< __tag0 = new com.sun.faces.taglib.jsf_core.ViewTag ();
---
> __tag0 = new org.apache.myfaces.taglib.core.ViewTag ();
116d115
< __tag0.setJspId("id0");
165c164
< private boolean _jsp__tag1(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
> private boolean _jsp__tag1(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
170c169
< com.sun.faces.taglib.jsf_core.LoadBundleTag __tag1 = null ;
---
> org.apache.myfaces.taglib.core.LoadBundleTag __tag1 = null ;
174c173
< __tag1 = new com.sun.faces.taglib.jsf_core.LoadBundleTag ();
---
> __tag1 = new org.apache.myfaces.taglib.core.LoadBundleTag ();
179c178
< __tag1.setBasename( weblogic.servlet.jsp.ELHelper.createValueExpression("resources.application",java.lang.String.class,pageContext,_jspx_fnmap));
---
> __tag1.setBasename(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("resources.application", java.lang.String.class,"basename"));
186c185
< throw new javax.servlet.jsp.JspTagException("Since tag class com.sun.faces.taglib.jsf_core.LoadBundleTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
---
> throw new javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.core.LoadBundleTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
200c199
< private boolean _jsp__tag2(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
> private boolean _jsp__tag2(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
205c204
< com.sun.faces.taglib.html_basic.OutputTextTag __tag2 = null ;
---
> org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag2 = null ;
209c208
< __tag2 = new com.sun.faces.taglib.html_basic.OutputTextTag ();
---
> __tag2 = new org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
214,215c213
< __tag2.setJspId("id2");
< __tag2.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeTitle}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
> __tag2.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeTitle}", java.lang.String.class,"value"));
220a219
> throw new javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
234c233
< private boolean _jsp__tag3(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
> private boolean _jsp__tag3(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
239c238
< com.sun.faces.taglib.html_basic.OutputTextTag __tag3 = null ;
---
> org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag3 = null ;
243c242
< __tag3 = new com.sun.faces.taglib.html_basic.OutputTextTag ();
---
> __tag3 = new org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
248,249c247
< __tag3.setJspId("id3");
< __tag3.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeHeading}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
> __tag3.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeHeading}", java.lang.String.class,"value"));
254a253
> throw new javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");
268c267
< private boolean _jsp__tag4(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, com.sun.faces.taglib.jsf_core.ViewTag parent) throws java.lang.Throwable
---
> private boolean _jsp__tag4(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.jsp.PageContext pageContext, javax.servlet.jsp.tagext.JspTag activeTag, org.apache.myfaces.taglib.core.ViewTag parent) throws java.lang.Throwable
273c272
< com.sun.faces.taglib.html_basic.OutputTextTag __tag4 = null ;
---
> org.apache.myfaces.taglib.html.HtmlOutputTextTag __tag4 = null ;
277c276
< __tag4 = new com.sun.faces.taglib.html_basic.OutputTextTag ();
---
> __tag4 = new org.apache.myfaces.taglib.html.HtmlOutputTextTag ();
282,283c281
< __tag4.setJspId("id4");
< __tag4.setValue( weblogic.servlet.jsp.ELHelper.createValueExpression("#{msg.welcomeMessage}",java.lang.Object.class,pageContext,_jspx_fnmap));
---
> __tag4.setValue(( java.lang.String) weblogic.jsp.internal.jsp.utils.JspRuntimeUtils.convertType("#{msg.welcomeMessage}", java.lang.String.class,"value"));
288a287
> throw new javax.servlet.jsp.JspTagException("Since tag class org.apache.myfaces.taglib.html.HtmlOutputTextTag does not implement BodyTag, it cannot return BodyTag.EVAL_BODY_BUFFERED");


Check from where are classed loaded
[dave@dave jsf-blank-myfaces]$ java -verbose:class weblogic.appc -keepGenerated  -verboseJavac -verbose -library /opt/weblogic/wlserver_12.1/common/deployable-libraries/jsf-1.2.war,/opt/weblogic/wlserver_12.1/common/deployable-libraries/jstl-1.2.war  WebContent/ > classloader.log


weblogic.appc
[dave@dave jsf-blank-myfaces]$ grep appc classloader.log 
[Loaded weblogic.appc from file:/opt/weblogic/wlserver_12.1/server/lib/weblogic.jar]


myfaces
[Loaded javax.faces.webapp.FacesServlet from file:/home/dave/app/jsf-blank-myfaces/WebContent/WEB-INF/lib/myfaces-api-1.1.5.jar]


Extract appc class

[dave@dave jsf-blank-myfaces]$ jar tvf /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar |grep -i appc
2091 Wed Dec 07 08:42:12 CET 2011 weblogic/management/configuration/WebAppContainerMBean.class
19320 Wed Dec 07 08:45:18 CET 2011 weblogic/management/configuration/WebAppContainerMBeanImpl.class
13336 Wed Dec 07 08:45:18 CET 2011 weblogic/management/configuration/WebAppContainerMBeanImpl$Helper.class
9673 Wed Dec 07 08:47:18 CET 2011 weblogic/ant/taskdefs/j2ee/Appc.class
479 Wed Dec 07 08:43:08 CET 2011 weblogic/appc.class

[dave@dave jsf-blank-myfaces]$ jar xvf /opt/weblogic/wlserver_12.1/server/lib/weblogic.jar weblogic/ant/taskdefs/j2ee/Appc.class
inflated: weblogic/ant/taskdefs/j2ee/Appc.class

Disassemble class files using javap
 

[dave@dave jsf-blank-myfaces]$ javap weblogic/ant/taskdefs/j2ee/Appc.class
Compiled from "Appc.java"
public class weblogic.ant.taskdefs.j2ee.Appc extends weblogic.ant.taskdefs.j2ee.CompilerTask {
public weblogic.ant.taskdefs.j2ee.Appc();
public void setClasspath(java.lang.String);
public void setSource(java.lang.String);
public void setOutput(java.lang.String);
public void setForceGeneration(boolean);
public void setLineNumbers(boolean);
public void setBasicClientJar(boolean);
public void setContinueCompilation(boolean);
public void setVerbose(boolean);
public void setEnableHotCodeGen(boolean);
public void setIiopDirectory(java.lang.String);
public void setIdlDirectory(java.lang.String);
public void setIdl(boolean);
public void setIdlOverwrite(boolean);
public void setIdlVerbose(boolean);
public void setIdlNoValueTypes(boolean);
public void setIdlNoAbstractInterfaces(boolean);
public void setIdlFactories(boolean);
public void setIdlVisibroker(boolean);
public void setIdlOrbix(boolean);
public void setIiop(boolean);
public void setIdlMethodSignatures(java.lang.String);
public void setlibraryDir(java.lang.String);
public void setPlan(java.lang.String);
public void setClientJarOutputDir(java.lang.String);
public void addConfiguredLibrary(weblogic.ant.taskdefs.utils.LibraryElement);
public void execute();
}

Weblogic 12c - Java EE 6 decriptors

$
0
0

Java EE 6 descriptors

Web Project 3.0 


web.xml 


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>testJSF2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

weblogic.xml http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm



<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>testJSF2</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>com.dave.*</wls:package-name>
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>com.dave.*</wls:resource-name>
</wls:prefer-application-resources>
</wls:container-descriptor>
<wls:security-role-assignment>
<wls:role-name>daverole</wls:role-name>
<wls:principal-name>dave</wls:principal-name>
</wls:security-role-assignment>
<wls:run-as-role-assignment>
<wls:role-name>daverole</wls:role-name>
<wls:run-as-principal-name>dave</wls:run-as-principal-name>
</wls:run-as-role-assignment>
</wls:weblogic-web-app>

EJB 3.1 project


ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
  <display-name>testDaveEJB31 </display-name>
 </ejb-jar>

weblogic-ejb-jar   http://docs.oracle.com/cd/E24329_01/web.1211/e24973/ejb_jar_ref.htm#autoId0


<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.3/weblogic-ejb-jar.xsd">
<!--weblogic-version:12.1.1-->
<wls:security-role-assignment>
<wls:role-name>daverole</wls:role-name>
<wls:principal-name>dave</wls:principal-name>
</wls:security-role-assignment>
<wls:run-as-role-assignment>
<wls:role-name>daverole</wls:role-name>
<wls:run-as-principal-name>dave</wls:run-as-principal-name>
</wls:run-as-role-assignment>
</wls:weblogic-ejb-jar>

Enterprise Application Project 6 (EAR)


application.xml


<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
id="Application_ID" version="6">
<display-name>testDaveEAR6</display-name>
<module>
<ejb>testDaveEJB31.jar</ejb>
</module>
<module>
<web>
<web-uri>testJSF2.war</web-uri>
<context-root>testJSF2</context-root>
</web>
</module>
</application>

weblogic-application.xml


<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
    <!--weblogic-version:12.1.1-->
    <wls:security>
        <wls:security-role-assignment>
            <wls:role-name>daverole</wls:role-name>
            <wls:principal-name>dave</wls:principal-name>
        </wls:security-role-assignment>
    </wls:security>
    <wls:application-param>
        <wls:param-name>webapp.encoding.default</wls:param-name>
        <wls:param-value>UTF-8</wls:param-value>
    </wls:application-param>
    <wls:prefer-application-packages>
        <wls:package-name>com.dave.*</wls:package-name>
    </wls:prefer-application-packages>
    <wls:prefer-application-resources>
        <wls:resource-name>com.dave.*</wls:resource-name>
    </wls:prefer-application-resources>
</wls:weblogic-application>


Declaring security roles 

http://docs.oracle.com/javaee/5/tutorial/doc/bncav.html

http://docs.oracle.com/cd/E19226-01/820-7627/gjgdi/index.html

@DeclareRoles("employee")
public class CalculatorServlet {
    //...
}

Specifying @DeclareRoles("employee") is equivalent to defining the following in the web.xml:

<security-role>
    <role-name>employee</role-name>
</security-role>

http://docs.oracle.com/cd/E24329_01/web.1211/e24421/secejbwar.htm#autoId1

Deployment Descriptor Only (Java EE standard)
The web.xml,weblogic.xml and ejb-jar.xml, weblogic-ejb-jar.xml deployment descriptors.
If roles have been defined for the application that contains the Web application or EJB, all roles are combined using a logical OR operation.

The following security-related annotations are available:

Eclipse OEPE project facets


 EJB 3.1


 Web 3.0 

 

Load application configuration using CDI on Weblogic 12c

$
0
0
Testing this solution on Weblogic 12c
http://weblogs.java.net/blog/jjviana/archive/2010/05/18/applicaction-configuration-java-ee-6-using-cdi-simple-example

Deployed EJB module requires beans.xml file on META-INF
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>


Annotation Config
package dave;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface Config {
 
}

Configuration factory
package dave;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;

public class ConfigurationFactory {

    private volatile static Properties configProperties;
    public static final String propertiesFilePath = "/application.properties";

    public synchronized static Properties getProperties() {

        if (configProperties == null) {
            configProperties = new Properties();
            try {
                InputStream is = ConfigurationFactory.class.getResourceAsStream(propertiesFilePath);
                System.out.println("Found resource file" + (is != null));
                configProperties.load(is);
            } catch (IOException ex) {
                Logger.getLogger(ConfigurationFactory.class.getName()).log(
                        Level.SEVERE, null, ex);
                throw new RuntimeException(ex);
            }

        }

        return configProperties;
    }

    public @Produces
    @Config
    String getConfiguration(InjectionPoint p) {

        String configKey = p.getMember().getDeclaringClass().getName() + "."
                + p.getMember().getName();
        Properties config = getProperties();
        if (config.getProperty(configKey) == null) {
            configKey = p.getMember().getDeclaringClass().getSimpleName() + "."
                    + p.getMember().getName();
            if (config.getProperty(configKey) == null)
                configKey = p.getMember().getName();
        }
        System.err.println("Config key= " + configKey + " value = "
                + config.getProperty(configKey));

        return config.getProperty(configKey);
    }

    public @Produces
    @Config
    Double getConfigurationDouble(InjectionPoint p) {

        String val = getConfiguration(p);
        return Double.parseDouble(val);

    }

}


Test Facade
package dave;

import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class TestFacade
 */
@Stateless(mappedName = "TestFacade")
public class TestFacade implements TestFacadeRemote {

    @EJB
    TestStateless stateless;

    public String getServerAddress() {
        return stateless.getServerAddress();
    }

}

Facade Remote interface
package dave;

import javax.ejb.Remote;

@Remote
public interface TestFacadeRemote {

public String getServerAddress();

}


EJB client calling facade
Client requires  /opt/weblogic/wlserver_12.1/server/lib/wlthint3client.jar on CLASSPATH
package dave;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TestEJBClient {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
        try {
            Properties props = new Properties();
            props.put(Context.PROVIDER_URL, "t3://localhost:7001");
            props.put(Context.INITIAL_CONTEXT_FACTORY,
                    "weblogic.jndi.WLInitialContextFactory");
            Context ctx = new InitialContext(props);
            TestFacadeRemote facade = (TestFacadeRemote) ctx.lookup("TestFacade#dave.TestFacadeRemote");
           
            System.out.println(facade.getServerAddress());
           
        } catch (NamingException e) {
            e.printStackTrace();
        }

    }

}



Loading configuration value in application class
package dave;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * Session Bean implementation class TestStateless
 */
@Stateless(mappedName = "TestStateless")
@LocalBean
public class TestStateless {

    @Inject @Config
    private String serverAddress;
   
    public String getServerAddress() {
        return serverAddress;
    }
   

}


Output in Weblogic server log
Found resource filetrue
Config key= serverAddress value = dave

Test with plain Java class
package dave;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;


@ApplicationScoped
public class TestBean {
   
    @Inject @Config
    private String serverAddress;
   
    public String getServerAddress() {
        return serverAddress;
    }

}

Added call to plain class
package dave;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * Session Bean implementation class TestFacade
 */
@Stateless(mappedName = "TestFacade")
public class TestFacade implements TestFacadeRemote {

    @EJB
    TestStateless stateless;
   
    @Inject
    TestBean testBean;

    public String getServerAddress() {
       
        System.out.println("get value from testbean " + testBean.getServerAddress());
       
        System.out.println("get value from testbean " + testBean.getServerAddress());
       
        System.out.println("get value from stateless " + stateless.getServerAddress());
       
        System.out.println("get value from stateless " + stateless.getServerAddress());
       
        return stateless.getServerAddress();
    }

}


Output in Weblogic log
Found resource filetrue
Config key= serverAddress value = dave
get value from testbean dave
get value from testbean dave
Config key= serverAddress value = dave
get value from stateless dave
get value from stateless dave



Exception when config file is not found
Exception in thread "main" javax.ejb.EJBTransactionRolledbackException: EJB Exception: 
    at weblogic.ejb.container.internal.BaseLocalObject.handleSystemException(BaseLocalObject.java:453)
    at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:166)
    at weblogic.ejb.container.internal.BaseLocalObject.preInvoke(BaseLocalObject.java:103)
    at weblogic.ejb.container.internal.BaseLocalObject.__WL_preInvoke(BaseLocalObject.java:67)
    at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:20)
    at dave.TestStateless_954dmo_NoIntfViewImpl.getServerAddress(Unknown Source)
    at dave.TestFacade.getServerAddress(TestFacade.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.oracle.pitchfork.intercept.MethodInvocationInvocationContext.proceed(MethodInvocationInvocationContext.java:103)
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.oracle.pitchfork.intercept.JeeInterceptorInterceptor.invoke(JeeInterceptorInterceptor.java:108)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(Unknown Source)
    at $Proxy111.getServerAddress(Unknown Source)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:32)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl.getServerAddress(Unknown Source)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:695)
    at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:520)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:516)
    at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:418)
    at java.util.Properties.load0(Properties.java:337)
    at java.util.Properties.load(Properties.java:325)
    at dave.ConfigurationFactory.getProperties(ConfigurationFactory.java:22)
    at dave.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:137)
    at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:132)
    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:299)
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:61)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:630)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:691)
    at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:118)
    at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:691)
    at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:700)
    at org.jboss.weld.bean.SessionBean$1$1.proceed(SessionBean.java:175)
    at com.oracle.injection.provider.weld.WeldInjectionServicesAdapter.aroundInject(WeldInjectionServicesAdapter.java:88)
    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:45)
    at org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:172)
    at com.oracle.injection.provider.weld.WeldEjbBeanManager$ExtendedInjectionTarget.inject(WeldEjbBeanManager.java:119)
    at com.oracle.injection.provider.weld.WeldEjbBeanManager.newBeanInstance(WeldEjbBeanManager.java:82)
    at weblogic.ejb.container.injection.InjectionBasedEjbComponentCreator.getBean(InjectionBasedEjbComponentCreator.java:75)
    at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(BaseEJBManager.java:209)
    at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBManager.java:235)
    at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessManager.java:293)
    at weblogic.ejb.container.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:185)
    at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSessionPool.java:114)
    at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessManager.java:174)
    at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:146)
    ... 38 more
Viewing all 181 articles
Browse latest View live