Package io.continual.iam.impl.common
Class CommonJsonIdentity
- java.lang.Object
-
- io.continual.iam.impl.common.CommonJsonObject
-
- io.continual.iam.impl.common.CommonJsonIdentity
-
- All Implemented Interfaces:
Identity,UserDataHolder
public class CommonJsonIdentity extends CommonJsonObject implements Identity
-
-
Constructor Summary
Constructors Constructor Description CommonJsonIdentity(String userId, org.json.JSONObject userRecord, CommonJsonDb<? extends CommonJsonIdentity,?> db)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddApiKey(String newApiKey)protected booleanaddGroup(String groupId)org.json.JSONObjectasJson()ApiKeycreateApiKey()Create an API key for this user.voiddeleteApiKey(ApiKey key)Delete an API key from the user.voidenable(boolean enable)Enable or disable the user.StringgetApiKey()Get the API key supplied to the constructor, if any.protected org.json.JSONObjectgetDataRecord()GroupgetGroup(String groupId)Get a group by ID if the user is a member.Set<String>getGroupIds()Get the IDs of the groups this user belongs toCollection<Group>getGroups()Get the groups this user belongs toStringgetId()Get the unique id for this userStringgetPasswordHash()StringgetPasswordSalt()static org.json.JSONObjectinitializeIdentity()booleanisEnabled()Is this identity enabled?Collection<String>loadApiKeysForUser()Load the set of API keys for this user.static voidmain(String[] args)voidreload()reload this object from the serverprotected booleanremoveGroup(String groupId)StringrequestPasswordReset(long secondsUntilExpire, String nonce)Request a password reset.voidsetApiKeyUsedForAuth(String apiKey)voidsetPassword(String password)Set the user's password.voidsetPasswordSaltAndHash(String salt, String hash)protected voidstore()StringtoString()-
Methods inherited from class io.continual.iam.impl.common.CommonJsonObject
getAllUserData, getUserData, getValue, getValue, putUserData, removeUserData, removeValue, setValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.continual.iam.identity.UserDataHolder
getAllUserData, getUserData, putUserData, removeUserData
-
-
-
-
Constructor Detail
-
CommonJsonIdentity
public CommonJsonIdentity(String userId, org.json.JSONObject userRecord, CommonJsonDb<? extends CommonJsonIdentity,?> db)
-
-
Method Detail
-
initializeIdentity
public static org.json.JSONObject initializeIdentity()
-
getId
public String getId()
Description copied from interface:IdentityGet the unique id for this user
-
setApiKeyUsedForAuth
public void setApiKeyUsedForAuth(String apiKey)
-
getApiKey
public String getApiKey()
Get the API key supplied to the constructor, if any.- Returns:
- an API key or null
-
asJson
public org.json.JSONObject asJson()
-
setPassword
public void setPassword(String password) throws IamSvcException
Description copied from interface:IdentitySet the user's password. Implementations of this interface should be careful to store the password indirectly (e.g. via salted hash), but this is not enforced at the interface layer.- Specified by:
setPasswordin interfaceIdentity- Parameters:
password- a password- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
setPasswordSaltAndHash
public void setPasswordSaltAndHash(String salt, String hash) throws IamSvcException
- Throws:
IamSvcException
-
requestPasswordReset
public String requestPasswordReset(long secondsUntilExpire, String nonce) throws IamSvcException, IamBadRequestException
Description copied from interface:IdentityRequest a password reset. The response is a unique tag that would normally be distributed to the user via email as a link. The user acknowledges the password change request by clicking the link. The link handler then calls completePasswordReset().- Specified by:
requestPasswordResetin interfaceIdentity- Parameters:
secondsUntilExpire- amount of time until the generated tag expiresnonce- arbitrary user data used to create the tag- Returns:
- a unique tag
- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamIdentityDoesNotExist- when the identity doesn't existIamBadRequestException- when the request is now allowed
-
createApiKey
public ApiKey createApiKey() throws IamSvcException
Description copied from interface:IdentityCreate an API key for this user.- Specified by:
createApiKeyin interfaceIdentity- Returns:
- an API key
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadApiKeysForUser
public Collection<String> loadApiKeysForUser() throws IamSvcException
Description copied from interface:IdentityLoad the set of API keys for this user.- Specified by:
loadApiKeysForUserin interfaceIdentity- Returns:
- a set of 0 or more API keys
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
deleteApiKey
public void deleteApiKey(ApiKey key) throws IamSvcException
Description copied from interface:IdentityDelete an API key from the user.- Specified by:
deleteApiKeyin interfaceIdentity- Parameters:
key- the API key to remove- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
enable
public void enable(boolean enable) throws IamSvcExceptionDescription copied from interface:IdentityEnable or disable the user. When disabled, authentication will fail.- Specified by:
enablein interfaceIdentity- Parameters:
enable- if true, enable the user- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
isEnabled
public boolean isEnabled()
Description copied from interface:IdentityIs this identity enabled?
-
getPasswordSalt
public String getPasswordSalt()
-
getPasswordHash
public String getPasswordHash()
-
getGroupIds
public Set<String> getGroupIds() throws IamSvcException
Description copied from interface:IdentityGet the IDs of the groups this user belongs to- Specified by:
getGroupIdsin interfaceIdentity- Returns:
- a set of group IDs
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
getGroups
public Collection<Group> getGroups() throws IamSvcException
Description copied from interface:IdentityGet the groups this user belongs to- Specified by:
getGroupsin interfaceIdentity- Returns:
- a set of groups
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
getGroup
public Group getGroup(String groupId) throws IamSvcException
Description copied from interface:IdentityGet a group by ID if the user is a member. Otherwise, null is returned.- Specified by:
getGroupin interfaceIdentity- Parameters:
groupId- the ID of the group to retrieve- Returns:
- a group or null if not a member
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
addApiKey
public void addApiKey(String newApiKey)
-
addGroup
protected boolean addGroup(String groupId)
-
removeGroup
protected boolean removeGroup(String groupId)
-
getDataRecord
protected org.json.JSONObject getDataRecord()
- Specified by:
getDataRecordin classCommonJsonObject
-
reload
public void reload() throws IamSvcExceptionDescription copied from interface:UserDataHolderreload this object from the server- Specified by:
reloadin interfaceUserDataHolder- Specified by:
reloadin classCommonJsonObject- Throws:
IamSvcException- if there's a problem in the IAM service
-
store
protected void store() throws IamSvcException- Specified by:
storein classCommonJsonObject- Throws:
IamSvcException
-
main
public static void main(String[] args)
-
-