com.jk.db.dataaccess.orm.eclipselink.FSSessionPCustomizer.java Source code

Java tutorial

Introduction

Here is the source code for com.jk.db.dataaccess.orm.eclipselink.FSSessionPCustomizer.java

Source

/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jk.db.dataaccess.orm.eclipselink;

import java.util.Properties;

import org.apache.commons.codec.binary.Base64;

/**
 * The Class FSSessionPCustomizer.
 *
 * @author Jalal Kiswani
 */
public class FSSessionPCustomizer {

    /**
     * Customize.
     *
     * @param prop
     *            the prop
     * @throws Exception
     *             the exception
     */
    public void customize(Properties prop) throws Exception {
        Object userNameProperty = prop.getProperty("fs.username");
        Object passwordProperty = prop.getProperty("fs.password");
        System.out.println("Username : " + userNameProperty + " , Password : " + passwordProperty);

        String userName = decode(userNameProperty.toString());

        String password = decode(passwordProperty.toString());

        //      prop.getLogin().setUserName(userName);
        //      prop.getLogin().setPassword(password);
        //
        //      prop.getProperties().put("javax.persistence.jdbc.user", userName);
        //      prop.getProperties().put("javax.persistence.jdbc.password", password);

    }

    /**
     * Decode.
     *
     * @param name
     *            the name
     * @return the string
     */
    public static String decode(String name) {
        return new String(Base64.decodeBase64(name));
    }

    /**
     * Encode.
     *
     * @param value
     *            the value
     * @return the string
     */
    public static String encode(String value) {
        return new String(Base64.encodeBase64(value.getBytes()));
    }

    /**
     * The main method.
     *
     * @param args
     *            the arguments
     */
    public static void main(String[] args) {
        System.out.println(encode("root"));
        System.out.println(encode("123456"));
        System.out.println(decode("ZmluOTc1MzE="));
    }

}