Skip to content

Instantly share code, notes, and snippets.

View nipunthathsara's full-sized avatar

Nipun Thathsara nipunthathsara

View GitHub Profile
@nipunthathsara
nipunthathsara / GSoC-2017-Openmrs.md
Last active August 28, 2017 19:11
Anonymous Patient Registration project - Description, Code and Installation guide

Anonymous Patient Registration Project

Student: Nipun Thathsara

Mentor: Sara Fatima

Project: Anonymous Patient Rgistration Project

Organization: Openmrs

Description: Openmrs supports registration of unknown patients. Project objectives are to make this function work out of the box for reference application and move unknown patient registration functionality to the openmrs-core by removing its dependency to modules.

@nipunthathsara
nipunthathsara / Sample Axis2 client
Created July 13, 2018 12:50
Axis2 SOAP client sample
package org.wso2.sample;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.synapse.MessageContext;
@nipunthathsara
nipunthathsara / URLClassLoader.java
Created April 10, 2020 19:11
URLClassLoader.java - Loading *.class files
...
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
final Class<?> result;
try {
result = AccessController.doPrivileged(
new PrivilegedExceptionAction<>() {
public Class<?> run() throws ClassNotFoundException {
@nipunthathsara
nipunthathsara / Launcher$AppClassLoader.java
Last active April 11, 2020 10:01
Launcher$ExtClassLoader java.ext.dirs
...
static class AppClassLoader extends URLClassLoader {
static {
ClassLoader.registerAsParallelCapable();
}
public static ClassLoader getAppClassLoader(final ClassLoader extcl)
throws IOException
{
@nipunthathsara
nipunthathsara / Launcher$ExtClassLoader.java
Created April 11, 2020 10:03
Launcher$ExtClassLoader.java getExtDir method
static class ExtClassLoader extends URLClassLoader {
public static ExtClassLoader getExtClassLoader() throws IOException
{
final File[] dirs = getExtDirs();
...
}
private static File[] getExtDirs() {
String s = System.getProperty("java.ext.dirs");
@nipunthathsara
nipunthathsara / Foo.java
Created April 13, 2020 15:50
Class loading example
package org.example;
import java.util.ArrayList;
import com.sun.crypto.provider.AESKeyGenerator;
public class Foo {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("java.ext.dirs : " + System.getProperty("java.ext.dirs"));
System.out.println("com.sun.crypto.provider.AESKeyGenerator : " + AESKeyGenerator.class.getClassLoader());
@nipunthathsara
nipunthathsara / LDAPSearch.sh
Created April 21, 2020 11:46
LDAP Search samples
// Check if xyz.com tenant admin exists in the LDAP server.
ldapsearch -H ldap://localhost:10389 -x -D "uid=admin,ou=system" -W -b "ou=users,ou=xyz.com,dc=wso2,dc=org" "(&(objectClass=person)(uid=xyzadmin))"
@nipunthathsara
nipunthathsara / curl.sh
Created April 23, 2020 20:18
Shell - Curl with random inputs
while(true)
do
curl -k -v -X POST 'http://192.168.43.173:5000/api/sensor-data' \
--header 'Content-Type: application/json' \
--header 'x-auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTg3NjUxMzEzLCJleHAiOjE1ODc2NTQ5MTN9.JLaDFORUBzIgH58c1BZLKFH6YiHkOEaCcXh015kZtfA' \
--header 'Content-Type: Application/json' \
--data "{\"sensorId\": \"$(( ( RANDOM % 10 ) + 1 ))\", \"co2Level\": \"$(( ( RANDOM % 10 ) + 1 ))\", \"smokeLevel\": \"$(( ( RANDOM % 10 ) + 1 ))\"}"
sleep 5
done
@nipunthathsara
nipunthathsara / adaptive-script.js
Created June 23, 2020 10:45
Enable Two Factor for Facebook authentication - Adaptive script
// Define the list of Social Identity Providers to step up the authentication.
var IdPsToStepUp = ['Facebook_IDP'];
var onLoginRequest = function(context) {
executeStep(1, {
// If first step (FB login) was a success then...
onSuccess: function (context) {
// Check if the first step was Facebook.
var idp = context.currentStep.idp;
if (IdPsToStepUp.indexOf(idp) >= 0) {
@nipunthathsara
nipunthathsara / App.java
Created September 13, 2020 16:20
Create OUs in LDAP
package org.example;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;