Browse Source

making LoginAssist, not complete yet, only create base environment

jflute 10 years ago
parent
commit
d045fe7984

+ 3 - 26
pom.xml

@@ -38,8 +38,8 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
 		<!-- Main Framework -->
-		<dbflute.version>1.1.0-sp7</dbflute.version>
-		<lastaflute.version>0.6.3-H-SNAPSHOT</lastaflute.version>
+		<dbflute.version>1.1.0-sp8-RC1</dbflute.version>
+		<lastaflute.version>0.6.1-RC5</lastaflute.version>
 		<lasta.taglib.version>0.6.0</lasta.taglib.version>
 		<servlet.version>3.1.0</servlet.version>
 		<jsp.version>2.3.1</jsp.version>
@@ -53,8 +53,7 @@
 
 		<!-- Testing -->
 		<junit.version>4.8.2</junit.version>
-		<utflute.version>0.5.0-sp8-RC1</utflute.version>
-		<jetty.boot.version>0.3.2</jetty.boot.version>
+		<utflute.version>0.5.0-sp8-RC3</utflute.version>
 
 		<!-- S2Robot -->
 		<s2robot.version>1.0.0-SNAPSHOT</s2robot.version>
@@ -630,27 +629,5 @@
 			<version>3.1</version>
 			<scope>test</scope>
 		</dependency>
-		<dependency>
-			<groupId>org.dbflute.jetty</groupId>
-			<artifactId>jetty-boot</artifactId>
-			<version>${jetty.boot.version}</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.eclipse.jetty</groupId> <!-- jetty-all does not contain JSP -->
-			<artifactId>jetty-jsp</artifactId>
-			<version>9.2.10.v20150310</version>
-			<scope>provided</scope>
-			<exclusions>
-				<exclusion> <!-- jstl already exists -->
-					<groupId>org.eclipse.jetty.orbit</groupId>
-					<artifactId>javax.servlet.jsp.jstl</artifactId>
-				</exclusion>
-				<exclusion>
-					<groupId>org.glassfish.web</groupId>
-					<artifactId>javax.servlet.jsp.jstl</artifactId>
-				</exclusion>
-			</exclusions>
-		</dependency>
 	</dependencies>
 </project>

+ 21 - 17
src/main/java/org/codelibs/fess/app/web/base/FessBaseAction.java

@@ -31,17 +31,18 @@
  */
 package org.codelibs.fess.app.web.base;
 
+import javax.annotation.Resource;
+
+import org.codelibs.fess.app.web.base.login.FessLoginAssist;
 import org.codelibs.fess.mylasta.action.FessHtmlPath;
 import org.codelibs.fess.mylasta.action.FessMessages;
+import org.codelibs.fess.mylasta.action.FessUserBean;
 import org.dbflute.hook.AccessContext;
-import org.dbflute.optional.OptionalObject;
 import org.dbflute.optional.OptionalThing;
 import org.lastaflute.db.dbflute.accesscontext.AccessContextArranger;
-import org.lastaflute.db.dbflute.accesscontext.AccessContextResource;
 import org.lastaflute.web.TypicalAction;
 import org.lastaflute.web.callback.ActionRuntime;
 import org.lastaflute.web.login.LoginManager;
-import org.lastaflute.web.login.UserBean;
 import org.lastaflute.web.response.ActionResponse;
 import org.lastaflute.web.validation.ActionValidator;
 import org.lastaflute.web.validation.LaValidatable;
@@ -58,6 +59,15 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
     /** The application type for FESs, e.g. used by access context. */
     protected static final String APP_TYPE = "FES"; // #change_it_first
 
+    /** The user type for Admin, e.g. used by access context. */
+    protected static final String USER_TYPE = "A";
+
+    // ===================================================================================
+    //                                                                           Attribute
+    //                                                                           =========
+    @Resource
+    private FessLoginAssist fessLoginAssist;
+
     // ===================================================================================
     //                                                                               Hook
     //                                                                              ======
@@ -94,30 +104,22 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
     //                                                                      ==============
     @Override
     protected AccessContextArranger newAccessContextArranger() { // for framework
+        // fess does not use DBFlute, and this is unneeded so dummy 
         return resource -> {
             final AccessContext context = new AccessContext();
             context.setAccessLocalDateTimeProvider(() -> currentDateTime());
-            context.setAccessUserProvider(() -> buildAccessUserTrace(resource));
+            context.setAccessUserProvider(() -> "unused");
             return context;
         };
     }
 
-    private String buildAccessUserTrace(AccessContextResource resource) {
-        // #app_customize you can customize the user trace for common column
-        final StringBuilder sb = new StringBuilder();
-        sb.append(myUserType().map(userType -> userType + ":").orElse(""));
-        sb.append(getUserBean().map(bean -> bean.getUserId()).orElseGet(() -> -1L));
-        sb.append(",").append(myAppType()).append(",").append(resource.getModuleName());
-        final String trace = sb.toString();
-        final int columnSize = 200;
-        return trace.length() > columnSize ? trace.substring(0, columnSize) : trace;
-    }
-
     // ===================================================================================
     //                                                                           User Info
     //                                                                           =========
     @Override
