How to enable TLS 1.2 Protocol for SOAP/REST calls in SOAP-UI

Sometimes, we need to hit an endpoint URL which is TLS 1.2 enabled and SOAP UI does not support it by default. Therefore, we could follow given below steps for necessary tuning:-

(1) Navigate to C:\Program Files\SmartBear\SoapUI-5.2.1\bin folder.

(2) Edit SoapUI-5.2.1.vmoptions file with any text editor.

(3) Add following entry and save the file. It will only enable TLS 1.2 protocol.

-Dsoapui.https.protocols=TLSv1.2
Advertisements

How to Mock Spring Security Context

Let’s say, we have the sample code for which we have to write Junit

 
public ApplicationUser getApplicationUser() {
	ApplicationUser applicationUser = (ApplicationUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	return applicationUser;
}

Therefore, to mock Spring Security Context to get the Principal object we could follow the given below approach:-

 
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import org.mockito.MockitoAnnotations;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import com.arpit.security.user.ApplicationUser;

public class BaseTest {

	@Before
	public void setupMock() {
		MockitoAnnotations.initMocks(this);
	}

	@Test
	public void mockApplicationUser() {
		ApplicationUser applicationUser = mock(ApplicationUser.class);
		Authentication authentication = mock(Authentication.class);
		SecurityContext securityContext = mock(SecurityContext.class);
		when(securityContext.getAuthentication()).thenReturn(authentication);
		SecurityContextHolder.setContext(securityContext);
		when(SecurityContextHolder.getContext().getAuthentication().getPrincipal()).thenReturn(applicationUser);
	}

}

Happy Coding !! ๐Ÿ™‚

Enable SSL Debug Trace in WebSphere

As a developer, we may have to enable SSL Debug Trace in WebSphere. Hence, following are the brief steps that could be used for reference:-

1. In the WebSphere Application Server (WAS) Admin Console, navigate to Servers > Server Types > WebSphere application servers, then select the server name.

2. Under Server Infrastructure, expand Java and Process Management > Process definition > Java Virtual Machine.

3. Add the following to the end of the Generic JVM Arguments box:

-Djavax.net.debug=ssl,handshake,data,trustmanager

4. Save to the master config, and restart the server for it to take hold.

5. This will add debug trace of the SSL handshake to the //profiles//logs//SystemOut.log

Happy Debugging ๐Ÿ™‚

Virtual Host Entry in WebSphere

Virtual host name entry could be found in plugin-cfg.xml of a server profile in WebSphere. It is mostly used to configure the port details which forms the complete URL for an application like http://serverName.application.com:55295/loan/casmgmt.htm

Location of an Application Server Profile:-
/WebSphere/7/AppServerBase1/profiles/AppServerBase1/installedApps/Server_Application_Cell/ear/Loan_Application.ear

Location of a file:-
/WebSphere/7/AppServerBase1/profiles/AppServerBase1/config/cells/plugin-cfg.xml

   <VirtualHostGroup Name="Loan_Application">
      <VirtualHost Name="*:55295"/>
   </VirtualHostGroup>

SQL query to extract XML data from Oracle table

Following query will help to extract the information of xml element from stored XML data in Oracle table.

select
	XMLTYPE(ad.ad_profile).EXTRACT('//bankId').getStringVal(), 
	XMLTYPE(ad.ad_profile).EXTRACT('//altDesc').getStringVal(), 
	DECODE(ad.adsta_id, 1, 'Success', 2, 'Failure')
from 
	alert_delivery ad
where 
	ad.altd_id in (1001,1002)
group by 
	XMLTYPE(ad.ad_profile).EXTRACT('//bankId').getStringVal(), 
	XMLTYPE(ad.ad_profile).EXTRACT('//altDesc').getStringVal(), 
	ad.adsta_id;

SQL script to grant the access to Schema owners

Sometimes, we need a SQL script to grant the access of different objects to multiple schema owners. Following script could be used as a reference :-

  
FOR R IN (SELECT owner, object_name from all_objects 
                where object_type in ('FUNCTION', 'PROCEDURE') 
                and owner in ('USR_APP', 'PRO_APP', 'TXN_APP')) LOOP
        execute immediate 'grant execute on ' || R.OWNER || '.' || R.Object_Name || ' to ' || 'SC_READ_ONLY_ACCESS';
END LOOP;

Happy Coding !!

Scala โ€“ Tuples & Lists

=====================================================
Tuples
=====================================================
A Tuple is a generalization of a collection of two, three, four, and more values. Each value can have its own type.

scala> val twoInts = (5,10)
	twoInts: (Int, Int) = (5,10)
 
scala> val twoStrings = ("Hello", "World")
	twoStrings: (String, String) = (Hello,World)
 
scala> val threeDoubles = (1.11, 2.22, 3.33)
	threeDoubles: (Double, Double, Double) = (1.11,2.22,3.33)
 
scala> val intAndString = (1, "Good Evening")
	intAndString: (Int, String) = (1,Good Evening)
 
scala> val mixedUp = (1, "Vinay Chauhan", 90.50)
	mixedUp: (Int, String, Double) = (1,Vinay Chauhan,90.5)

The elements of a Tuple can be recovered in a few different ways. One way is to use a Tuple when initializing some variables, each of which takes on the value of the corresponding position in the Tuple on the right side of the equal sign.

scala> var (firstInt,secondInt) = twoInts
	firstInt: Int = 5
	secondInt: Int = 10

scala> firstInt
	res39: Int = 5	

Similarly, we could do the actvity for other tuples. 

scala> var (rollNo,name,marks) = mixedUp
	rollNo: Int = 1
	name: String = Vinay Chauhan
	marks: Double = 90.5

scala> rollNo
	res41: Int = 1

scala> name
	res42: String = Vinay Chauhan

scala> marks
	res43: Double = 90.5

***********************************
Few Tips
***********************************	
Another way to access the values in a Tuple is via indexation, using โ€œ_nโ€ where n is the index of the item you want.

scala> print(mixedUp._1)
	1
scala> print(mixedUp._2)
	Vipin Chauhan
scala> print(mixedUp._3)
	90.5

***********************************
Few Tips
***********************************
An alternate form of creating a 2-sized tuple is with the relation operator (->). This is a popular shortcut for representing key-value pairs in tuples:	

scala> val fruitData = "FruitKing" -> "Mango"
	fruitData: (String, String) = (FruitKing,Mango)

scala> fruitData._1
	res3: String = FruitKing

scala> fruitData._2
	res4: String = Mango

=====================================================
Lists
=====================================================
Lists are collections of ordered items that will be familiar to anyone who has done any shopping. Tuples are obviously related to lists, but they are less versatile in that they must be created in a single statement, they have a bounded length (about 20 or so), and they donโ€™t support operations that perform computations on all of their elements. In Scala, we can create lists of Strings, Ints, and Doubles (and more).

scala> val fruitList = List("Mango","Orange","PineApple")
	fruitList: List[String] = List(Mango, Orange, PineApple))

