Java源码示例:javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters

示例1
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String name = request.getParameter("name");
    if (null != name || !"".equals(name)) {
        AuthenticationStatus status = securityContext.authenticate(
                request, response, AuthenticationParameters.withParams().credential(new CallerOnlyCredential(name)));

        response.getWriter().write("Authentication status: " + status.name() + "\n");
    }

    String principal = null;
    if (request.getUserPrincipal() != null) {
        principal = request.getUserPrincipal().getName();
    }

    response.getWriter().write("User: " + principal + "\n");
    response.getWriter().write("Role \"role1\" access: " + request.isUserInRole("role1") + "\n");
    response.getWriter().write("Role \"role2\" access: " + request.isUserInRole("role2") + "\n");
    response.getWriter().write("Role \"role3\" access: " + request.isUserInRole("role3") + "\n");
    response.getWriter().write("Access to /authServlet? " + securityContext.hasAccessToWebResource("/authServlet") + "\n");
}
 
示例2
@Override
public AuthenticationStatus authenticate(final HttpServletRequest request,
                                         final HttpServletResponse response,
                                         final AuthenticationParameters parameters) {

    try {
        final MessageInfo messageInfo = new TomEEMessageInfo(request, response, true, parameters);
        final ServerAuthContext serverAuthContext = getServerAuthContext(request);
        final AuthStatus authStatus = serverAuthContext.validateRequest(messageInfo, new Subject(), null);

        return mapToAuthenticationStatus(authStatus);

    } catch (final AuthException e) {
        return AuthenticationStatus.SEND_FAILURE;
    }
}
 
示例3
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    final AuthenticationParameters parameters =
            AuthenticationParameters.withParams()
                                    .credential(new UsernamePasswordCredential(req.getParameter("username"),
                                                                               req.getParameter("password")))
                                    .newAuthentication(true);

    securityContext.authenticate(req, resp, parameters);

    final Principal callerPrincipal = securityContext.getCallerPrincipal();

    resp.getWriter().write(callerPrincipal.getName());
}
 
示例4
private AuthenticationStatus continueAuthentication() {
    return securityContext.authenticate(
            (HttpServletRequest) externalContext.getRequest(),
            (HttpServletResponse) externalContext.getResponse(),
            AuthenticationParameters.withParams().credential(new UsernamePasswordCredential(email, password))
    );
}
 
示例5
public TomEEMessageInfo(final HttpServletRequest request,
                        final HttpServletResponse response,
                        final boolean authMandatory,
                        final AuthenticationParameters authParameters) {
    super(request, response, authMandatory);
    getMap().put(AUTH_PARAMS, authParameters);
    getMap().put(AUTHENTICATE, Boolean.toString(true));
}
 
示例6
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    final AuthenticationParameters parameters =
            AuthenticationParameters.withParams()
                                    .credential(new UsernamePasswordCredential(req.getParameter("username"),
                                                                               req.getParameter("password")))
                                    .newAuthentication(true);

    securityContext.authenticate(req, resp, parameters);

    resp.getWriter().write("ok!");
}
 
示例7
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    final AuthenticationParameters parameters =
            AuthenticationParameters.withParams()
                                    .credential(new UsernamePasswordCredential(req.getParameter("username"),
                                                                               req.getParameter("password")))
                                    .newAuthentication(true);

    securityContext.authenticate(req, resp, parameters);

    resp.getWriter().write(securityContext.isCallerInRole(req.getParameter("role")) ? "ok" : "nok");
}
 
示例8
@Override
public AuthenticationParameters getAuthParameters() {
    return (AuthenticationParameters) messageInfo.getMap()
                                                 .getOrDefault(TomEEMessageInfo.AUTH_PARAMS,
                                                               new AuthenticationParameters());
}
 
示例9
AuthenticationStatus authenticate(HttpServletRequest request, HttpServletResponse response,
AuthenticationParameters parameters);