##### Coverage Report - jp.co.y_net.amm.page.TopPage

Classes in this File | Line Coverage | Branch Coverage | Complexity

TopPage

0% | 0/22

N/A | N/A

0.0;0

TopPage$1

0% | 0/3

N/A | N/A

0.0;0

TopPage$2

0% | 0/18

0% | 0/4

0.0;0

TopPage$3

0% | 0/11

0% | 0/4

0.0;0

TopPage$3$1

0% | 0/3

0% | 0/4

0.0;0

TopPage$3$2

0% | 0/6

N/A | N/A

0.0;0

TopPage$4

0% | 0/7

N/A | N/A

0.0;0

1

0

     package jp.co.y_net.amm.page;

2

3

     import java.io.File;

4

     import java.io.FilenameFilter;

5

     import java.util.ArrayList;

6

     import java.util.Collections;

7

     import java.util.Comparator;

8

     import java.util.List;

9

10

     import jp.co.y_net.amm.AppSession;

11

     import jp.co.y_net.amm.dao.Usr;

12

     import jp.co.y_net.amm.service.Logincheck;

13

     import jp.co.y_net.amm.service.Logincheck.LogincheckResult;

14

15

     import org.apache.wicket.markup.html.WebMarkupContainer;

16

     import org.apache.wicket.markup.html.basic.Label;

17

     import org.apache.wicket.markup.html.form.Button;

18

     import org.apache.wicket.markup.html.form.Form;

19

     import org.apache.wicket.markup.html.form.TextField;

20

     import org.apache.wicket.markup.html.link.DownloadLink;

21

     import org.apache.wicket.markup.html.list.ListItem;

22

     import org.apache.wicket.markup.html.list.PageableListView;

23

     import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;

24

     import org.apache.wicket.markup.html.panel.FeedbackPanel;

25

     import org.apache.wicket.model.IModel;

26

     import org.apache.wicket.model.LoadableDetachableModel;

27

     import org.apache.wicket.model.Model;

28

29

     /**

30

      * トップページ

31

      * @author k_inaba

32

      */

