javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters Java Examples

The following examples show how to use javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserAuthenticationServlet.java    From javaee8-cookbook with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #2
Source File: TomEESecurityContext.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example #3
Source File: SecurityContextTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: LoginBacking.java    From blog-tutorials with MIT License 5 votes vote down vote up
private AuthenticationStatus continueAuthentication() {
    return securityContext.authenticate(
            (HttpServletRequest) externalContext.getRequest(),
            (HttpServletResponse) externalContext.getResponse(),
            AuthenticationParameters.withParams().credential(new UsernamePasswordCredential(email, password))
    );
}
 
Example #5
Source File: TomEEMessageInfo.java    From tomee with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #6
Source File: SecurityContextTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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!");
}
 
Example #7
Source File: SecurityContextTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #8
Source File: TomEEHttpMessageContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public AuthenticationParameters getAuthParameters() {
    return (AuthenticationParameters) messageInfo.getMap()
                                                 .getOrDefault(TomEEMessageInfo.AUTH_PARAMS,
                                                               new AuthenticationParameters());
}
 
Example #9
Source File: SecurityContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
AuthenticationStatus authenticate(HttpServletRequest request, HttpServletResponse response,
AuthenticationParameters parameters);