-    protected OptionalThing<UserBean> getUserBean() { // to return as concrete class
+    protected OptionalThing<FessUserBean> getUserBean() { // to return as concrete class
+        // #login waiting
+        //return fessLoginAssist.getSessionUserBean();
         return OptionalThing.empty();// uses application server authentication so empty here
     }
 
@@ -128,11 +130,13 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
 
     @Override
     protected OptionalThing<String> myUserType() { // for framework
-        return OptionalObject.empty(); // same reason as getUserBean()
+        return OptionalThing.of(USER_TYPE); // same reason as getUserBean()
     }
 
     @Override
     protected OptionalThing<LoginManager> myLoginManager() {
+        // #login waiting
+        //return OptionalThing.of(fessLoginAssist);
         return OptionalThing.empty(); // same reason as getUserBean()
     }
 

+ 118 - 0
src/main/java/org/codelibs/fess/app/web/base/login/FessLoginAssist.java

@@ -0,0 +1,118 @@
+/*
+ * Copyright 2012 the CodeLibs Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.codelibs.fess.app.web.base.login;
+
+import javax.annotation.Resource;
+
+import org.codelibs.fess.app.web.LoginAction;
+import org.codelibs.fess.mylasta.action.FessUserBean;
+import org.codelibs.fess.mylasta.direction.FessConfig;
+import org.dbflute.optional.OptionalEntity;
+import org.dbflute.optional.OptionalThing;
+import org.lastaflute.core.magic.async.AsyncManager;
+import org.lastaflute.core.time.TimeManager;
+import org.lastaflute.web.login.LoginHandlingResource;
+import org.lastaflute.web.login.LoginManager;
+import org.lastaflute.web.login.TypicalLoginAssist;
+import org.lastaflute.web.login.exception.LoginRequiredException;
+import org.lastaflute.web.login.option.LoginSpecifiedOption;
+
+/**
+ * @author jflute
+ */
+public class FessLoginAssist extends TypicalLoginAssist<String, FessUserBean, Object> // #change_it also UserBean
+        implements LoginManager {
+
+    // ===================================================================================
+    //                                                                           Attribute
+    //                                                                           =========
+    @Resource
+    private TimeManager timeManager;
+    @Resource
+    private AsyncManager asyncManager;
+    @Resource
+    private FessConfig fessConfig;
+
+    // ===================================================================================
+    //                                                                           Find User
+    //                                                                           =========
+    @Override
+    protected boolean doCheckUserLoginable(String email, String cipheredPassword) {
+        //return memberBhv.selectCount(cb -> {
+        //    cb.query().arrangeLogin(email, cipheredPassword);
+        //}) > 0;
+        return false;
+    }
+
+    @Override
+    protected OptionalEntity<Object> doFindLoginUser(String email, String cipheredPassword) {
+        //return memberBhv.selectEntity(cb -> {
+        //    cb.query().arrangeLogin(email, cipheredPassword);
+        //});
+        return null;
+    }
+
+    @Override
+    protected OptionalEntity<Object> doFindLoginUser(String userId) {
+        //return memberBhv.selectEntity(cb -> {
+        //    cb.query().arrangeLoginByIdentity(userId);
+        //});
+        return null;
+    }
+
+    // ===================================================================================
+    //                                                                       Login Process
+    //                                                                       =============
+    @Override
+    protected FessUserBean createUserBean(Object userEntity) {
+        return new FessUserBean();
+    }
+
+    @Override
+    protected OptionalThing<String> getCookieRememberMeKey() {
+        // example to use remember-me
+        //return OptionalThing.of(fessConfig.getCookieRememberMeFessKey());
+        return OptionalThing.empty();
+    }
+
+    @Override
+    protected void saveLoginHistory(Object member, FessUserBean userBean, LoginSpecifiedOption option) {
+        asyncManager.async(() -> {
+            insertLogin(member);
+        });
+    }
+
+    protected void insertLogin(Object member) {
+    }
+
+    @Override
+    protected void checkPermission(LoginHandlingResource resource) throws LoginRequiredException {
+        super.checkPermission(resource);
+    }
+    
+    // ===================================================================================
+    //                                                                      Login Resource
+    //                                                                      ==============
+    @Override
+    protected Class<FessUserBean> getUserBeanType() {
+        return FessUserBean.class;
+    }
+
+    @Override
+    protected Class<?> getLoginActionType() {
+        return LoginAction.class;
+    }
+}

+ 52 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessUserBean.java

@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012 the CodeLibs Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.codelibs.fess.mylasta.action;
+
+import org.lastaflute.web.login.TypicalUserBean;
+
+/**
+ * @author jflute
+ */
+public class FessUserBean extends TypicalUserBean<String> { // #change_it also LoginAssist
+
+    // ===================================================================================
+    //                                                                          Definition
+    //                                                                          ==========
+    /** The serial version UID for object serialization. (Default) */
+    private static final long serialVersionUID = 1L;
+
+    // ===================================================================================
+    //                                                                           Attribute
+    //                                                                           =========
+
+    // ===================================================================================
+    //                                                                         Constructor
+    //                                                                         ===========
+    public FessUserBean() {
+    }
+
+    // ===================================================================================
+    //                                                                      Implementation
+    //                                                                      ==============
+    @Override
+    public String getUserId() {
+        return null;
+    }
+
+    // ===================================================================================
+    //                                                                            Accessor
+    //                                                                            ========
+}