本文整理汇总了Java中io.undertow.security.idm.PasswordCredential类的典型用法代码示例。如果您正苦于以下问题:Java PasswordCredential类的具体用法?Java PasswordCredential怎么用?Java PasswordCredential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PasswordCredential类属于io.undertow.security.idm包,在下文中一共展示了PasswordCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyCredential
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private boolean verifyCredential(Account account, Credential credential) {
boolean match = false;
if (credential instanceof PasswordCredential) {
char[] password = ((PasswordCredential) credential).getPassword();
User user = users.get(account.getPrincipal().getName());
String expectedPassword = user.getPassword();
try {
match = HashUtil.validatePassword(password, expectedPassword);
Arrays.fill(password, ' ');
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
logger.error("Exception:", e);
}
}
if(logger.isDebugEnabled()) logger.debug("verfifyCredential = " + match);
return match;
}
示例2: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
PasswordCredential passwordCredential = (PasswordCredential) credential;
try {
User user = repository.authenticate(id, passwordCredential.getPassword());
if(logger.isDebugEnabled()) {
logger.debug("User {} logged", user);
}
return new UserPrincipal(user.id, user.username, User.ROLES);
} catch (UserNotFoundException e) {
if(logger.isInfoEnabled()) {
logger.info("Login failed", e);
}
}
return null;
}
示例3: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
if (id == null || id.trim().length() == 0) {
return null;
}
FakeAccount account = accounts.get(id);
if ((credential instanceof PasswordCredential)
&& String.valueOf(((PasswordCredential) credential).getPassword()).equals(account.password)) {
account.roles.add(
LightblueRestTestHarness.SECURITY_ROLE_AUTHENTICATED);
return account;
}
return null;
}
示例4: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public Account verify(String username, Credential credential) {
if (username == null || credential == null || !(credential instanceof PasswordCredential)) {
return null;
}
PasswordCredential pwc = (PasswordCredential) credential;
try {
Set<String> roles = getRoles(username, new String(pwc.getPassword()));
Account acct = new SimpleAccount(username, pwc.getPassword(), roles);
return acct;
} catch (NamingException e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例5: verifyCredential
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
private boolean verifyCredential(Account account, Credential credential) {
String id = account.getPrincipal().getName();
SimpleAccount ourAccount = getAccount(id);
if (ourAccount == null) {
return false;
}
if (credential instanceof PasswordCredential
&& account instanceof SimpleAccount) {
char[] password = ((PasswordCredential) credential).getPassword();
char[] expected = ourAccount.getCredentials().getPassword();
return checkPassword(
this.bcryptHashedPassword,
password,
expected);
}
return false;
}
示例6: SimpleAccount
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
/**
*
* @param name
* @param password
* @param roles
*/
public SimpleAccount(String name, char[] password, Set<String> roles) {
if (name == null) {
throw new IllegalArgumentException("argument principal cannot be null");
}
if (password == null) {
throw new IllegalArgumentException("argument password cannot be null");
}
if (roles == null || roles.isEmpty()) {
roles = Sets.newHashSet();
}
this.principal = new SimplePrincipal(name);
this.credential = new PasswordCredential(password);
this.roles = roles;
}
示例7: login
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public boolean login(final String username, final String password) {
final Account account = identityManager.verify(username, new PasswordCredential(password.toCharArray()));
if (account == null) {
return false;
}
authenticationComplete(account, programaticMechName, true);
this.authenticationState = AuthenticationState.AUTHENTICATED;
return true;
}
示例8: runFormAuth
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange exchange, final SecurityContext securityContext) {
final FormDataParser parser = formParserFactory.createParser(exchange);
if (parser == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as no form parser is present");
// TODO - May need a better error signaling mechanism here to prevent repeated attempts.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
try {
final FormData data = parser.parseBlocking();
final FormData.FormValue jUsername = data.getFirst("j_username");
final FormData.FormValue jPassword = data.getFirst("j_password");
if (jUsername == null || jPassword == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as username or password was not present in the posted result");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
final String userName = jUsername.getValue();
final String password = jPassword.getValue();
AuthenticationMechanismOutcome outcome = null;
PasswordCredential credential = new PasswordCredential(password.toCharArray());
try {
IdentityManager identityManager = securityContext.getIdentityManager();
Account account = identityManager.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, name, true);
outcome = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
}
} finally {
if (outcome == AuthenticationMechanismOutcome.AUTHENTICATED) {
handleRedirectBack(exchange);
exchange.endExchange();
}
return outcome != null ? outcome : AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
if(!(credential instanceof PasswordCredential)) {
return null;
}
PasswordCredential pc = (PasswordCredential) credential;
char[] pwdArr = pc.getPassword();
if(pwdArr != null && passwordEncoder.matches(new String(pwdArr), encodedPass)) {
return new AccountImpl(id);
}
return null;
}
示例10: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
/**
* Called by FormAuthenticationMechanism when user submits the login form.
*/
@Override
public Account verify(String id, Credential credential) {
PasswordCredential pwdCredential = (PasswordCredential) credential;
return this.userRolesMapping
.entrySet()
.stream()
.filter(entry -> StringUtils.equals(entry.getKey(), id)
&& ArrayUtils.isNotEmpty(pwdCredential.getPassword())
&& CredentialMatcher.match(entry.getKey(), new String(pwdCredential.getPassword())))
.map(entry -> new SimpleAccount(new SimplePrincipal(entry.getKey()), new HashSet<>(entry.getValue())))
.findFirst()
.orElse(null);
}
示例11: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
protected Optional<Account> verify(String[] credentials, IdentityManager identityManager) {
try {
Account account = identityManager.verify(credentials[0], new PasswordCredential(credentials[1].toCharArray()));
return Optional.ofNullable(account);
} catch (NullPointerException e) {
throw new AuthenticationException(AuthenticationMechanismOutcome.NOT_AUTHENTICATED, "Malformated credentials - "
+ e.getMessage());
}
}
示例12: verifyCredential
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
private boolean verifyCredential(Credential credential) {
if (credential instanceof PasswordCredential) {
return CodecUtils.checkJBCrypt(
new String (((PasswordCredential) credential).getPassword()),
this.password);
}
return false;
}
示例13: testValidVerify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Test
public void testValidVerify() {
//given
Identity identity = new Identity("foo", CodecUtils.hexJBcrypt("bar"));
PasswordCredential credential = new PasswordCredential(password);
//when
Account account = identity.verify("foo", credential);
//then
assertThat(account, not(nullValue()));
assertThat(account.getPrincipal().getName(), equalTo("foo"));
}
示例14: testNonValidVerify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Test
public void testNonValidVerify() {
//given
Identity identity = new Identity("foo", CodecUtils.hexJBcrypt("abar"));
PasswordCredential credential = new PasswordCredential(password);
//when
Account account = identity.verify("foo", credential);
//then
assertThat(account, nullValue());
}
示例15: verify
import io.undertow.security.idm.PasswordCredential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
if (id == null || id.length() == 0) {
HttpServerLogger.ROOT_LOGGER.debug("Missing or empty username received, aborting account verification.");
return null;
}
if (credential instanceof PasswordCredential) {
return verify(id, (PasswordCredential) credential);
} else if (credential instanceof DigestCredential) {
return verify(id, (DigestCredential) credential);
}
throw HttpServerLogger.ROOT_LOGGER.invalidCredentialType(credential.getClass().getName());
}