• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CredentialException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.security.auth.login.CredentialException的典型用法代码示例。如果您正苦于以下问题:Java CredentialException类的具体用法?Java CredentialException怎么用?Java CredentialException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CredentialException类属于javax.security.auth.login包,在下文中一共展示了CredentialException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getKeyVaultCredential

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
public AzureKeyVaultCredential getKeyVaultCredential(Run<?, ?> build) throws CredentialNotFoundException, CredentialException
{
    // Try override values
    LOGGER.log(Level.INFO, String.format("Trying override credentials..."));
    AzureKeyVaultCredential credential = getKeyVaultCredential(build, this.applicationSecret, this.credentialID);
    if (credential.isValid())
    {
        LOGGER.log(Level.INFO, String.format("Using override credentials"));
        return credential;
    }
    
    // Try global values
    LOGGER.log(Level.INFO, String.format("Trying global credentials"));
    credential = getKeyVaultCredential(build, getDescriptor().getApplicationSecret(), getDescriptor().getCredentialID());
    if (credential.isValid())
    {
        LOGGER.log(Level.INFO, String.format("Using global credentials"));
        return credential;
    }
    throw new CredentialNotFoundException("Unable to find a valid credential with provided parameters");
}
 
开发者ID:mbearup,项目名称:azure-keyvault-plugin,代码行数:22,代码来源:AzureKeyVaultBuildWrapper.java


示例2: readFields

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
private String[] readFields(final byte[] buffer) throws CredentialException {
    List<String> fields = new ArrayList<>();
    int pos = 0;
    Buffer b = Buffer.buffer();
    while (pos < buffer.length) {
        byte val = buffer[pos];
        if (val == 0x00) {
            fields.add(b.toString(StandardCharsets.UTF_8));
            b = Buffer.buffer();
        } else {
            b.appendByte(val);
        }
        pos++;
    }
    fields.add(b.toString(StandardCharsets.UTF_8));

    if (fields.size() != 3) {
        throw new CredentialException("client provided malformed PLAIN response");
    } else if (fields.get(1) == null || fields.get(1).length() == 0) {
        throw new CredentialException("PLAIN response must contain an authentication ID");
    } else if(fields.get(2) == null || fields.get(2).length() == 0) {
        throw new CredentialException("PLAIN response must contain a password");
    } else {
        return fields.toArray(new String[3]);
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:27,代码来源:AbstractHonoAuthenticationService.java


示例3: getCredentialById

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
public AzureKeyVaultCredential getCredentialById(String _credentialID, Run<?, ?> build) throws CredentialNotFoundException, CredentialException
{
    AzureKeyVaultCredential credential = new AzureKeyVaultCredential();
    IdCredentials cred = CredentialsProvider.findCredentialById(_credentialID, IdCredentials.class, build);
    
    if (cred==null)
    {
        throw new CredentialNotFoundException(_credentialID);
    }
    
    if(StringCredentials.class.isInstance(cred))
    {
        // Secret Text object
        LOGGER.log(Level.INFO, String.format("Fetched %s as StringCredentials", _credentialID));
        CredentialsProvider.track(build, cred);
        credential.setApplicationSecret(StringCredentials.class.cast(cred).getSecret());
        return credential;
    }
    else if(StandardUsernamePasswordCredentials.class.isInstance(cred))
    {
        // Username/Password Object
        LOGGER.log(Level.INFO, String.format("Fetched %s as StandardUsernamePasswordCredentials", _credentialID));
        CredentialsProvider.track(build, cred);
        credential.setApplicationID(StandardUsernamePasswordCredentials.class.cast(cred).getUsername());
        credential.setApplicationSecret(StandardUsernamePasswordCredentials.class.cast(cred).getPassword());
        return credential;
    }
    else
    {
        throw new CredentialException("Could not determine the type for Secret id " + _credentialID + " only 'Secret Text' and 'Username/Password' are supported");
    }
}
 
开发者ID:mbearup,项目名称:azure-keyvault-plugin,代码行数:33,代码来源:AzureKeyVaultBuildWrapper.java


示例4: login

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) {
    HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
    httpSessionSecurityContextRepository.loadContext(holder);

    try {
        // 使用提供的证书认证用户
        List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN");
        Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities);
        SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(auth));

        // 认证用户
        if(!auth.isAuthenticated())
            throw new CredentialException("用户不能够被认证");
    } catch (Exception ex) {
        // 用户不能够被认证,重定向回登录页
        logger.info(ex);
        return "login";
    }

    // 从会话得到默认保存的请求
    DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST");
    // 为令牌请求生成认证参数Map
    Map<String, String> authParams = getAuthParameters(defaultSavedRequest);
    AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clientDetailsService).createAuthorizationRequest(authParams);
    authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    model.addAttribute("authorizationRequest", authRequest);

    httpSessionSecurityContextRepository.saveContext(SecurityContextHolder.getContext(), holder.getRequest(), holder.getResponse());
    return "authorize";
}
 
