LoginSignup
4
4

More than 5 years have passed since last update.

WindowsでJavaセキュリティ例外サイトを追加するスクリプト

Last updated at Posted at 2015-02-26

javaのセキュリティ例外リストにサイトを追加する

概要

Javaのセキュリティ要件がどんどん厳しくなってきています。
テスト環境では正式な署名したりしないので、例外サイトに登録してしまう事も多いと思います。

今回は例として以下のサイトを追加するバッチを、DOSバッチとPowerShellで作成してみます。

 http://sample1.com/
 https://sample2.com/

といっても、単純に以下のファイルにURLを追加するだけです。
Vista以降
%APPDATA%..\LocalLow\sun\Java\Deployment\Security\exception.sites
XP
%APPDATA%\sun\Java\Deployment\Security\exception.sites

ただし、最低限の汎用性を持たせるために、以下の条件を実装しました。
* 既存の登録済サイトは残したまま登録対象を追加する
* 登録対象が既に追加されていた場合は2重登録しないようにする

DOSバッチ

DOS-Batch
SETLOCAL ENABLEDELAYEDEXPANSION

REM SET EX_PATH="%APPDATA%\sun\Java\Deployment\Security\exception.sites"
SET EX_PATH="%APPDATA%\..\LocalLow\sun\Java\Deployment\Security\exception.sites"

REM ここで登録するサイトをリストアップ
SET EX_SITE[0]=http://sample1.com/
SET EX_SITE[1]=https://sample2.com/

REM         ↓終了インデックスは登録数に合わせる
FOR /L %%i IN (0,1,1) DO (
    FINDSTR !EX_SITE[%%i]! %EX_PATH%
  IF ERRORLEVEL 1 ECHO !EX_SITE[%%i]!>> %EX_PATH%
)

PowerShell

デフォルトのセキュリティ設定ではスクリプトファイル*.ps1が実行できないので要注意。

PowerShell
# file path
#$ex_path = "$env:APPDATA\Sun\Java\Deployment\security\exception.sites"
$ex_path = "$env:APPDATA\..\LocalLow\Sun\Java\Deployment\security\exception.sites"

# target site
$ex_sites = @("http://www.example1.com/","https://www.example2.com/")

foreach($ex_site in $ex_sites){
  if( -Not(Select-String $ex_site $ex_path -quiet) ){
    Add-Content $ex_path "$ex_site"
  }
}
echo "例外サイト追加しました"
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4