当前位置: 首页>>代码示例>>Java>>正文


Java PasswordCredential类代码示例

本文整理汇总了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;
}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:18,代码来源:MapIdentityManager.java

示例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;
}
 
开发者ID:vvergnolle,项目名称:vas,代码行数:20,代码来源:RepositoryIdentityManager.java

示例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;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:17,代码来源:FakeIdentityManager.java

示例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;
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:17,代码来源:ADIdentityManager.java

示例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;
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:22,代码来源:AbstractDbIdentityManager.java

示例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;
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:24,代码来源:SimpleAccount.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:SecurityContextImpl.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:FormAuthenticationMechanism.java

示例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;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:13,代码来源:AuthConfiguration.java

示例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);
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:17,代码来源:SimpleIdentityManager.java

示例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());
  }
}
 
开发者ID:vvergnolle,项目名称:vas,代码行数:10,代码来源:RestAuthenticationMechanism.java

示例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;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:10,代码来源:Identity.java

示例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"));
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:14,代码来源:IdentityTest.java

示例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());
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:13,代码来源:IdentityTest.java

示例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());
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:16,代码来源:RealmIdentityManager.java


注:本文中的io.undertow.security.idm.PasswordCredential类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。