Package net.i2p.i2pcontrol.security
Class SecurityManager
- java.lang.Object
-
- net.i2p.i2pcontrol.security.SecurityManager
-
public class SecurityManager extends Object
Manage the password storing for I2PControl.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_AUTH_PASSWORD
-
Constructor Summary
Constructors Constructor Description SecurityManager(I2PAppContext ctx, KeyStoreProvider ksp, ConfigurationManager conf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getHash(String string)
Hash input one time with SHA-256, return Base64 encdoded string.String
getPasswdHash(String pwd)
Hash pwd with using BCrypt with the default salt.boolean
isDefaultPasswordValid()
Is this password correct?boolean
isValid(String pwd)
Is this password correct?boolean
setPasswd(String newPasswd)
Set new password.void
stopTimedEvents()
AuthToken
validatePasswd(String pwd)
Add a Authentication Token if the provided password is valid.void
verifyToken(String tokenID)
Checks whether the AuthToken with the given ID exists and if it does whether is has expired.
-
-
-
Field Detail
-
DEFAULT_AUTH_PASSWORD
public static final String DEFAULT_AUTH_PASSWORD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SecurityManager
public SecurityManager(I2PAppContext ctx, KeyStoreProvider ksp, ConfigurationManager conf)
- Parameters:
ksp
- may be null (if webapp)
-
-
Method Detail
-
stopTimedEvents
public void stopTimedEvents()
-
getPasswdHash
public String getPasswdHash(String pwd)
Hash pwd with using BCrypt with the default salt.- Parameters:
pwd
-- Returns:
- BCrypt hash of salt and input string
-
getHash
public String getHash(String string)
Hash input one time with SHA-256, return Base64 encdoded string.- Parameters:
string
-- Returns:
- Base64 encoded string
-
isValid
public boolean isValid(String pwd)
Is this password correct?- Returns:
- true if password is valid.
- Since:
- 0.12
-
isDefaultPasswordValid
public boolean isDefaultPasswordValid()
Is this password correct?- Returns:
- true if password is valid.
- Since:
- 0.12
-
validatePasswd
public AuthToken validatePasswd(String pwd)
Add a Authentication Token if the provided password is valid. The token will be valid for one day.- Returns:
- AuthToken if password is valid. If password is invalid null will be returned.
-
setPasswd
public boolean setPasswd(String newPasswd)
Set new password. Old tokens will NOT remain valid, to encourage the new password being tested.- Parameters:
newPasswd
-- Returns:
- Returns true if a new password was set.
-
verifyToken
public void verifyToken(String tokenID) throws InvalidAuthTokenException, ExpiredAuthTokenException
Checks whether the AuthToken with the given ID exists and if it does whether is has expired.- Parameters:
tokenID
- - The token to validate- Throws:
InvalidAuthTokenException
ExpiredAuthTokenException
-
-