scala> fruitList.head
	res0: String = Mango

scala> fruitList.tail
	res2: List[String] = List(Orange, PineApple)

scala> fruitList
	res3: List[String] = List(Mango, Orange, PineApple)

scala> fruitList(1)
	res4: String = Orange

scala> fruitList(2)
	res5: String = PineApple

scala> for(data <- fruitList) println(data) Mango Orange PineApple scala> val oddList = List(1,3,5,7);
	oddList: List[Int] = List(1, 3, 5, 7)

We see that Scala responds that a List has been created, along with brackets around the type of the elements it contains. So, List[Int] is read as โ€œa List of Intsโ€ and so on. This is to say that List is a parameterized data structure: it is a container that holds elements of specific types. 

***********************************
Few Tips
***********************************	
We can also create Lists with mixtures of types.

scala> val intsAndDoubles  = List (1,1.5,2,2.5)
	intsAndDoubles: List[Double] = List(1.0, 1.5, 2.0, 2.5)

scala> val embeddedList = (fruitList,oddList);
	embeddedList: (List[String], List[Int]) = (List(Mango, Orange, PineApple),List(1, 3, 5, 7))

***********************************
Use Case for Reducer 
***********************************
scala> val numbers = List(1,2,3,4,5)
	numbers: List[Int] = List(1, 2, 3, 4, 5)

scala> val total = numbers.reduce((a:Int, b:Int) => a+b)
	total: Int = 15

	
=========================================================================
List methods
=========================================================================
scala> fruitList.length
	res48: Int = 3

Comments: The notation variable.method indicates that you are invoking a function that is specific to the type of that variable on the value in that variable. Scala is an object-oriented language, which means that every value has a set of actions that comes with it. Which actions are available depends on its type. 

scala> 2.+(3)
	res49: Int = 5

scala> "Good".+("Evening")
	res51: String = GoodEvening	

Comments: Lets return to Lists and what we can do with them. โ€œAdditionโ€ of two lists is their concatenation and is indicated with โ€œ++โ€œ.

scala> val oddList = List(1,3,5,7);
	oddList: List[Int] = List(1, 3, 5, 7)

scala> val evenList = List (2,4,6,8);
	evenList: List[Int] = List(2, 4, 6, 8)

scala> val completeList = oddList ++ evenList
	completeList: List[Int] = List(1, 3, 5, 7, 2, 4, 6, 8)

Comments: We can append a single item to the front of a List with โ€œ::โ€œ.

scala> val completeList = 0 :: oddList ++ evenList
	completeList: List[Int] = List(0, 1, 3, 5, 7, 2, 4, 6, 8)

And sort a list with sorted, and reverse it with reverse, and do both in sequence

scala> completeList.sorted
	res52: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8)

scala> completeList.reverse
	res54: List[Int] = List(8, 6, 4, 2, 7, 5, 3, 1, 0)

scala> completeList.sorted.reverse
	res55: List[Int] = List(8, 7, 6, 5, 4, 3, 2, 1, 0)

Note: List is immutable: you cannot change it, so all of these operations will always return new Lists. 

scala> val myList = completeList.sorted
	myList: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8)

scala> myList(2);
	res57: Int = 2

Another useful method is slice, which gives you a sublist from one index up to, but not including, another.
scala> myList.slice(2,6)
	res58: List[Int] = List(2, 3, 4, 5)

Therefore, the slice gave us a list with the elements from index 2 (the third element) up to index 5 (the sixth element).

***********************************
Few Tips
***********************************
On lists that contain numbers, we can use the sum method.
scala> myList.sum
	res60: Int = 36

One thing we often want to do with lists is obtain a String representation of their contents in some visually useful way. For example, we might want a fruitList to be a String with one item per line, or a list of Ints to have a comma between each element. The mkString method does just what we need.

scala> fruitList.mkString("\n")
	res61: String =
	Mango
	Orange
	PineApple

Want to know if a list contains a particular element? Use contains on the list.
scala> fruitList.contains("Apple")
	res63: Boolean = false

scala> fruitList.contains("Mango")
	res64: Boolean = true