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

Java UsernamePasswordCredential类代码示例

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

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



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

示例1: login

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public void login() {

        FacesContext context = FacesContext.getCurrentInstance();
        Credential credential = new UsernamePasswordCredential(username, new Password(password));

        AuthenticationStatus status = securityContext.authenticate(
                getRequest(context),
                getResponse(context),
                withParams()
                        .credential(credential)
                        .newAuthentication(!continued)
                        .rememberMe(rememberMe)
        );

        LOG.info("authentication result:" + status);

        if (status.equals(SEND_CONTINUE)) {
            // Authentication mechanism has send a redirect, should not
            // send anything to response from JSF now.
            context.responseComplete();
        } else if (status.equals(SEND_FAILURE)) {
            addError(context, "Authentication failed");
        }

    }
 
开发者ID:hantsy,项目名称:javaee8-jsf-sample,代码行数:26,代码来源:LoginBean.java


示例2: login

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public void login() {
    
    Credential credential = new UsernamePasswordCredential(username, new Password(password));
    
    AuthenticationStatus status = securityContext.authenticate(
        getRequestFrom(facesContext),
        getResponseFrom(facesContext),
        withParams().credential(credential));
    
    if (status.equals(SEND_CONTINUE)) {
        facesContext.responseComplete();
    } else if (status.equals(SEND_FAILURE)) {
        addError(facesContext, "Authentication failed");
    }
    
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:17,代码来源:LoginBean.java


示例3: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response,
                                            HttpMessageContext httpMessageContext) throws AuthenticationException {

    // ...
    String name = request.getParameter("name");
    String password = request.getParameter("password");

    if (name != null && password != null) {
        CredentialValidationResult result = identityStoreHandler.validate(new UsernamePasswordCredential(name, password));

        return httpMessageContext.notifyContainerAboutLogin(result);
    }

    return httpMessageContext.doNothing();
}
 
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:17,代码来源:TestAuthenticationMechanism.java


示例4: validate

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
    CredentialValidationResult result;

    if (credential instanceof UsernamePasswordCredential) {
        UsernamePasswordCredential usernamePassword = (UsernamePasswordCredential) credential;

        result = users.findByUsername(usernamePassword.getCaller())
            .map(
                u -> passwordHash.matches(new String(usernamePassword.getPassword().getValue()), u.getPassword())
                ? new CredentialValidationResult(usernamePassword.getCaller(), u.getAuthorities())
                : INVALID_RESULT
            )
            .orElse(INVALID_RESULT);

    } else {
        result = NOT_VALIDATED_RESULT;
    }
    return result;
}
 
开发者ID:hantsy,项目名称:javaee8-jaxrs-sample,代码行数:21,代码来源:JpaIdentityStore.java


示例5: login

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public void login() {

        FacesContext context = FacesContext.getCurrentInstance();
        Credential credential = new UsernamePasswordCredential(username, new Password(password));

        AuthenticationStatus status = securityContext.authenticate(
                getRequest(context),
                getResponse(context),
                withParams()
                        .credential(credential));

        LOG.info("authentication result:" + status);

        if (status.equals(SEND_CONTINUE)) {
            // Authentication mechanism has send a redirect, should not
            // send anything to response from JSF now.
            context.responseComplete();
        } else if (status.equals(SEND_FAILURE)) {
            addError(context, "Authentication failed");
        }

    }
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:23,代码来源:LoginBean.java


示例6: login

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public void login() {

        FacesContext context = FacesContext.getCurrentInstance();
        Credential credential = new UsernamePasswordCredential(username, new Password(password));

        AuthenticationStatus status = securityContext.authenticate(
                getRequest(context),
                getResponse(context),
                withParams()
                        .credential(credential));

        LOG.log(Level.INFO, "authentication result:{0}", status);

        if (status.equals(SEND_CONTINUE)) {
            // Authentication mechanism has send a redirect, should not
            // send anything to response from JSF now.
            context.responseComplete();
        } else if (status.equals(SEND_FAILURE)) {
            addError(context, "Authentication failed");
        }

    }
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:23,代码来源:LoginBean.java


示例7: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {

    if (request.getParameter("login:username") != null && request.getParameter("login:password") != null) {

        String name = request.getParameter("login:username");
        Password password = new Password(request.getParameter("login:password"));

        CredentialValidationResult result = identityStore.validate(
                new UsernamePasswordCredential(name, password));

        if (result.getStatus() == VALID) {
            return httpMessageContext.notifyContainerAboutLogin(
                    result.getCallerPrincipal(), result.getCallerGroups());
        } else {
            
            return httpMessageContext.responseUnauthorized();
        }
    }

    return httpMessageContext.doNothing();
}
 
开发者ID:ivargrimstad,项目名称:security-samples,代码行数:23,代码来源:SimpleJSFAuthenticationMechanism.java


示例8: validate

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public CredentialValidationResult validate(UsernamePasswordCredential userCredential) {

        if (userCredential.compareTo("admin", "pwd1")) {
            return new CredentialValidationResult("admin", new HashSet<>(asList("admin", "user", "demo")));
        }

        return INVALID_RESULT;
    }
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:9,代码来源:LiteWeightIdentityStore.java


