Friday, February 12, 2016

How to check whether LDAP username and password is correct - LDAP/OpenDJ

You can use "ldapwhoami" command to check whether a ldap username and password is correct.

ldapwhoami -vvv -h <host> -p <port> -D "<binddn>" -x -w <password>

"bindDN" is the LDAP credential you used to authenticate with a LDAP server.

Example of binddn;

cn=Manager,ou=example,dc=com,dc=au

Command line options used in this example:

-H ldapuri - Specify URI(s) referring to the ldap server(s); only the protocol/host/port fields are allowed; a list of URI, separated by whitespace or commas is expected.
-h ldaphost - Specify an alternate host on which the ldap server is running. Deprecated in favor of -H.
-p ldapport - Specify an alternate TCP port where the ldap server is listening. Deprecated in favor of -H.
-v - Run in verbose mode, with many diagnostics written to standard output.
-w passwd - Use passwd as the password for simple authentication. 
-x - Use simple authentication instead of SASL
-D binddn -Use the Distinguished Name binddn to bind to the LDAP directory. For SASL binds, the server is expected to ignore this value.

More details:

Tips on Tools Usage - SqlPlus

Editing a previously executed sql statement:

Type ed in the sqlplus. Then sqlplus will open the previous command in an editor (e.g: in vi). Then you can edit the sql command and save it using Esc key + :wq as you normally does in "vi" editor.
Then type / to run the edited command.

Executing the previous sql statement:

Type / or r in the sqlplus terminal to run the previously executed sql statement again.

Show the previously executed sql statement without executing it:

Type "list" in the sqlplus terminal.

Formatting of the sql output:

Change the width of a column in the sql output, for a character field:

column <filed_name> format a<width_number_of_characters>

E.g:
column user_name format a100

Change the width of a column in the sql output, for a numeric field:

column <field_name> format <number_format>

E.g:
column salary format 9999.99

Set the line size of the sql output:

set linesize <line_size>

E.g:
set linesize 300

More Details:

http://www.comp.nus.edu.sg/~ooibc/courses/sql/sqlplus.htm
http://ugweb.cs.ualberta.ca/~c391/manual/chapt4.html
http://www.orafaq.com/wiki/SQL*Plus

Tips on Tools Usage - WLST (For viewing MBeans)

Locate the wlst.sh

solaris:

find <a_parent_folder_in_path_to_wls> -name wlst.sh

linux:

locate wlst.sh

Storing weblogic admin username password in a file for easy access:

Use storeUserConfig([userConfigFile], [userKeyFile], [nm]) command.
After this, you do not have to specify username and password when connecting to a wlst session.

Example session for viewing custom MBeans (MBeans in your application):


cd /<path_to_wls>/wlserver_10.3/common/bin
sh ./wlst.sh
wls:/offline> connect(url='t3://hostname:managedserverpot')
custom()
ls()

Tuesday, February 9, 2016

MySQL - An alternative for using constants in MySQL stored procedures

MySQL does not support declaring constants to be shared between different stored procedures. But some other RDBMS like Oracle supports this feature. To still have something similar to constants in Oracle PL/SQL in MySQL, I found that following workaround acts as an alternative to declaring constant variables.

In MySQL, you can add some characteristics of the your stored function in the stored function definition. you can mark a stored function as a DETERMINISTIC or NON-DETERMINISTIC.
DETERMINISTIC means for same input, the function returns the same output every time it invokes.
In addition to this, you can mark a stored function to say whether the function has SQL or not, whether the SQL in the function does any update or read only.

What I am going to use as an alternative to constant is to use a DETERMINISTIC NO SQL function (without any input argument) with the same name as the constant I want and which returns the value of the constant variable I want to use.

Example: Following example shows how this alternative solution is applied for a constant named "OPERATION_TYPE_ABORT" with the value "ABORT". 
DROP FUNCTION IF EXISTS OPERATION_TYPE_ABORT;
DELIMITER //
CREATE FUNCTION OPERATION_TYPE_ABORT() RETURNS VARCHAR(6) 
DETERMINISTIC NO SQL
BEGIN
    RETURN ("ABORT");
END//
DELIMITER ;

Output:

mysql> select "test" FROM DUAL WHERE "ABORT" = OPERATION_TYPE_ABORT();
+------+
| test |
+------+
| test |
+------+
1 row in set (0.00 sec)

mysql> select "test" FROM DUAL WHERE "ABORT2" = OPERATION_TYPE_ABORT();
Empty set (0.00 sec)

How to check the JDK version used for compiling a java class

You can use javap command to find the compiled version of a class. javap (Java Class File Disassembler) tool is a tool provided with JDK to disassemble class files.

Unix:

Open a terminal and change the working directory to the place where your class is located.
javap -verbose HelloWorld.class| grep "major"
 

Windows:

Open a command prompt and change the working directory to the place where your class is located.
javap -verbose HelloWorld.class | findstr "major" 
 
E.g.: 
 
 
 
 Following is the mapping between the major version and the relevant JDK version.
Major VersionComipled JDK version
461.2
471.3
481.4
495
506
517
528