本文整理汇总了Java中io.undertow.security.idm.Credential类的典型用法代码示例。如果您正苦于以下问题:Java Credential类的具体用法?Java Credential怎么用?Java Credential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于io.undertow.security.idm包,在下文中一共展示了Credential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyCredential
import io.undertow.security.idm.Credential; //导入依赖的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.Credential; //导入依赖的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.Credential; //导入依赖的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.Credential; //导入依赖的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.Credential; //导入依赖的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: authenticate
import io.undertow.security.idm.Credential; //导入依赖的package包/类
public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext securityContext) {
SSLSessionInfo sslSession = exchange.getConnection().getSslSessionInfo();
if (sslSession != null) {
try {
Certificate[] clientCerts = getPeerCertificates(exchange, sslSession, securityContext);
if (clientCerts[0] instanceof X509Certificate) {
Credential credential = new X509CertificateCredential((X509Certificate) clientCerts[0]);
IdentityManager idm = securityContext.getIdentityManager();
Account account = idm.verify(credential);
if (account != null) {
securityContext.authenticationComplete(account, name, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
}
} catch (SSLPeerUnverifiedException e) {
// No action - this mechanism can not attempt authentication without peer certificates so allow it to drop out
// to NOT_ATTEMPTED.
}
}
/*
* For ClientCert we do not have a concept of a failed authentication, if the client did use a key then it was deemed
* acceptable for the connection to be established, this mechanism then just 'attempts' to use it for authentication but
* does not mandate success.
*/
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例7: verify
import io.undertow.security.idm.Credential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
Account account = getAccount(id);
if (account != null && verifyCredential(account, credential)) {
return account;
}
return null;
}
示例8: verify
import io.undertow.security.idm.Credential; //导入依赖的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;
}
示例9: verify
import io.undertow.security.idm.Credential; //导入依赖的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);
}
示例10: verify
import io.undertow.security.idm.Credential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
if (this.account.getPrincipal().getName().equals(id)) {
return this.account;
} else {
return null;
}
}
示例11: verify
import io.undertow.security.idm.Credential; //导入依赖的package包/类
@Override
public Account verify(Credential credential) {
return new Account() {
@Override
public Principal getPrincipal() {
return principal;
}
@Override
public Set<String> getRoles() {
return Collections.emptySet();
}
};
}
示例12: verify
import io.undertow.security.idm.Credential; //导入依赖的package包/类
@Override
public Account verify(String username, Credential credential) {
Account account = null;
if (this.username.equals(username) && verifyCredential(credential)) {
account = getAccount(username);
}
return account;
}
示例13: verifyCredential
import io.undertow.security.idm.Credential; //导入依赖的package包/类
private boolean verifyCredential(Credential credential) {
if (credential instanceof PasswordCredential) {
return CodecUtils.checkJBCrypt(
new String (((PasswordCredential) credential).getPassword()),
this.password);
}
return false;
}
示例14: verify
import io.undertow.security.idm.Credential; //导入依赖的package包/类
@Override
public Account verify(String id, Credential credential) {
Account account = users.get(id);
if (account != null && verifyCredential(account, credential)) {
return account;
}
return null;
}
示例15: verify
import io.undertow.security.idm.Credential; //导入依赖的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());
}