Package de.kosmos_lab.web.persistence
Class JSONPersistence
- java.lang.Object
-
- de.kosmos_lab.web.persistence.JSONPersistence
-
- All Implemented Interfaces:
IPersistence,ISesssionPersistence,IUserPersistence
public class JSONPersistence extends Object implements IUserPersistence, ISesssionPersistence
-
-
Field Summary
Fields Modifier and Type Field Description protected org.json.JSONObjectjsonprotected ConcurrentHashMap<String,String>sessionsprotected ConcurrentHashMap<String,User>usersprotected ConcurrentHashMap<UUID,User>usersByUUID
-
Constructor Summary
Constructors Constructor Description JSONPersistence(ControllerWithPersistence server, File storageFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddJWT(String token)booleanaddUser(String username, String password, int level)add a user to the persistencevoidcacheUser(User user)voiddoSave()ControllerWithPersistencegetController()StringgetJWT(User user)get the jwt for a userorg.json.JSONObjectgetJWT(String jwtid)get the JWT with a specific jwtid back, if it is in the system and still validCollection<org.json.JSONObject>getMySessions(String username)UsergetUser(String username)get a user from persistenceUsergetUser(UUID uuid)protected voidinit()intinitSesssions()intinitUsers()voidkillJWT(String jwtid)Userlogin(String username, String password)try to loginvoidprepare()protected voidsave()org.json.JSONObjectverifyJWT(String token)verify the given jwt
-
-
-
Field Detail
-
json
protected org.json.JSONObject json
-
users
protected ConcurrentHashMap<String,User> users
-
usersByUUID
protected ConcurrentHashMap<UUID,User> usersByUUID
-
sessions
protected ConcurrentHashMap<String,String> sessions
-
-
Constructor Detail
-
JSONPersistence
public JSONPersistence(ControllerWithPersistence server, File storageFile)
-
-
Method Detail
-
addJWT
public void addJWT(@Nonnull String token)- Specified by:
addJWTin interfaceISesssionPersistence- Specified by:
addJWTin interfaceIUserPersistence
-
addUser
public boolean addUser(@CheckForNull String username, @CheckForNull String password, int level)Description copied from interface:IUserPersistenceadd a user to the persistence- Specified by:
addUserin interfaceIUserPersistence- Returns:
-
cacheUser
public void cacheUser(User user)
-
doSave
public void doSave()
-
getJWT
public org.json.JSONObject getJWT(@Nonnull String jwtid)Description copied from interface:IUserPersistenceget the JWT with a specific jwtid back, if it is in the system and still valid- Specified by:
getJWTin interfaceISesssionPersistence- Specified by:
getJWTin interfaceIUserPersistence- Parameters:
jwtid- the id to find- Returns:
-
getJWT
public String getJWT(@Nonnull User user) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException
Description copied from interface:IUserPersistenceget the jwt for a user- Specified by:
getJWTin interfaceISesssionPersistence- Specified by:
getJWTin interfaceIUserPersistence- Returns:
- Throws:
UnsupportedEncodingExceptionNoSuchAlgorithmExceptionInvalidKeyException
-
getMySessions
public Collection<org.json.JSONObject> getMySessions(String username)
- Specified by:
getMySessionsin interfaceISesssionPersistence- Specified by:
getMySessionsin interfaceIUserPersistence
-
getController
public ControllerWithPersistence getController()
-
getUser
public User getUser(@CheckForNull String username)
Description copied from interface:IUserPersistenceget a user from persistence- Specified by:
getUserin interfaceIUserPersistence- Returns:
-
getUser
public User getUser(@CheckForNull UUID uuid)
- Specified by:
getUserin interfaceIUserPersistence
-
init
protected void init()
-
initSesssions
public int initSesssions()
- Specified by:
initSesssionsin interfaceISesssionPersistence
-
initUsers
public int initUsers()
- Specified by:
initUsersin interfaceIUserPersistence
-
killJWT
public void killJWT(String jwtid)
- Specified by:
killJWTin interfaceISesssionPersistence- Specified by:
killJWTin interfaceIUserPersistence
-
login
public User login(@CheckForNull String username, @CheckForNull String password) throws LoginFailedException
Description copied from interface:IUserPersistencetry to login- Specified by:
loginin interfaceIUserPersistence- Returns:
- returns a jwt token on success
- Throws:
LoginFailedException
-
prepare
public void prepare()
-
save
protected void save()
-
verifyJWT
public org.json.JSONObject verifyJWT(@Nonnull String token)Description copied from interface:IUserPersistenceverify the given jwt- Specified by:
verifyJWTin interfaceISesssionPersistence- Specified by:
verifyJWTin interfaceIUserPersistence- Returns:
-
-