Welcome to Gary Han's den on the web.
This portal records Gary's everyday thoughts and notes on programming and life.
Please enjoy...

Saturday, October 8, 2016 - 3:08pm

  • Saturday, October 8, 2016 - 3:08pm

    few ways to get the user information:

    -User user= (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    this pulls the whole user object.

    - Principal userPrincipal = request.getUserPrincipal();
    this pulls the user principal, which has access to the username by doing:
    userPrincipal.getName();

    - User currentUser = request.getSession(false).getAttribute("SPRING_SECURITY_CONTEXT").getAuthentication().getPrincipal();
    you may do a few null checks, but this is the long and early way to get the user. Works in the filters too.

Monday, September 19, 2016 - 11:29am

  • Monday, September 19, 2016 - 11:29am

    Just a fun note,

    I was having a discussion with a group of programmers from different backgrounds.

    And I was asked the question whats a better language and why do you prefer Java.

    So my answer is, I like to build using Lego not PlayDoh.

    When I program in Java, I feel my program is very safe and consistent.

    when I program in PHP, Python or Ruby, I feel my program is very squishy.

    A simply example is:

Monday, September 22, 2014 - 2:15pm

  • Monday, September 22, 2014 - 2:15pm

    We can go on and on about feature differences on Oracle and Mysql. Table locking, stored proc, recovery, transaction control blah blah blah...
    As a software user (yes, they are just regular software we use) I don't really care as long as it works and does what I need.

    So today I want to get to the point and take note of the performance differences in Oracle and Mysql.

    The key difference in Oracle over Mysql is its ability to perform fast CRUDs even under large number of threads and transactions.

Wednesday, April 9, 2014 - 11:36am

  • Wednesday, April 9, 2014 - 11:36am

    Since so many people are talking about this issue, I will join too.

    Openssl has a very simple yet dangerous flaw in the programming when they implemented the heartbeat feature.

    Heartbeat is used to keep the session alive by having client server send a request over and the hosting server sends a response back.

    But the issue with that is the request contains both the package and the package size.

    and openssl simply echos back the original package and append anything after it with whatever package size it was specified?
    REALLY? SERIOUSLY?

Tuesday, October 8, 2013 - 12:50pm

  • Tuesday, October 8, 2013 - 12:50pm

    Websphere is a pain in the butt to deal with.

    So whenever you have issues deploying a war file or any kind of issues,

    first thing to try is to clear the websphere cache! I will do the trick 99% of the time!

    to do so:

    shut down websphere server.

    /{websphereInstallPath}/IBM/WebSphere/AppServer/bin/clearClassCache.sh
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/*
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/wstemp/*
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/temp/*

Wednesday, August 21, 2013 - 3:43pm

  • Wednesday, August 21, 2013 - 3:43pm

    If you are putting your database to maintenance, and you want to kill off all sessions from connecting your db so you can do whatever you want with it.

    Do the follow for a quick clean up:

    STARTUP FORCE;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;

    now you are free to do whatever you want with your database.

    when you are done:

    ALTER SYSTEM UNQUIESCE;

    now all other connections can start hitting your database again.

Wednesday, June 5, 2013 - 12:14pm

  • Wednesday, June 5, 2013 - 12:14pm

    simple reminder to enable ftp on server:

    yum -y install vsftpd

    vi /etc/vsftpd/vsftpd.conf

    ensure a line listen_port=21 is added to the config file,
    and remove #connect_from_port_20=YES

    vi /etc/vsftpd/ftpusers
    remove root as not allowed user

    vi /etc/vsftpd/user_list
    remove root as not allowed user

Tuesday, April 23, 2013 - 11:21am

  • Tuesday, April 23, 2013 - 11:21am

    When working with special characters we sometimes run into the issue where the string is not recognizing these characters.
    Especially when trying to parse files from one platform from another.

    I had the following line in a txt file on windows: (saved as ANSI)

    éèêë

    I had the following code that parses and replaces these characters:
    (Java file is saved as UTF-8)
    -------------------
    File file = new File("/windowsPathMappedOnLinux");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    String fileContent = "";

Tuesday, August 9, 2011 - 5:56pm

  • Tuesday, August 9, 2011 - 5:56pm

    When you get a database dump from a server and try to import it to one another, often u will face errors like:

     DEFAULT '1753-01-01 00:00:00', "end_date" DATE DEFAULT '1753-01-01
    ORA-39083: Object type TABLE failed to create with error:
    ORA-01861: literal does not match format string

     

    This indicates that the database dump might be using a string format which is different from your server.

    To prove this, login to sqlplus, and do:

    select sysdate from dual;

    if the result is not of:

Thursday, March 3, 2011 - 11:00am

  • Thursday, March 3, 2011 - 11:00am

    Many of us might have came to the probelm where in IE or Chrome, when visiting the secure pages an alert message pops up saying that some of the content of the page is not encrypted.
    This is usually due to non-relative links on our page.
     
    i.e.:
    in: https://www.garyhan.com/secure but some how all your images and css are showing up as http.
    This is because usually when setting up a load balancer, the encryption is handled on the balancer(LB) level, then the LB transfers requests to each of your servers on http port.