33

     public class TopPage extends CommonFrameA {

34

             private static final long serialVersionUID = 1L;

35

36

0

         public TopPage() {

37

38

             /* フィードバックパネル */

39

0

             final WebMarkupContainer fbPanel = new FeedbackPanel("feedback");

40

0

             add(fbPanel);

41

42

             /* ログインフォーム領域 ------------------------------------------------------------------------------------- */

43

0

             WebMarkupContainer divLogin = new WebMarkupContainer("divLogin") {

44

                 @Override

45

                 public boolean isVisible() {

46

                     //return AppSession.isLogin() == false;

47

0

                     return true;

48

                 }

49

             };

50

0

             add(divLogin);

51

52

53

0

             final Model<String> modelChallengestringA = Model.of(challengestring.execute());

54

0

             final TextField<String> textChallenge = new TextField<String>("textChallenge", modelChallengestringA);

55

0

             final TextField<String> textLoginId = new TextField<String>("textLoginId", Model.of(""));

56

     //        if(AppLogger.isDebug()) {

57

     //            textLoginId.setModelObject("ryoma.sakamoto@example.com");

58

     //        }

59

             //final PasswordTextField textPassword = new PasswordTextField("textPassword", Model.of(""));

60

             //textPassword.setResetPassword(false); // かんたんログイン時の初期入力を許可する

61

     //        final TextField<String> textPassword = new TextField<String>("textPassword", Model.of(""));

62

0

             final TextField<String> textChallengeResponse = new TextField<String>("textChallengeResponse", Model.of(""));

63

     //        final CheckBox eazy = new CheckBox("eazy", Model.of(false));

64

     //        /* かんたんログインによる入力値補完 */

65

     //        if("true".equals(getCookie("eazy"))) {

66

     //            textLoginId.setModelObject(getCookie("uid"));

67

     //            textPassword.setModelObject(getCookie("pass"));

68

     //            eazy.setModelObject(true);

69

     //        }

70

71

             /* ログイン */

72

0

             Button btnLogin = new Button("btnLogin");

73

     //        btnLogin.add(new AttributeModifier("onclick", "return eventLogin(true)"));

74

75

0

             Form<Void> form =new Form<Void>("form") {

76

                 @Override

77

                 public boolean isVisible() {

78

                     //return AppSession.isLogin() == false;

79

0

                     return true;

80

                 }

81

                 @Override

82

                 public void onSubmit() {

83

                     /* ログイン処理 */

84

85

0

                     String challengestringA = modelChallengestringA.getObject();

86

0

                     String loginidB = textLoginId.getValue();

87

0

                     String cresE = textChallengeResponse.getValue();

88

89

90

                     /* ------------------------ */

91

92

                     //Integer checkresult = logincheck.executeFromAmm(loginidB, cresE, challengestringA);

93

0

                     LogincheckResult checkresult = logincheck.executeFromApi(loginidB, cresE, challengestringA); // ここではAPI呼び出しと同等にする

94

95

96

0

                     if(0 == checkresult.errorCode) {

97

                         /* 認証成功 */

98

99

                         /* セッションへ登録 */

100

0

                         Usr usr = usrDao.getByLoginid(loginidB);

101

0

                         AppSession.get().setLoginUser(usr);

102

103

     //                  /* かんたんログイン */

104

     //                  if(eazy.getModelObject()) {

105

     //                      int time = 60 * 60 * 24 * 10; // 10日間保存

106

     //                      addCookie("uid", textLoginId.getModelObject(), time);

107

     //                      addCookie("pass", textPassword.getModelObject(), time);

108

     //                      addCookie("eazy", eazy.getModelObject() ? "true" : "false", time);

109

     //                  }

110

111

                         /* jsessionidの変更（セッション固定化攻撃対策）*/

112

0

                         AppSession.get().replaceSession();

113

114

0

                         if(AppSession.get().returnPageClass != null) {

115

                             /* 呼び出し元が設定されている場合 */

116

0

                             setResponsePage(AppSession.get().returnPageClass, AppSession.get().returnPageParameters);

117

0

                         } else {

118

                             /* 呼び出し元が設定されていない場合 */

119

0

                             setResponsePage(getApplication().getHomePage());

120

                         }

121

122

0

                     } else {

123

     //                    error("メールアドレスかパスワードが間違っています。");

124

     //                    setResponsePage(getPageClass());

125

0

                         error(Logincheck.errorMemo.get(checkresult.errorCode) + "/" + Logincheck.errorMessage.get(checkresult.errorCode) );

126

                     }

127

0

                 }

128

             };

129

0

             divLogin.add(form);

130

0

             form.add(textChallenge);

131

0

             form.add(textLoginId);

132

0

             form.add(textChallengeResponse);

133

     //        form.add(eazy);

134

0

             form.add(btnLogin);

135

136

     //        /* お知らせ領域 */

137

     //        List<Infomation> infos = readInfo();

138

     //        final ListView<Infomation> listInfo = new PageableListView<Infomation>("listInfo", infos, 20) {

139

     //            private static final long serialVersionUID = 1L;

140

     //

141

     //            @Override

142

     //            protected void populateItem(ListItem<Infomation> item) {

143

     //                Infomation info = item.getModelObject();

144

     //                item.add(new Label("infoDate", info.getInfoDateFormat()));

145

     //

146

     //                //item.add(new Label("infoCont", info.getTitleFormat()));

147

     //                WebMarkupContainer infoCont = new WebMarkupContainer("infoCont");

148

     //                item.add(infoCont);

149

     //

150

     //                PageParameters params = new PageParameters();

151

     //                params.set("pid", "1");

152

     //                BookmarkablePageLink<InfoPage> link = new BookmarkablePageLink<InfoPage>("link", InfoPage.class, params);

153

     //                link.add(new Label("label", info.getTitleFormat()));

154

     //                infoCont.add(link);

155

     //

156

     //            }

157

     //        };

158

     //        add(listInfo);

159

160

161

             /* ログ取得 */

162

0

             final IModel<List<File>> logs = new LoadableDetachableModel<List<File>>() {

163

                 @Override

164

                 protected List<File> load() {

165

0

                     File dir = new File(System.getProperty("catalina.base"), "logs");

166

0

                     if(dir.exists() == false) {

167

0

                         return new ArrayList<File>();

168

                     }

169

0

                     File[] aryLogs = dir.listFiles(new FilenameFilter() {

170

                         @Override

171

                         public boolean accept(File dir, String name) {

172

0

                             return (name.startsWith("AMMLog") && name.endsWith(".log"));

173

                         }

174

                     });

175

0

                     List<File> logs = new ArrayList<File>();

176

0

                     for(File l: aryLogs) {

177

0

                         logs.add(l);

178

                     }

179

0

                     Collections.sort(logs, new Comparator<File>() {

180

                         @Override

181

                         public int compare(File o1, File o2) {

182

0

                             return Long.valueOf(o1.lastModified())

183

0

                                     .compareTo(

184

0

                                             Long.valueOf(o2.lastModified())

185

0

                                             ) * -1;

186

                         }

187

                     });

188

0

                     return logs;

189

                 }

190

             };

191

0

             final PageableListView<File> listview = new PageableListView<File>("lvLog", logs, 5) {

192

                 private static final long serialVersionUID = 1L;

193

                 @Override

194

                 protected void populateItem(ListItem<File> item) {

195

0

                     File log = item.getModelObject();

196

197

0

                     DownloadLink lnkLog = new DownloadLink("lnkLog", log);

198

199

0

                     lnkLog.add(new Label("log", log.getAbsolutePath()));

200

0

                     item.add(lnkLog);

201

0

                 }

202

             };

203

     //        listview.setReuseItems(true);

204

0

             add(listview);

205

0

             PagingNavigator navigator = new PagingNavigator("paging", listview);

206

0

             add(navigator);

207

208

0

         }

209

210

     }