示例9: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest req, HttpServletResponse res, HttpMessageContext context) {

    CredentialValidationResult result = idStoreHandler.validate(
            new UsernamePasswordCredential(
                    req.getParameter("name"), req.getParameter("password")));

    if (result.getStatus() == VALID) {
        return context.notifyContainerAboutLogin(result);
    } else {
        return context.responseUnauthorized();
    }

}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:15,代码来源:LiteAuthenticationMechanism.java


示例10: validate

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public CredentialValidationResult validate(UsernamePasswordCredential usernamePasswordCredential) {

        // validate
        // ...
        if (usernamePasswordCredential.compareTo("duke", "helloWorld")) {
            return new CredentialValidationResult("duke", singleton("admin"));
        }

        return CredentialValidationResult.INVALID_RESULT;
    }
 
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:11,代码来源:TestIdentityStore.java


示例11: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext context) {

    LOGGER.log(Level.INFO, "validateRequest: {0}", request.getRequestURI());
    // Get the (caller) name and password from the request
    // NOTE: This is for the smallest possible example only. In practice
    // putting the password in a request query parameter is highly insecure
    String name = request.getParameter("username");
    String password = request.getParameter("password");
    String token = extractToken(context);

    if (name != null && password != null
        && "POST".equals(request.getMethod())
        && request.getRequestURI().endsWith("/auth/login")) {
        LOGGER.log(Level.INFO, "user credentials : {0}, {1}", new String[]{name, password});
        // validation of the credential using the identity store
        CredentialValidationResult result = identityStoreHandler.validate(new UsernamePasswordCredential(name, password));
        if (result.getStatus() == CredentialValidationResult.Status.VALID) {
            // Communicate the details of the authenticated user to the container and return SUCCESS.
            return createToken(result, context);
        }
        // if the authentication failed, we return the unauthorized status in the http response
        return context.responseUnauthorized();
    } else if (token != null) {
        // validation of the jwt credential
        return validateToken(token, context);
    } else if (context.isProtected()) {
        // A protected resource is a resource for which a constraint has been defined.
        // if there are no credentials and the resource is protected, we response with unauthorized status
        return context.responseUnauthorized();
    }
    // there are no credentials AND the resource is not protected, 
    // SO Instructs the container to "do nothing"
    return context.doNothing();
}
 
开发者ID:hantsy,项目名称:javaee8-jaxrs-sample,代码行数:36,代码来源:JwtAuthenticationMechanism.java


示例12: validate

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
public CredentialValidationResult validate(UsernamePasswordCredential usernamePasswordCredential) {

        if (usernamePasswordCredential.compareTo("user", "password")) {
            return new CredentialValidationResult("user", new HashSet<>(asList("foo", "bar")));
        }

        return INVALID_RESULT;
    }
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:9,代码来源:TestIdentityStore.java


示例13: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
    final String name = request.getParameter("name");
    final String pwd = request.getParameter("password");

    if (name != null && pwd != null ) {

        // Get the (caller) name and password from the request
        // NOTE: This is for the smallest possible example only. In practice
        // putting the password in a request query parameter is highly
        // insecure
        
        Password password = new Password(pwd);

        // Delegate the {credentials in -> identity data out} function to
        // the Identity Store
        CredentialValidationResult result = identityStoreHandler.validate(
                new UsernamePasswordCredential(name, password));

        if (result.getStatus() == VALID) {
            // Communicate the details of the authenticated user to the
            // container. In many cases the underlying handler will just store the details 
            // and the container will actually handle the login after we return from 
            // this method.
            return httpMessageContext.notifyContainerAboutLogin(
                    result.getCallerPrincipal(), result.getCallerGroups());
        }

        return httpMessageContext.responseUnauthorized();
    }

    return httpMessageContext.doNothing();
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:34,代码来源:TestAuthenticationMechanism.java


示例14: validateRequest

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {

    if (request.getParameter("name") != null && request.getParameter("password") != null) {

        // Get the (caller) name and password from the request
        // NOTE: This is for the smallest possible example only. In practice
        // putting the password in a request query parameter is highly
        // insecure
        String name = request.getParameter("name");
        Password password = new Password(request.getParameter("password"));

        // Delegate the {credentials in -> identity data out} function to
        // the Identity Store
        CredentialValidationResult result = identityStore.validate(
                new UsernamePasswordCredential(name, password));

        if (result.getStatus() == VALID) {
            // Communicate the details of the authenticated user to the
            // container. In many cases the underlying handler will just store the details 
            // and the container will actually handle the login after we return from 
            // this method.
            return httpMessageContext.notifyContainerAboutLogin(
                    result.getCallerPrincipal(), result.getCallerGroups());
        } else {
            return httpMessageContext.responseUnauthorized();
        }
    }

    return httpMessageContext.doNothing();
}
 
开发者ID:ivargrimstad,项目名称:security-samples,代码行数:32,代码来源:SimpleAuthenticationMechanism.java


示例15: validate

import javax.security.enterprise.credential.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {

    UsernamePasswordCredential user = (UsernamePasswordCredential) credential;
    
    if (user.getCaller().equalsIgnoreCase("Duke") && user.getPasswordAsString().equalsIgnoreCase("Dance")) {
    
       return new CredentialValidationResult("Duke",new HashSet<>(asList("foo", "bar")));
    }

    return INVALID_RESULT;
}
 
开发者ID:ivargrimstad,项目名称:security-samples,代码行数:13,代码来源:SimpleIdentityStore.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java OPTIONS类代码示例发布时间:2022-05-22
下一篇:
Java ExecutionStrategy类代码示例发布时间: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