質問編集履歴

2

情報追加

2019/10/05 23:05

投稿

syachiku
syachiku

スコア117

test CHANGED
File without changes
test CHANGED
@@ -132,7 +132,59 @@
132
132
 
133
133
  Object handler, ModelAndView modelAndView) throws Exception {
134
134
 
135
+ if (modelAndView != null && !isRedirectView(modelAndView)) {
136
+
137
+ if (isUserLogged()) {
138
+
135
- //ログインユーザの取得してModelAndViewにセットする処理
139
+ addToModelUserDetails(modelAndView);
140
+
141
+ }
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ public static boolean isRedirectView(ModelAndView mv) {
150
+
151
+ String viewName = mv.getViewName();
152
+
153
+ if (viewName.startsWith("redirect:/")) {
154
+
155
+ return true;
156
+
157
+ }
158
+
159
+ View view = mv.getView();
160
+
161
+ return (view != null && view instanceof SmartView && ((SmartView) view).isRedirectView());
162
+
163
+ }
164
+
165
+
166
+
167
+ public static boolean isUserLogged() {
168
+
169
+ try {
170
+
171
+ return !SecurityContextHolder.getContext().getAuthentication().getName().equals("anonymousUser");
172
+
173
+ } catch (Exception e) {
174
+
175
+ return false;
176
+
177
+ }
178
+
179
+ }
180
+
181
+
182
+
183
+ private void addToModelUserDetails(ModelAndView model) {
184
+
185
+ String loggedUsername = SecurityContextHolder.getContext().getAuthentication().getName();
186
+
187
+ model.addObject("loggedUsername", loggedUsername);
136
188
 
137
189
  }
138
190
 

1

タイトルに情報追加

2019/10/05 23:05

投稿

syachiku
syachiku

スコア117

test CHANGED
@@ -1 +1 @@
1
- Spring boot2でSpringSecurityとInterceptorの設定を行うとstaticフォルダ内のcssにアクセスできなくなる
1
+ Spring boot2でSpringSecurityとInterceptorの設定を行うとstaticフォルダ内のcssやjsにアクセスできなくなる
test CHANGED
File without changes