io.odysz.semantics.IUser Maven / Gradle / Ivy
package io.odysz.semantics;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import io.odysz.anson.Anson;
import io.odysz.common.AESHelper;
import io.odysz.common.EnvPath;
import io.odysz.semantics.meta.TableMeta;
import io.odysz.transact.x.TransException;
/**Provide user e.g. servlet session information to modify some data in AST.
* Usage
*
* 1. Configure the implementations class name in config.xml.
* 2. If the client needing logging in and responsed with a user object, the class must extend {@link SemanticObject}.
* - For default implementation, see semantic.jserv/JUser.
*
* This is not necessary if using semantic-transact directly. But if the caller
* want to set user information like fingerpirnt for modified records, this can be used
* to let semantic-transact providing user identity to the semantics handler.
*
* In v1.1.1, sessionId is read only. If a new password have been updated,
* just remove then re-login
*
* @author ody
*/
public interface IUser {
/**
* Provide user table's meta for managing session by AnSession.
* @return table meta
* @throws SQLException
* @throws SemanticException
*/
TableMeta meta(String... connId) throws TransException, SQLException;
/**
* The sqls is committed to database, do something for logging.
* If there are some operation needing to update db, return those sql statements.
* If the parameter sqls is returned, it will be committed again because the semantic connection
* is think it's the logging sql.
* Make sure the committed sqls is not returned, only logging sqls are needed.
* @param sqls
* @param logger
* @return SQLs for logging, null for nothing to do
* @throws TransException
*/
default ArrayList dbLog(final ArrayList sqls) throws TransException { return null; }
/**
* Check user log in (already has pswd, iv and user Id from db)
* @param request request object. In sematic.jserv, it's SessionReq object.
* @return true: ok; false: failed
* @throws TransException Checking login information failed
*/
default boolean login(Object request) throws TransException { return false; }
/** If a user is allowed to change password, this is used to verify old
* and must be overridden to check the old password cipher.
* @param pswdCypher64 decrypted with my token id
* @param iv64
* @return yes or no the old password is working
* @throws TransException
* @throws IOException
* @throws GeneralSecurityException
*/
default boolean guessPswd(String pswdCypher64, String iv64) throws TransException, GeneralSecurityException, IOException { return false; }
default IUser sessionId(String rad64num) { return this; }
/**
* A session Id can never be changed.
* If a new password been updated, just remove the session and re-login.
* @return the session token
*/
default String sessionId() { return null; }
/**
* Update last touched time stamp.
* FYI, if the session object will be terminated when time is out,
* this method must touch the current time to keep session alive.
* Note: science v1.3.5, this requires users implement a touch function, and return the instance.
* @since 1.3.5
* */
default IUser touch() { return this; };
/**Last touched time in milliseconds, set by {@link #touch()}.
*/
long touchedMs();
/**user id */
String uid() ;
IUser logAct(String funcName, String funcId);
default SemanticObject logout() { return null; }
default void writeJsonRespValue(Object writer) throws IOException {}
/**Add notifyings
* @param note
* @return this
* @throws TransException
*/
public IUser notify(Object note) throws TransException;
/**Get notified string list.
* @return notifyings
*/
public List