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 */ 016package org.opengion.plugin.column; 017 018import org.opengion.fukurou.security.HybsCryptography; 019import org.opengion.fukurou.util.StringUtil; 020import org.opengion.hayabusa.db.AbstractDBType; 021 022/** 023 * パスワード情報など、重要な情報のハッシュコード(SHA-1)を扱う為の、カラム属性を定義します。 024 * 025 * パスワード情報など、重要な情報のハッシュコードに、SHA-1 があります。このクラスは、 026 * MessageDigestにより、SHA-1 でハッシュした文字を作成します。 027 * 028 * 値としては、標準の X と同じ半角文字列「 c < 0x20 || c > 0x7e 以外」でのみ 029 * 処理することが出来ます。 030 * 031 * タイプチェックとして、以下の条件を判定します。 032 * ・文字列長は、Byte換算での文字数との比較 033 * ・半角文字列チェック「 c < 0x20 || c > 0x7e 以外」エラー 034 * ・文字パラメータの 正規表現チェック 035 * ・クロスサイトスクリプティングチェック 036 * 037 * @og.group データ属性 038 * 039 * @version 4.0 040 * @author Takahashi Masakazu 041 * @since JDK5.0, 042 */ 043public class DBType_SHA1 extends AbstractDBType { 044 //* このプログラムのVERSION文字列を設定します。 {@value} */ 045 private static final String VERSION = "6.9.7.0 (2018/05/14)" ; 046 047 /** 048 * デフォルトコンストラクター 049 * 050 * @og.rev 6.9.7.0 (2018/05/14) PMD Each class should declare at least one constructor 051 */ 052 public DBType_SHA1() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 053 054 /** 055 * String引数の文字列を+1した文字列を返します。 056 * ※ このクラスでは実装されていません。 057 * 058 * @param value String引数の文字列 059 * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。 060 * 061 * @return String引数の文字列を+1した文字列 062 */ 063 @Override 064 public String valueAdd( final String value ) { 065 final String errMsg = "このメソッドは、このクラスからは使用できません。"; 066 throw new UnsupportedOperationException( errMsg ); 067 } 068 069 /** 070 * MessageDigestにより、SHA-1 でハッシュした文字を返します。 071 * 072 * マイナス時には符号を反転させて、16進数で文字列に変換しています。 073 * よって、このメソッドで変換した文字でのみ突き合わせて正しいかどうかを 074 * 判断してください。 075 * 076 * 077 * @param value (一般に編集データとして登録されたデータ) 078 * 079 * @return 修正後の文字列(一般にデータベースに登録するデータ) 080 */ 081 @Override 082 public String valueSet( final String value ) { 083 return HybsCryptography.getSHA1( StringUtil.rTrim( value ) ); 084 } 085}