Package org.zaproxy.zap.users
Class User
- java.lang.Object
-
- org.zaproxy.zap.utils.Enableable
-
- org.zaproxy.zap.users.User
-
- All Implemented Interfaces:
EnableableInterface
public class User extends Enableable
ZAP representation of a web application user.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
authenticate()
Authenticates the user, using its authentication credentials and the authentication method corresponding to its Context.static User
decode(int contextId, java.lang.String encodedString)
Decodes an User from an encoded string.protected static User
decode(int contextId, java.lang.String encodedString, ExtensionAuthentication authenticationExtension)
Helper method for decoding an user from an encoded string.static java.lang.String
encode(User user)
Encodes the User in a String.boolean
equals(java.lang.Object obj)
WebSession
getAuthenticatedSession()
AuthenticationCredentials
getAuthenticationCredentials()
Gets the configured authentication credentials of this user.AuthenticationState
getAuthenticationState()
Returns the authentication state for this user.Context
getContext()
Lazy loader for getting the context to which this user corresponds.int
getContextId()
Gets the context id.org.apache.commons.httpclient.HttpState
getCorrespondingHttpState()
int
getId()
Gets the id.protected long
getLastSuccessfulAuthTime()
Deprecated.use #getAuthenticationState().getLastSuccessfulAuthTime()java.lang.String
getName()
Gets the name of the user.int
hashCode()
boolean
isAuthenticated(HttpMessage msg)
Checks if the response received by the Http Message corresponds to this user.void
processMessageToMatchAuthenticatedSession(HttpMessage message)
Modifies a message so its Request Header/Body matches the web session corresponding to this user.void
processMessageToMatchUser(HttpMessage message)
Modifies a message so its Request Header/Body matches the web session corresponding to this user.void
queueAuthentication(HttpMessage unauthenticatedMessage)
Resets the existing authenticated session, causing subsequent calls toprocessMessageToMatchUser(HttpMessage)
to reauthenticate.boolean
requiresAuthentication()
Checks if an authentication is needed and will be performed at the next call toprocessMessageToMatchUser(HttpMessage)
.void
setAuthenticatedSession(WebSession session)
void
setAuthenticationCredentials(AuthenticationCredentials authenticationCredentials)
Sets the authentication credentials for the user.void
setName(java.lang.String name)
Sets the name.java.lang.String
toString()
-
Methods inherited from class org.zaproxy.zap.utils.Enableable
isEnabled, setEnabled
-
-
-
-
Constructor Detail
-
User
public User(int contextId, java.lang.String name)
Instantiates a new user.- Parameters:
contextId
- the context idname
- the name
-
User
public User(int contextId, java.lang.String name, int id)
Instantiates a new user.- Parameters:
contextId
- the context idname
- the nameid
- the id
-
-
Method Detail
-
getName
public java.lang.String getName()
Gets the name of the user.- Returns:
- the name
-
getContextId
public int getContextId()
Gets the context id.- Returns:
- the context id
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getContext
public Context getContext()
Lazy loader for getting the context to which this user corresponds.- Returns:
- the context
-
getId
public int getId()
Gets the id.- Returns:
- the id
-
processMessageToMatchUser
public void processMessageToMatchUser(HttpMessage message)
Modifies a message so its Request Header/Body matches the web session corresponding to this user.- Parameters:
message
- the message
-
processMessageToMatchAuthenticatedSession
public void processMessageToMatchAuthenticatedSession(HttpMessage message)
Modifies a message so its Request Header/Body matches the web session corresponding to this user.- Parameters:
message
- the message
-
getAuthenticationCredentials
public AuthenticationCredentials getAuthenticationCredentials()
Gets the configured authentication credentials of this user.- Returns:
- the authentication credentials
-
setAuthenticationCredentials
public void setAuthenticationCredentials(AuthenticationCredentials authenticationCredentials)
Sets the authentication credentials for the user. These will be used to authenticate the user, if necessary.- Parameters:
authenticationCredentials
- the new authentication credentials
-
requiresAuthentication
public boolean requiresAuthentication()
Checks if an authentication is needed and will be performed at the next call toprocessMessageToMatchUser(HttpMessage)
.- Returns:
- true, if requires authentication
-
queueAuthentication
public void queueAuthentication(HttpMessage unauthenticatedMessage)
Resets the existing authenticated session, causing subsequent calls toprocessMessageToMatchUser(HttpMessage)
to reauthenticate.- Parameters:
unauthenticatedMessage
- the unauthenticated message
-
getLastSuccessfulAuthTime
@Deprecated protected long getLastSuccessfulAuthTime()
Deprecated.use #getAuthenticationState().getLastSuccessfulAuthTime()Gets the last successful auth time.- Returns:
- the time of last successful authentication
-
isAuthenticated
public boolean isAuthenticated(HttpMessage msg)
Checks if the response received by the Http Message corresponds to this user.- Parameters:
msg
- the msg- Returns:
- true, if is authenticated
-
authenticate
public void authenticate()
Authenticates the user, using its authentication credentials and the authentication method corresponding to its Context.- See Also:
SessionManagementMethod
,AuthenticationMethod
,Context
-
encode
public static java.lang.String encode(User user)
Encodes the User in a String. Fields that contain strings are Base64 encoded.- Parameters:
user
- the user- Returns:
- the string
-
decode
public static User decode(int contextId, java.lang.String encodedString)
Decodes an User from an encoded string. The string provided as input should have been obtained through calls toencode(User)
.- Parameters:
contextId
- the ID of the context the user belongs toencodedString
- the encoded string- Returns:
- the user
-
decode
protected static User decode(int contextId, java.lang.String encodedString, ExtensionAuthentication authenticationExtension)
Helper method for decoding an user from an encoded string. Seedecode(int, String)
.- Parameters:
contextId
- the ID of the context the user belongs toencodedString
- the encoded stringauthenticationExtension
- the authentication extension- Returns:
- the user
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classEnableable
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classEnableable
-
setName
public void setName(java.lang.String name)
Sets the name.- Parameters:
name
- the new name
-
getCorrespondingHttpState
public org.apache.commons.httpclient.HttpState getCorrespondingHttpState()
-
getAuthenticatedSession
public WebSession getAuthenticatedSession()
-
setAuthenticatedSession
public void setAuthenticatedSession(WebSession session)
-
getAuthenticationState
public AuthenticationState getAuthenticationState()
Returns the authentication state for this user.- Returns:
- the authentication state
- Since:
- 2.10.0
-
-