001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.plugin.token;
017    
018    import java.util.Dictionary;
019    import java.util.Hashtable;
020    
021    import org.opengion.hayabusa.common.HybsSystem;
022    import org.opengion.hayabusa.html.AbstractCreateToken;
023    import org.opengion.fukurou.util.StringUtil;
024    import com.akamai.token_v2.*;
025    
026    // import com.akamai.authentication.URLToken.URLTokenFactory;
027    
028    /**
029     * アカマイのト?クンを付加するためのプラグインです?
030     * 
031     * 以下?シス?リソース設定を行う事でパラメータの変更が可能です?
032     * AKAMAI_TOKEN_NAME:ト?クン名称(初期値?akminame)
033     * AKAMAI_ENCRYPTION:ト?クン作?時暗号化キー(初期値?enckey)
034     * 
035     * こ?プラグイン利用にはcom.akamai.token_v2.*;が?です?
036     *
037     * @og.group 画面表示
038     * @og.rev 5.8.2.2 (2014/12/19) 
039     *
040     * @version  5.0
041     * @author       Takahashi Masakazu
042     * @since    JDK5.0,
043     */
044    public class CreateToken_Akamai extends AbstractCreateToken {
045            //* こ?プログラ??VERSION??を設定します?       {@value} */
046            private static final String VERSION = "5.8.2.1 (2014/12/13)" ;
047            
048            private static final String AKAMAI_TOKEN_NAME = StringUtil.nval(HybsSystem.sys( "AKAMAI_TOKEN_NAME" ),"akminame");
049            private static final String AKAMAI_ENCRYPTION = StringUtil.nval(HybsSystem.sys( "AKAMAI_ENCRYPTION" ),"enckey");
050            
051    //      private static final URLTokenFactory fact = new URLTokenFactory();
052            private Dictionary token_config;
053    
054    
055            /**
056             * アカマイのト?クンを付けたURLを返します?
057             *
058             *
059             * @return  URL
060             */
061            @Override
062            public String  generateURL( final String inURL, final long time, final String user, final String[] param ){
063                    long wn = ( time - System.currentTimeMillis() ) /1000;
064    //              return fact.generateURL(inURL, null, wn , AKAMAI_SALT, System.currentTimeMillis()); 
065    
066                    token_config = new Hashtable();
067                    token_config.put("token_name", new String( AKAMAI_TOKEN_NAME ));
068                    token_config.put("key", new String( AKAMAI_ENCRYPTION ));
069                    token_config.put("window_seconds", new String( Long.toString( wn ) ));
070                    token_config.put("url", new String( inURL ));
071                    try{
072                            String tkn =  AkamaiToken.generateToken( token_config );
073                            
074                            return tkn;
075                    }
076                    catch( Exception ex ){
077                            ex.printStackTrace();
078                            return inURL;
079                    }
080            }       
081    
082    }