开发者ID:chaokunyang,项目名称:microservices-event-sourcing,代码行数:32,代码来源:LoginController.java


示例5: testCtor2

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
/**
 * @tests javax.security.auth.login.CredentialException#CredentialException(
 *        java.lang.String)
 */
public final void testCtor2() {
    assertNull(new CredentialException(null).getMessage());

    String message = "";
    assertSame(message, new CredentialException(message).getMessage());

    message = "message";
    assertSame(message, new CredentialException(message).getMessage());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:14,代码来源:CredentialExceptionTest.java


示例6: matches

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@Override
public boolean matches(Account account, AuthenticationToken token) throws CredentialException {
    Object tokenCredentials = token.readCredentials();
    if (tokenCredentials == null) {
        throw new CredentialNotFoundException("token");
    }
    Object accountCredentials = account.getCredentials();
    if (accountCredentials == null) {
        throw new CredentialNotFoundException("account");
    }
    String hashed = Crypto.sha512(tokenCredentials.toString(), account.getPrincipal().getName(), hashIterations);
    return accountCredentials.toString().equals(hashed);
}
 
开发者ID:guestful,项目名称:module.jaxrs-filter-security,代码行数:14,代码来源:HashedCredentialsMatcher.java


示例7: removeUser

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
public synchronized final boolean removeUser(String regId) throws CredentialException {
	if (!registeredUsers.contains(regId)) {
		throw new CredentialException("wrong credentials for given user");
	}
	if (registeredUsers.remove(regId)) {
		return true;
	}
	return false;
}
 
开发者ID:HTWK-App,项目名称:Server-Application,代码行数:10,代码来源:UpdateService.java


示例8: login

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) {

    HttpRequestResponseHolder responseHolder = new HttpRequestResponseHolder(request, response);
    sessionRepository.loadContext(responseHolder);

    try {
        // Authenticate the user with the supplied credentials
        List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN");

        Authentication auth =
                new UsernamePasswordAuthenticationToken(request.getParameter("username"),
                        request.getParameter("password"), authorities);

        SecurityContextHolder.getContext()
                .setAuthentication(authenticationManager.authenticate(auth));

        // Authenticate the user
        if(!authenticationManager.authenticate(auth).isAuthenticated())
            throw new CredentialException("User could not be authenticated");

    } catch (Exception ex) {
        // The user couldn't be authenticated, redirect back to login
        ex.printStackTrace();
        return "login";
    }

    // Get the default saved request from session
    DefaultSavedRequest defaultSavedRequest = ((DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST"));

    // Generate an authorization parameter map for the token request
    Map<String, String> authParams = getAuthParameters(defaultSavedRequest);

    // Create the authorization request and put it in the view model
    AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clients).createAuthorizationRequest(authParams);
    authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    sessionRepository.saveContext(SecurityContextHolder.getContext(), responseHolder.getRequest(), responseHolder.getResponse());
    model.addAttribute("authorizationRequest", authRequest);

    // Return the token authorization view
    return "authorize";
}
 
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:43,代码来源:LoginController.java


示例9: getData

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@Override
protected Object[] getData() {
    return new Object[] {new CredentialException("message")};
}
 
开发者ID:shannah,项目名称:cn1,代码行数:5,代码来源:CredentialExceptionTest.java


示例10: testCtor1

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
/**
 * @tests javax.security.auth.login.CredentialException#CredentialException()
 */
public final void testCtor1() {
    assertNull(new CredentialException().getMessage());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:7,代码来源:CredentialExceptionTest.java


示例11: disablePushNotification

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@RequestMapping(value = "/push", method = RequestMethod.DELETE)
public @ResponseBody
String disablePushNotification(@RequestParam(value = "regid") String regid)
		throws CredentialException {
	return "" + updateService.removeUser(regid);
}
 
开发者ID:HTWK-App,项目名称:Server-Application,代码行数:7,代码来源:AuthenticationController.java


示例12: disablePushNotificationViaGet

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
@RequestMapping(value = "/push/delete", method = RequestMethod.GET)
public @ResponseBody
String disablePushNotificationViaGet(@RequestParam(value = "regid") String regid)
		throws CredentialException {
	return "" + updateService.removeUser(regid);
}
 
开发者ID:HTWK-App,项目名称:Server-Application,代码行数:7,代码来源:AuthenticationController.java


示例13: matches

import javax.security.auth.login.CredentialException; //导入依赖的package包/类
boolean matches(Account account, AuthenticationToken token) throws CredentialException; 
开发者ID:guestful,项目名称:module.jaxrs-filter-security,代码行数:2,代码来源:CredentialsMatcher.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MultiverseWorld类代码示例发布时间:2022-05-22
下一篇:
Java FailingMapper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap