1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.mylasta.direction;
17
18 import java.util.List;
19 import java.util.function.Consumer;
20
21 import javax.annotation.Resource;
22
23 import org.codelibs.fess.app.web.base.FessAdminAction;
24 import org.codelibs.fess.mylasta.direction.sponsor.FessActionAdjustmentProvider;
25 import org.codelibs.fess.mylasta.direction.sponsor.FessApiFailureHook;
26 import org.codelibs.fess.mylasta.direction.sponsor.FessCookieResourceProvider;
27 import org.codelibs.fess.mylasta.direction.sponsor.FessCurtainBeforeHook;
28 import org.codelibs.fess.mylasta.direction.sponsor.FessCurtainFinallyHook;
29 import org.codelibs.fess.mylasta.direction.sponsor.FessJsonResourceProvider;
30 import org.codelibs.fess.mylasta.direction.sponsor.FessListedClassificationProvider;
31 import org.codelibs.fess.mylasta.direction.sponsor.FessMailDeliveryDepartmentCreator;
32 import org.codelibs.fess.mylasta.direction.sponsor.FessMultipartRequestHandler;
33 import org.codelibs.fess.mylasta.direction.sponsor.FessSecurityResourceProvider;
34 import org.codelibs.fess.mylasta.direction.sponsor.FessTimeResourceProvider;
35 import org.codelibs.fess.mylasta.direction.sponsor.FessUserLocaleProcessProvider;
36 import org.codelibs.fess.mylasta.direction.sponsor.FessUserTimeZoneProcessProvider;
37 import org.lastaflute.core.direction.CachedFwAssistantDirector;
38 import org.lastaflute.core.direction.FwAssistDirection;
39 import org.lastaflute.core.direction.FwCoreDirection;
40 import org.lastaflute.core.security.InvertibleCryptographer;
41 import org.lastaflute.core.security.OneWayCryptographer;
42 import org.lastaflute.db.dbflute.classification.ListedClassificationProvider;
43 import org.lastaflute.db.direction.FwDbDirection;
44 import org.lastaflute.web.direction.FwWebDirection;
45 import org.lastaflute.web.ruts.process.ActionRuntime;
46 import org.lastaflute.web.ruts.renderer.JspHtmlRenderingProvider;
47
48
49
50
51 public class FessFwAssistantDirector extends CachedFwAssistantDirector {
52
53
54
55
56 @Resource
57 protected FessConfig fessConfig;
58
59
60
61
62 @Override
63 protected void prepareAssistDirection(final FwAssistDirection direction) {
64 direction.directConfig(nameList -> nameList.add("fess_config.properties"), "fess_env.properties");
65 }
66
67
68
69
70 @Override
71 protected void prepareCoreDirection(final FwCoreDirection direction) {
72
73 direction.directDevelopmentHere(fessConfig.isDevelopmentHere());
74
75
76 direction.directLoggingTitle(fessConfig.getDomainTitle(), fessConfig.getEnvironmentTitle());
77
78
79
80 direction.directFrameworkDebug(fessConfig.isFrameworkDebug());
81
82
83 direction.directCurtainBefore(createCurtainBeforeHook());
84 direction.directCurtainFinally(createCurtainFinallyHook());
85
86 direction.directSecurity(createSecurityResourceProvider());
87 direction.directTime(createTimeResourceProvider());
88 direction.directMail(createFessMailDeliveryDepartmentCreator().create());
89 direction.directJson(createJsonResourceProvider());
90 }
91
92 protected FessJsonResourceProvider createJsonResourceProvider() {
93 return new FessJsonResourceProvider();
94 }
95
96 protected FessCurtainBeforeHook createCurtainBeforeHook() {
97 return new FessCurtainBeforeHook();
98 }
99
100 protected FessCurtainFinallyHook createCurtainFinallyHook() {
101 return new FessCurtainFinallyHook();
102 }
103
104 protected FessSecurityResourceProvider createSecurityResourceProvider() {
105 final InvertibleCryptographer inver;
106 final String cipherAlgorism = fessConfig.getAppCipherAlgorism();
107 if ("blowfish".equalsIgnoreCase(cipherAlgorism)) {
108 inver = InvertibleCryptographer.createBlowfishCipher(fessConfig.getAppCipherKey());
109 } else if ("des".equalsIgnoreCase(cipherAlgorism)) {
110 inver = InvertibleCryptographer.createDesCipher(fessConfig.getAppCipherKey());
111 } else if ("rsa".equalsIgnoreCase(cipherAlgorism)) {
112 inver = InvertibleCryptographer.createRsaCipher(fessConfig.getAppCipherKey());
113 } else {
114 inver = InvertibleCryptographer.createAesCipher(fessConfig.getAppCipherKey());
115 }
116
117 final OneWayCryptographer oneWay;
118 final String digestAlgorism = fessConfig.getAppDigestAlgorism();
119 if ("sha512".equalsIgnoreCase(digestAlgorism)) {
120 oneWay = OneWayCryptographer.createSha512Cryptographer();
121 } else if ("md5".equalsIgnoreCase(digestAlgorism)) {
122 oneWay = new OneWayCryptographer("MD5", OneWayCryptographer.ENCODING_UTF8);
123 } else {
124 oneWay = OneWayCryptographer.createSha256Cryptographer();
125 }
126
127 return new FessSecurityResourceProvider(inver, oneWay);
128 }
129
130 protected FessTimeResourceProvider createTimeResourceProvider() {
131 return new FessTimeResourceProvider(fessConfig);
132 }
133
134 protected FessMailDeliveryDepartmentCreator createFessMailDeliveryDepartmentCreator() {
135 return new FessMailDeliveryDepartmentCreator(fessConfig);
136 }
137
138
139
140
141 @Override
142 protected void prepareDbDirection(final FwDbDirection direction) {
143 direction.directClassification(createListedClassificationProvider());
144 }
145
146 protected ListedClassificationProvider createListedClassificationProvider() {
147 return new FessListedClassificationProvider();
148 }
149
150
151
152
153 @Override
154 protected void prepareWebDirection(final FwWebDirection direction) {
155 direction.directRequest(createUserLocaleProcessProvider(), createUserTimeZoneProcessProvider());
156 direction.directCookie(createCookieResourceProvider());
157 direction.directAdjustment(createActionAdjustmentProvider());
158 direction.directMessage(createMessageNameList(), "fess_label");
159 direction.directApiCall(createApiFailureHook());
160 direction.directMultipart(FessMultipartRequestHandler::new);
161 direction.directHtmlRendering(new JspHtmlRenderingProvider() {
162 @Override
163 protected String getShowErrorsForwardPath(final ActionRuntime runtime) {
164 if (FessAdminAction.class.isAssignableFrom(runtime.getActionType())) {
165 return "/admin/error/error.jsp";
166 }
167 return "/error/system.jsp";
168 }
169 });
170 }
171
172 protected Consumer<List<String>> createMessageNameList() {
173 return nameList -> nameList.add("fess_message");
174 }
175
176 protected FessUserLocaleProcessProvider createUserLocaleProcessProvider() {
177 return new FessUserLocaleProcessProvider();
178 }
179
180 protected FessUserTimeZoneProcessProvider createUserTimeZoneProcessProvider() {
181 return new FessUserTimeZoneProcessProvider();
182 }
183
184 protected FessCookieResourceProvider createCookieResourceProvider() {
185 final InvertibleCryptographer cr = InvertibleCryptographer.createAesCipher("*unused@");
186 return new FessCookieResourceProvider(fessConfig, cr);
187 }
188
189 protected FessActionAdjustmentProvider createActionAdjustmentProvider() {
190 return new FessActionAdjustmentProvider();
191 }
192
193 protected FessApiFailureHook createApiFailureHook() {
194 return new FessApiFailureHook();
195 }
196 }