3.304.X (2020-XX-XX)
・G国亡国に伴い JinParser 2.102.2 に対応。
+ ・ログイン管理画面の廃止。
+ ・JinArchiverによるXMLアーカイブファイルのビューア機能。
3.303.106 (2019-05-07)
・必須環境をJavaSE8に引き上げ。
import jp.sfjp.jindolf.summary.VillageDigest;
import jp.sfjp.jindolf.util.GUIUtils;
import jp.sfjp.jindolf.util.StringUtils;
-import jp.sfjp.jindolf.view.AccountPanel;
import jp.sfjp.jindolf.view.ActionManager;
import jp.sfjp.jindolf.view.AvatarPics;
import jp.sfjp.jindolf.view.FilterPanel;
FindPanel findPanel = this.windowManager.getFindPanel();
FilterPanel filterPanel = this.windowManager.getFilterPanel();
LogFrame logFrame = this.windowManager.getLogFrame();
- AccountPanel accountPanel = this.windowManager.getAccountPanel();
HelpFrame helpFrame = this.windowManager.getHelpFrame();
topFrame.setJMenuBar(this.actionManager.getMenuBar());
periodTab.setDialogPref(pref);
optionPanel.getDialogPrefPanel().setDialogPref(pref);
- accountPanel.setModel(this.model);
-
OptionInfo optInfo = this.appSetting.getOptionInfo();
ConfigStore configStore = this.appSetting.getConfigStore();
helpFrame.updateVmInfo(optInfo, configStore);
}
/**
- * アカウント管理画面を表示する。
- */
- private void actionShowAccount(){
- AccountPanel accountPanel = this.windowManager.getAccountPanel();
- toggleWindow(accountPanel);
- return;
- }
-
- /**
* ログ表示画面を表示する。
*/
private void actionShowLog(){
if(cmd == null) return;
switch(cmd){
- case ActionManager.CMD_ACCOUNT:
- actionShowAccount();
- break;
case ActionManager.CMD_OPENXML:
actionOpenXml();
break;
+++ /dev/null
-/*
- * manage authentification info
- *
- * License : The MIT License
- * Copyright(c) 2012 olyutorskii
- */
-
-package jp.sfjp.jindolf.net;
-
-import java.io.UnsupportedEncodingException;
-import java.net.CookieHandler;
-import java.net.CookieManager;
-import java.net.CookieStore;
-import java.net.HttpCookie;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Cookieを用いた人狼BBSサーバとの認証管理を行う。
- *
- * <p>Cookie管理はVM内で共有される。
- *
- * <p>2012-10現在、サポートするのはG国のみ。
- *
- * <p>2012-10より、Cookie "uniqID" の送出も必要になった模様。
- *
- * <p>2020-02現在、認証が必要なHTTP通信は発生しない。
- */
-class AuthManager{
-
- private static final String COOKIE_LOGIN = "login";
- private static final String ENC_POST = StandardCharsets.UTF_8.name();
- private static final String PARAM_REDIR;
-
- /** ログアウト用のPOSTデータ。 */
- static final String POST_LOGOUT;
-
- private static final CookieManager COOKIE_MANAGER;
-
- static{
- PARAM_REDIR = "cgi_param=" + encodeForm4Post("&#bottom");
- POST_LOGOUT = "cmd=logout" + '&' + PARAM_REDIR;
-
- COOKIE_MANAGER = new CookieManager();
- CookieHandler.setDefault(COOKIE_MANAGER);
- }
-
-
- private final URI baseURI;
-
-
- /**
- * コンストラクタ。
- *
- * @param bbsUri 人狼BBSサーバURI
- * @throws NullPointerException 引数がnull
- */
- AuthManager(URI bbsUri){
- Objects.nonNull(bbsUri);
- this.baseURI = bbsUri;
- return;
- }
-
- /**
- * コンストラクタ。
- *
- * @param bbsUrl 人狼BBSサーバURL
- * @throws NullPointerException 引数がnull
- * @throws IllegalArgumentException 不正なURL書式
- */
- AuthManager(URL bbsUrl)
- throws IllegalArgumentException{
- this(urlToUri(bbsUrl));
- return;
- }
-
-
- /**
- * URLからURIへ変換する。
- *
- * <p>書式に関する例外は
- * 非チェック例外{@link IllegalArgumentException}へ変換される。
- *
- * @param url URL
- * @return URI
- * @throws NullPointerException 引数がnull
- * @throws IllegalArgumentException 不正な書式
- */
- private static URI urlToUri(URL url)
- throws IllegalArgumentException{
- Objects.nonNull(url);
-
- URI uri;
- try{
- uri = url.toURI();
- }catch(URISyntaxException e){
- throw new IllegalArgumentException(e);
- }
-
- return uri;
- }
-
- /**
- * 与えられた文字列に対し
- * 「application/x-www-form-urlencoded」符号化を行う。
- *
- * <p>この符号化はHTTPのPOSTメソッドで必要になる。
- * この処理は、一般的なPC用Webブラウザにおける、
- * HTML文書のFORMタグに伴うsubmit処理を模倣する。
- *
- * <p>生成文字列はUS-ASCIIの範疇に収まる。はず。
- *
- * @param formData 元の文字列
- * @return 符号化された文字列
- * @see java.net.URLEncoder
- * @see
- * <a href="http://tools.ietf.org/html/rfc1866#section-8.2.1">
- * RFC1866 8.2.1
- * </a>
- */
- protected static String encodeForm4Post(String formData){
- Objects.nonNull(formData);
-
- String result;
- try{
- result = URLEncoder.encode(formData, ENC_POST);
- }catch(UnsupportedEncodingException e){
- assert false;
- result = null;
- }
-
- return result;
- }
-
- /**
- * 配列版{@link #encodeForm4Post(java.lang.String)}。
- *
- * @param formData 元の文字列
- * @return 符号化された文字列
- * @see #encodeForm4Post(java.lang.String)
- */
- protected static String encodeForm4Post(char[] formData){
- String txt = new String(formData);
- String result = encodeForm4Post(txt);
- return result;
- }
-
- /**
- * ログイン用POSTデータを生成する。
- *
- * @param userID 人狼BBSアカウント名
- * @param password パスワード
- * @return POSTデータ
- */
- public static String buildLoginPostData(String userID, char[] password){
- Objects.nonNull(userID);
- Objects.nonNull(password);
-
- String id = encodeForm4Post(userID);
- String pw = encodeForm4Post(password);
-
- String result = MessageFormat.format(
- "cmd=login&{0}&user_id={1}&password={2}",
- PARAM_REDIR, id, pw
- );
-
- return result;
- }
-
-
- /**
- * このサーバの認証Cookieを取得する。
- *
- * <p>G国での認証Cookie名は"login"。
- *
- * <p>※ 2012-10より"uniqID"も増えた模様だが判定には使わない。
- *
- * @param cookieStore Cookie記憶域
- * @return 認証Cookie。認証された状態に無いときはnull。
- */
- protected HttpCookie getAuthCookie(CookieStore cookieStore){
- List<HttpCookie> cookieList = cookieStore.get(this.baseURI);
- for(HttpCookie cookie : cookieList){
- String cookieName = cookie.getName();
- if(COOKIE_LOGIN.equals(cookieName)) return cookie;
- }
-
- return null;
- }
-
- /**
- * このサーバに現在ログイン中か否か認証状態により判別する。
- *
- * @return ログイン中ならtrue
- */
- boolean hasLoggedIn(){
- assert COOKIE_MANAGER == CookieHandler.getDefault();
- CookieStore cookieStore = COOKIE_MANAGER.getCookieStore();
-
- HttpCookie authCookie = getAuthCookie(cookieStore);
- if(authCookie == null){
- clearAuthentication();
- return false;
- }
-
- return true;
- }
-
- /**
- * このサーバの認証情報をクリアする。
- *
- * <p>以降、BBSサーバへ認証情報は送られなくなる。
- *
- * <p>ログアウトと同じ意味。
- */
- void clearAuthentication(){
- assert COOKIE_MANAGER == CookieHandler.getDefault();
- CookieStore cookieStore = COOKIE_MANAGER.getCookieStore();
-
- HttpCookie authCookie = getAuthCookie(cookieStore);
- if(authCookie != null){
- cookieStore.remove(this.baseURI, authCookie);
- }
-
- return;
- }
-
-}
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.lang.ref.SoftReference;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
*
* <p>画像(40種強)はキャッシュ管理が行われる。
*
- * <p>進行中の村の参加者しか知り得ないHTML要素(赤ログその他)を受信するための
- * 認証情報をCookieで管理する。
- * ※ 2020-02現在、進行中の村は存在しないゆえ、
- * Cookie認証を必要とする国は人狼BBSに存在しない。
+ * <p>※ 2020-02現在、進行中の村は存在しないゆえ、
+ * Cookie認証処理は削除された。
*
* <p>最後にHTTP受信が行われた時刻を保持する。
*/
private static final Object CACHE_LOCK = new Object();
private static final Logger LOGGER = Logger.getAnonymousLogger();
- private static final String ENC_POST = StandardCharsets.UTF_8.name();
static{
IMAGE_CACHE = new HashMap<>();
private final URL baseURL;
- private final AuthManager authManager;
private final Charset charset;
private final boolean isSJIS;
super();
this.baseURL = baseURL;
- this.authManager = new AuthManager(this.baseURL);
this.charset = charset;
String charsetName = this.charset.name();
}
/**
- * 指定された認証情報をPOSTする。
- *
- * <p>ログイン動作を模した物。
- *
- * @param authData 認証情報
- * @return 認証情報が受け入れられたらtrue
- * @throws java.io.IOException ネットワークエラー
- */
- protected boolean postAuthData(String authData) throws IOException{
- URL url = getQueryURL("");
- HttpURLConnection connection =
- (HttpURLConnection) url.openConnection(this.proxy);
- connection.setRequestProperty("Accept", "*/*");
- connection.setRequestProperty("User-Agent", USER_AGENT);
- connection.setUseCaches(false);
- connection.setInstanceFollowRedirects(false);
- connection.setDoInput(true);
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
-
- byte[] authBytes = authData.getBytes(ENC_POST);
-
- try(OutputStream os = TallyOutputStream.getOutputStream(connection)){
- os.write(authBytes);
- os.flush();
- }
-
- updateLastAccess(connection);
-
- connection.disconnect();
-
- if( ! this.authManager.hasLoggedIn() ){
- String logMessage = "認証情報の送信に失敗しました。";
- LOGGER.warning(logMessage);
- return false;
- }
-
- LOGGER.info("正しく認証が行われました。");
-
- return true;
- }
-
- /**
* トップページのHTMLデータを取得する。
*
* @return HTMLデータ
return this.lastServerMs;
}
- /**
- * 与えられたユーザIDとパスワードでログイン処理と認証を行う。
- *
- * <p>すでに認証済みならなにもしない。
- *
- * @param userID ユーザID
- * @param password パスワード
- * @return ログインに成功すればtrue
- * @throws java.io.IOException ネットワークエラー
- */
- public final boolean login(String userID, char[] password)
- throws IOException{
- if(this.authManager.hasLoggedIn()){
- return true;
- }
-
- String postText = AuthManager.buildLoginPostData(userID, password);
- boolean result;
- try{
- result = postAuthData(postText);
- }catch(IOException e){
- this.authManager.clearAuthentication();
- throw e;
- }
-
- return result;
- }
-
- /**
- * ログアウト処理を行う。
- *
- * <p>認証済みでなければなにもしない。
- *
- * @throws java.io.IOException ネットワーク入出力エラー
- */
- public void logout() throws IOException{
- if( ! this.authManager.hasLoggedIn() ){
- return;
- }
-
- try{
- postAuthData(AuthManager.POST_LOGOUT);
- }finally{
- this.authManager.clearAuthentication();
- }
-
- return;
- }
- // TODO シャットダウンフックでログアウトさせようかな…
-
- /**
- * ログイン中か否か認証情報で判定する。
- *
- * @return ログイン中ならtrue
- */
- public boolean hasLoggedIn(){
- boolean result = this.authManager.hasLoggedIn();
- return result;
- }
-
}
+++ /dev/null
-/*
- * Account panel
- *
- * License : The MIT License
- * Copyright(c) 2008 olyutorskii
- */
-
-package jp.sfjp.jindolf.view;
-
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.Frame;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPasswordField;
-import javax.swing.JSeparator;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.border.Border;
-import jp.sfjp.jindolf.VerInfo;
-import jp.sfjp.jindolf.data.Land;
-import jp.sfjp.jindolf.data.LandsTreeModel;
-import jp.sfjp.jindolf.dxchg.TextPopup;
-import jp.sfjp.jindolf.net.ServerAccess;
-import jp.sfjp.jindolf.util.GUIUtils;
-import jp.sfjp.jindolf.util.Monodizer;
-import jp.sourceforge.jindolf.corelib.LandState;
-
-/**
- * ログインパネル。
- */
-@SuppressWarnings("serial")
-public class AccountPanel
- extends JDialog
- implements ActionListener, ItemListener{
-
- private static final Logger LOGGER = Logger.getAnonymousLogger();
-
-
- private final Map<Land, String> landUserIDMap =
- new HashMap<>();
- private final Map<Land, char[]> landPasswordMap =
- new HashMap<>();
-
- private final JComboBox<Land> landBox = new JComboBox<>();
- private final JTextField idField = new JTextField(15);
- private final JPasswordField pwField = new JPasswordField(15);
- private final JButton loginButton = new JButton("ログイン");
- private final JButton logoutButton = new JButton("ログアウト");
- private final JButton closeButton = new JButton("閉じる");
- private final JTextArea status = new JTextArea();
-
- /**
- * アカウントパネルを生成。
- * @param owner フレームオーナー
- */
- @SuppressWarnings("LeakingThisInConstructor")
- public AccountPanel(Frame owner){
- super(owner);
- setModal(true);
-
- GUIUtils.modifyWindowAttributes(this, true, false, true);
-
- this.landBox.setToolTipText("アカウント管理する国を選ぶ");
- this.idField.setToolTipText("IDを入力してください");
- this.pwField.setToolTipText("パスワードを入力してください");
-
- Monodizer.monodize(this.idField);
- Monodizer.monodize(this.pwField);
-
- this.idField.setMargin(new Insets(1, 4, 1, 4));
- this.pwField.setMargin(new Insets(1, 4, 1, 4));
-
- this.idField.setComponentPopupMenu(new TextPopup());
-
- this.landBox.setEditable(false);
- this.landBox.addItemListener(this);
-
- this.status.setEditable(false);
- this.status.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- this.status.setRows(2);
- this.status.setLineWrap(true);
-
- this.loginButton.addActionListener(this);
- this.logoutButton.addActionListener(this);
- this.closeButton.addActionListener(this);
-
- getRootPane().setDefaultButton(this.loginButton);
-
- Container content = getContentPane();
- GridBagLayout layout = new GridBagLayout();
- GridBagConstraints constraints = new GridBagConstraints();
- content.setLayout(layout);
-
- constraints.gridwidth = GridBagConstraints.REMAINDER;
- constraints.weightx = 1.0;
- constraints.insets = new Insets(5, 5, 5, 5);
-
- JComponent accountPanel = createCredential();
- JComponent buttonPanel = createButtonPanel();
-
- constraints.weighty = 0.0;
- constraints.fill = GridBagConstraints.HORIZONTAL;
- content.add(accountPanel, constraints);
-
- Border border = BorderFactory.createTitledBorder("ログインステータス");
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- panel.add(this.status, BorderLayout.CENTER);
- panel.setBorder(border);
-
- constraints.weighty = 1.0;
- constraints.fill = GridBagConstraints.BOTH;
- content.add(panel, constraints);
-
- constraints.weighty = 0.0;
- constraints.fill = GridBagConstraints.HORIZONTAL;
- content.add(new JSeparator(), constraints);
-
- content.add(buttonPanel, constraints);
-
- return;
- }
-
- /**
- * 認証パネルを生成する。
- * @return 認証パネル
- */
- private JComponent createCredential(){
- JPanel credential = new JPanel();
-
- GridBagLayout layout = new GridBagLayout();
- GridBagConstraints constraints = new GridBagConstraints();
-
- credential.setLayout(layout);
-
- constraints.insets = new Insets(5, 5, 5, 5);
- constraints.fill = GridBagConstraints.NONE;
-
- constraints.anchor = GridBagConstraints.EAST;
- credential.add(new JLabel("国名 :"), constraints);
- constraints.anchor = GridBagConstraints.WEST;
- credential.add(this.landBox, constraints);
-
- constraints.gridy = 1;
- constraints.anchor = GridBagConstraints.EAST;
- constraints.weightx = 0.0;
- constraints.fill = GridBagConstraints.NONE;
- credential.add(new JLabel("ID :"), constraints);
- constraints.anchor = GridBagConstraints.WEST;
- constraints.weightx = 1.0;
- constraints.fill = GridBagConstraints.HORIZONTAL;
- credential.add(this.idField, constraints);
-
- constraints.gridy = 2;
- constraints.anchor = GridBagConstraints.EAST;
- constraints.weightx = 0.0;
- constraints.fill = GridBagConstraints.NONE;
- credential.add(new JLabel("パスワード :"), constraints);
- constraints.anchor = GridBagConstraints.WEST;
- constraints.weightx = 1.0;
- constraints.fill = GridBagConstraints.HORIZONTAL;
- credential.add(this.pwField, constraints);
-
- return credential;
- }
-
- /**
- * ボタンパネルの作成。
- * @return ボタンパネル
- */
- private JComponent createButtonPanel(){
- JPanel buttonPanel = new JPanel();
-
- GridBagLayout layout = new GridBagLayout();
- GridBagConstraints constraints = new GridBagConstraints();
-
- buttonPanel.setLayout(layout);
-
- constraints.fill = GridBagConstraints.NONE;
- constraints.anchor = GridBagConstraints.WEST;
- constraints.weightx = 0.0;
- constraints.weighty = 0.0;
-
- buttonPanel.add(this.loginButton, constraints);
-
- constraints.insets = new Insets(0, 5, 0, 0);
- buttonPanel.add(this.logoutButton, constraints);
-
- constraints.anchor = GridBagConstraints.EAST;
- constraints.weightx = 1.0;
- constraints.insets = new Insets(0, 15, 0, 0);
- buttonPanel.add(this.closeButton, constraints);
-
- return buttonPanel;
- }
-
- /**
- * 現在コンボボックスで選択中の国を返す。
- * @return 現在選択中のLand
- */
- private Land getSelectedLand(){
- Land land = (Land) ( this.landBox.getSelectedItem() );
- return land;
- }
-
- /**
- * ACTIVEな最初の国がコンボボックスで既に選択されている状態にする。
- */
- private void preSelectActiveLand(){
- for(int index = 0; index < this.landBox.getItemCount(); index++){
- Object item = this.landBox.getItemAt(index);
- Land land = (Land) item;
- LandState state = land.getLandDef().getLandState();
- if(state == LandState.ACTIVE){
- this.landBox.setSelectedItem(land);
- return;
- }
- }
- return;
- }
-
- /**
- * 指定された国のユーザIDを返す。
- * @param land 国
- * @return ユーザID
- */
- private String getUserID(Land land){
- return this.landUserIDMap.get(land);
- }
-
- /**
- * 指定された国のパスワードを返す。
- * @param land 国
- * @return パスワード
- */
- private char[] getPassword(Land land){
- return this.landPasswordMap.get(land);
- }
-
- /**
- * ネットワークエラーを通知するモーダルダイアログを表示する。
- * OKボタンを押すまでこのメソッドは戻ってこない。
- * @param e ネットワークエラー
- */
- protected void showNetworkError(IOException e){
- LOGGER.log(Level.WARNING,
- "アカウント処理中にネットワークのトラブルが発生しました", e);
-
- Land land = getSelectedLand();
- ServerAccess server = land.getServerAccess();
- String message =
- land.getLandDef().getLandName()
- +"を運営するサーバとの間の通信で"
- +"何らかのトラブルが発生しました。\n"
- +"相手サーバのURLは [ " + server.getBaseURL() + " ] だよ。\n"
- +"Webブラウザでも遊べないか確認してみてね!\n";
-
- JOptionPane pane = new JOptionPane(message,
- JOptionPane.WARNING_MESSAGE,
- JOptionPane.DEFAULT_OPTION );
-
- String title = VerInfo.getFrameTitle("通信異常発生");
- JDialog dialog = pane.createDialog(this, title);
-
- dialog.pack();
- dialog.setVisible(true);
- dialog.dispose();
-
- return;
- }
-
- /**
- * アカウントエラーを通知するモーダルダイアログを表示する。
- * OKボタンを押すまでこのメソッドは戻ってこない。
- */
- protected void showIllegalAccountDialog(){
- Land land = getSelectedLand();
- String message =
- land.getLandDef().getLandName()
- +"へのログインに失敗しました。\n"
- +"ユーザ名とパスワードは本当に正しいかな?\n"
- +"あなたは本当に [ " + getUserID(land) + " ] さんかな?\n"
- +"WebブラウザによるID登録手続きは本当に完了してるかな?\n"
- +"Webブラウザでもログインできないか試してみて!\n"
- +"…ユーザ名やパスワードにある種の特殊文字を使っている人は"
- +"問題があるかも。";
-
- JOptionPane pane = new JOptionPane(message,
- JOptionPane.WARNING_MESSAGE,
- JOptionPane.DEFAULT_OPTION );
-
- String title = VerInfo.getFrameTitle("ログイン認証失敗");
- JDialog dialog = pane.createDialog(this, title);
-
- dialog.pack();
- dialog.setVisible(true);
- dialog.dispose();
-
- return;
- }
-
- /**
- * 入力されたアカウント情報を基に現在選択中の国へログインする。
- * @return ログインに成功すればtrueを返す。
- */
- protected boolean login(){
- Land land = getSelectedLand();
- ServerAccess server = land.getServerAccess();
-
- String id = this.idField.getText();
- char[] password = this.pwField.getPassword();
- this.landUserIDMap.put(land, id);
- this.landPasswordMap.put(land, password);
-
- boolean result = false;
- try{
- result = server.login(id, password);
- }catch(IOException e){
- showNetworkError(e);
- return false;
- }
-
- if( ! result ){
- showIllegalAccountDialog();
- }
-
- return result;
- }
-
- /**
- * 現在選択中の国からログアウトする。
- */
- protected void logout(){
- try{
- logoutInternal();
- }catch(IOException e){
- showNetworkError(e);
- }
- return;
- }
-
- /**
- * 現在選択中の国からログアウトする。
- * @throws java.io.IOException ネットワークエラー
- */
- protected void logoutInternal() throws IOException{
- Land land = getSelectedLand();
- ServerAccess server = land.getServerAccess();
- server.logout();
- return;
- }
-
- /**
- * 現在選択中の国のログイン状態に合わせてGUIを更新する。
- */
- private void updateGUI(){
- Land land = getSelectedLand();
- if(land == null) return;
-
- LandState state = land.getLandDef().getLandState();
- ServerAccess server = land.getServerAccess();
- boolean hasLoggedIn = server.hasLoggedIn();
-
- if(state != LandState.ACTIVE){
- this.status.setText(
- "この国は既に募集を停止しました。\n"
- +"ログインは無意味です" );
- this.idField.setEnabled(false);
- this.pwField.setEnabled(false);
- this.loginButton.setEnabled(false);
- this.logoutButton.setEnabled(false);
- }else if(hasLoggedIn){
- this.status.setText("ユーザ [ " + getUserID(land) + " ] として\n"
- +"現在ログイン中です");
- this.idField.setEnabled(false);
- this.pwField.setEnabled(false);
- this.loginButton.setEnabled(false);
- this.logoutButton.setEnabled(true);
- }else{
- this.status.setText("現在ログインしていません");
- this.idField.setEnabled(true);
- this.pwField.setEnabled(true);
- this.loginButton.setEnabled(true);
- this.logoutButton.setEnabled(false);
- }
-
- return;
- }
-
- /**
- * 国情報を設定する。
- * @param model 国情報
- * @throws NullPointerException 引数がnull
- */
- public void setModel(LandsTreeModel model) throws NullPointerException{
- if(model == null) throw new NullPointerException();
-
- this.landUserIDMap.clear();
- this.landPasswordMap.clear();
- this.landBox.removeAllItems();
-
- for(Land land : model.getLandList()){
- String userID = "";
- char[] password = {};
- this.landUserIDMap.put(land, userID);
- this.landPasswordMap.put(land, password);
- this.landBox.addItem(land);
- }
-
- preSelectActiveLand();
- updateGUI();
-
- return;
- }
-
- /**
- * {@inheritDoc}
- * ボタン操作のリスナ。
- * @param event イベント {@inheritDoc}
- */
- // TODO Return キー押下によるログインもサポートしたい
- @Override
- public void actionPerformed(ActionEvent event){
- Object source = event.getSource();
-
- if(source == this.closeButton){
- setVisible(false);
- dispose();
- return;
- }
-
- if(source == this.loginButton){
- login();
- }else if(source == this.logoutButton){
- logout();
- }
-
- updateGUI();
-
- return;
- }
-
- /**
- * {@inheritDoc}
- * コンボボックス操作のリスナ。
- * @param event イベント {@inheritDoc}
- */
- @Override
- public void itemStateChanged(ItemEvent event){
- Object source = event.getSource();
- if(source != this.landBox) return;
-
- Land land = (Land) event.getItem();
- String id;
- char[] password;
-
- switch(event.getStateChange()){
- case ItemEvent.SELECTED:
- id = getUserID(land);
- password = getPassword(land);
- this.idField.setText(id);
- this.pwField.setText(new String(password));
- updateGUI();
- break;
- case ItemEvent.DESELECTED:
- id = this.idField.getText();
- password = this.pwField.getPassword();
- this.landUserIDMap.put(land, id);
- this.landPasswordMap.put(land, password);
- break;
- default:
- assert false;
- return;
- }
-
- return;
- }
-
- // TODO IDかパスワードが空の場合はログインボタンを無効にしたい
-}
public class ActionManager{
/** アクション{@value}。 */
- public static final String CMD_ACCOUNT = "ACCOUNT";
- /** アクション{@value}。 */
public static final String CMD_OPENXML = "OPENXML";
/** アクション{@value}。 */
public static final String CMD_EXIT = "EXIT";
* setup menu items.
*/
private void setupMenuItems(){
- buildMenuItem(CMD_ACCOUNT, "アカウント管理", KeyEvent.VK_M);
buildMenuItem(CMD_OPENXML, "XMLを読み込む", KeyEvent.VK_O);
buildMenuItem(CMD_EXIT, "終了", KeyEvent.VK_X);
buildMenuItem(CMD_COPY, "選択範囲をコピー", KeyEvent.VK_C);
* @return メニューバー
*/
private JMenuBar buildMenuBar(){
- this.menuFile.add(getMenuItem(CMD_ACCOUNT));
this.menuFile.add(getMenuItem(CMD_OPENXML));
this.menuFile.addSeparator();
this.menuFile.add(getMenuItem(CMD_EXIT));
getFrameTitle("オプション設定");
private static final String TITLE_FIND =
getFrameTitle("発言検索");
- private static final String TITLE_ACCOUNT =
- getFrameTitle("アカウント管理");
private static final String TITLE_DIGEST =
getFrameTitle("村のダイジェスト");
private static final String TITLE_DAYSUMMARY =
private TalkPreview talkPreview;
private OptionPanel optionPanel;
private FindPanel findPanel;
- private AccountPanel accountPanel;
private VillageDigest villageDigest;
private DaySummary daySummary;
private HelpFrame helpFrame;
}
/**
- * ログインウィンドウを生成する。
- * @return ログインウィンドウ
- */
- protected AccountPanel createAccountPanel(){
- AccountPanel result;
-
- result = new AccountPanel(NULLPARENT);
- result.setTitle(TITLE_ACCOUNT);
- result.pack();
- result.setVisible(false);
-
- this.windowSet.add(result);
-
- return result;
- }
-
- /**
- * ログインウィンドウを返す。
- * @return ログインウィンドウ
- */
- public AccountPanel getAccountPanel(){
- if(this.accountPanel == null){
- this.accountPanel = createAccountPanel();
- }
- return this.accountPanel;
- }
-
- /**
* 村ダイジェストウィンドウを生成する。
* @return 村ダイジェストウィンドウ
*/
if(this.filterPanel != null) this.filterPanel.pack();
if(this.findPanel != null) this.findPanel.pack();
- if(this.accountPanel != null) this.accountPanel.pack();
return;
}
+++ /dev/null
-/*
- */
-
-package jp.sfjp.jindolf.net;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class AuthManagerTest {
-
- public AuthManagerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- /**
- * Test of encodeForm4Post method, of class AuthManager.
- */
- @Test
- public void testEncodeForm4Post_String() {
- System.out.println("encodeForm4Post");
-
- String result;
-
- result = AuthManager.encodeForm4Post("");
- assertEquals("", result);
-
- result = AuthManager.encodeForm4Post("abc");
- assertEquals("abc", result);
-
- result = AuthManager.encodeForm4Post("a c");
- assertEquals("a+c", result);
-
- result = AuthManager.encodeForm4Post("a\nc");
- assertEquals("a%0Ac", result);
-
- result = AuthManager.encodeForm4Post("a%c");
- assertEquals("a%25c", result);
-
- result = AuthManager.encodeForm4Post("a=c");
- assertEquals("a%3Dc", result);
-
- result = AuthManager.encodeForm4Post("a?c");
- assertEquals("a%3Fc", result);
-
- result = AuthManager.encodeForm4Post("a&c");
- assertEquals("a%26c", result);
-
- result = AuthManager.encodeForm4Post("a;c");
- assertEquals("a%3Bc", result);
-
- result = AuthManager.encodeForm4Post("a漢c");
- assertEquals("a%E6%BC%A2c", result);
-
- return;
- }
-
- /**
- * Test of encodeForm4Post method, of class AuthManager.
- */
- @Test
- public void testEncodeForm4Post_charArr() {
- System.out.println("encodeForm4Post");
-
- String result;
-
- result = AuthManager.encodeForm4Post(new char[]{});
- assertEquals("", result);
-
- result = AuthManager.encodeForm4Post(new char[]{'a', 'b', 'c'});
- assertEquals("abc", result);
-
- result = AuthManager.encodeForm4Post(new char[]{'a', ' ', 'c'});
- assertEquals("a+c", result);
-
- return;
- }
-
- /**
- * Test of buildLoginPostData method, of class AuthManager.
- */
- @Test
- public void testBuildLoginPostData() {
- System.out.println("buildLoginPostData");
-
- String result;
-
- result = AuthManager.buildLoginPostData("abc", new char[]{'x', 'y', 'z'});
- assertEquals("cmd=login&cgi_param=%26%23bottom&user_id=abc&password=xyz", result);
-
- result = AuthManager.buildLoginPostData("a c", new char[]{'x', ' ', 'z'});
- assertEquals("cmd=login&cgi_param=%26%23bottom&user_id=a+c&password=x+z", result);
-
- return;
- }
-
-}