congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
HttpMessageContext
Code IndexAdd Tabnine to your IDE (free)

How to use
HttpMessageContext
in
javax.security.enterprise.authentication.mechanism.http

Best Java code snippets using javax.security.enterprise.authentication.mechanism.http.HttpMessageContext (Showing top 20 results out of 315)

origin: javax/javaee-web-api

@Override
public AuthenticationStatus doNothing() {
  return getWrapped().doNothing();
}
origin: org.glassfish.soteria/javax.security.enterprise

private boolean isOnInitialProtectedURL(HttpMessageContext httpMessageContext) {
  return 
    httpMessageContext.isProtected() &&
    
    // When HttpServletRequest#authenticate is called, it counts as "mandated" authentication
    // which here means isProtected() is true. But we want to use HttpServletRequest#authenticate
    // to resume a dialog started by accessing a protected page, so therefore exclude it here.
    !httpMessageContext.isAuthenticationRequest() &&
    getSavedRequest(httpMessageContext.getRequest()) == null && 
    getSavedAuthentication(httpMessageContext.getRequest()) == null &&
        
    // Some servers consider the Servlet special URL "/j_security_check" as
    // a protected URL
    !httpMessageContext.getRequest().getRequestURI().endsWith("j_security_check");
}

origin: javax/javaee-web-api

@Override
public HttpServletResponse getResponse() {
  return getWrapped().getResponse();
}
origin: org.glassfish.soteria/javax.security.enterprise

private AuthenticationStatus processCallerInitiatedAuthentication(InvocationContext invocationContext, HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws Exception {
  // Try to authenticate with the next interceptor or actual authentication mechanism
  AuthenticationStatus authstatus;
  
  try {
    authstatus = (AuthenticationStatus) invocationContext.proceed();
  } catch (AuthException e) {
    authstatus = AuthenticationStatus.SEND_FAILURE;
  }
  
  if (authstatus == AuthenticationStatus.SUCCESS) {
    
    if (httpMessageContext.getCallerPrincipal() == null) {
      return AuthenticationStatus.SUCCESS;
    }
    
    // Actually authenticated now, so we remove the authentication dialog marker
    removeCallerInitiatedAuthentication(httpMessageContext.getRequest());
    
    // TODO: for some mechanisms, such as OAuth the caller would now likely be at an
    // application OAuth landing page, and should likely be returned to "some other" location
    // (e.g. the page from which a login link was clicked in say a top menu bar)
    //
    // Do we add support for this, e.g. via a watered down savedRequest (saving only a caller provided URL)
    // Or do we leave this as an application responsibility?
  }
  
  return authstatus;
}

origin: org.glassfish.soteria/javax.security.enterprise

private void tryClean(HttpMessageContext httpMessageContext) {
  
  // 1. Check if caller aborted earlier flow and does a new request to protected resource
  if (isOnProtectedURLWithStaleData(httpMessageContext)) {
    removeSavedRequest(httpMessageContext.getRequest());
    removeCallerInitiatedAuthentication(httpMessageContext.getRequest());
  }
  
  // 2. Check if caller aborted earlier flow and explicitly initiated a new authentication dialog 
  if (httpMessageContext.getAuthParameters().isNewAuthentication()) {
    saveCallerInitiatedAuthentication(httpMessageContext.getRequest());
    removeSavedRequest(httpMessageContext.getRequest());
    removeSavedAuthentication(httpMessageContext.getRequest());
  }
}

origin: org.glassfish.soteria/javax.security.enterprise

  return httpMessageContext.forward(
    loginToContinueAnnotation.loginPage());
} else {
  return httpMessageContext.redirect(
    getBaseURL(request) + loginToContinueAnnotation.loginPage());
  if (httpMessageContext.getCallerPrincipal() == null) {
    return AuthenticationStatus.SUCCESS;
        httpMessageContext.getCallerPrincipal(),
        httpMessageContext.getGroups()));
    return httpMessageContext.redirect(savedRequest.getFullRequestURL());
  return httpMessageContext.redirect( // TODO: optionally forward?
    getBaseURL(request) + errorPage);
} else {
  .withRequest(new HttpServletRequestDelegator(request, requestData))
  .notifyContainerAboutLogin(
    authenticationData.getPrincipal(), 
    authenticationData.getGroups());
origin: javaee/security-soteria

@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMsgContext) throws AuthenticationException {
  String[] credentials = getCredentials(request);
  if (!isEmpty(credentials)) {
    IdentityStoreHandler identityStoreHandler = CDI.current().select(IdentityStoreHandler.class).get();
    CredentialValidationResult result = identityStoreHandler.validate(
        new UsernamePasswordCredential(credentials[0], new Password(credentials[1])));
    if (result.getStatus() == VALID) {
      return httpMsgContext.notifyContainerAboutLogin(
        result.getCallerPrincipal(), result.getCallerGroups());
    }
  }
  if (httpMsgContext.isProtected()) {
    response.setHeader("WWW-Authenticate", format("Basic realm=\"%s\"", basicAuthenticationMechanismDefinition.realmName()));
    return httpMsgContext.responseUnauthorized();
  }
  return httpMsgContext.doNothing();
}
origin: javaee/security-soteria

@SuppressWarnings("unchecked")
@AroundInvoke
public Object intercept(InvocationContext invocationContext) throws Exception {
  
  if (isImplementationOf(invocationContext.getMethod(), validateRequestMethod)) {
    
    HttpMessageContext httpMessageContext = (HttpMessageContext)invocationContext.getParameters()[2];
    
    Principal userPrincipal = getPrincipal(httpMessageContext.getRequest());
    
    if (userPrincipal != null) {
      
      httpMessageContext.getHandler().handle(new Callback[] { 
        new CallerPrincipalCallback(httpMessageContext.getClientSubject(), userPrincipal) }
      );
                 return SUCCESS;
    }
    
    Object outcome = invocationContext.proceed();
    
    if (SUCCESS.equals(outcome)) {
      httpMessageContext.getMessageInfo().getMap().put("javax.servlet.http.registerSession", TRUE.toString());
    }
    
    return outcome;
  }
  
  return invocationContext.proceed();
}
origin: javaee/security-soteria

/**
 * Called in response to a {@link HttpServletRequest#logout()} call.
 *
 */
@Override
public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException {
  HttpMessageContext msgContext = new HttpMessageContextImpl(handler, messageInfo, subject);
  
  CDI.current()
    .select(HttpAuthenticationMechanism.class).get()
    .cleanSubject(msgContext.getRequest(), msgContext.getResponse(), msgContext);
}
origin: javaee-samples/javaee8-samples

  return context.responseUnauthorized();
} else if (token != null) {
} else if (context.isProtected()) {
  return context.responseUnauthorized();
return context.doNothing();
origin: org.glassfish.soteria/javax.security.enterprise

@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
  
  if (hasCredential(httpMessageContext)) {
    IdentityStoreHandler identityStoreHandler = CDI.current().select(IdentityStoreHandler.class).get();
    
    return httpMessageContext.notifyContainerAboutLogin(
        identityStoreHandler.validate(
        httpMessageContext.getAuthParameters()
                 .getCredential()));
  }
  
  return httpMessageContext.doNothing();
}

origin: org.glassfish.soteria/javax.security.enterprise

    return httpMessageContext.notifyContainerAboutLogin(
      result.getCallerPrincipal(), result.getCallerGroups());
  } else {
if (authstatus == AuthenticationStatus.SUCCESS && httpMessageContext.getCallerPrincipal() != null) {
      toCallerPrincipal(httpMessageContext.getCallerPrincipal()),
      httpMessageContext.getGroups()
    );
origin: javax/javaee-web-api

@Override
public AuthenticationStatus notifyContainerAboutLogin(CredentialValidationResult result) {
  return getWrapped().notifyContainerAboutLogin(result);
}
origin: org.glassfish.soteria/javax.security.enterprise

@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
  
  if (isValidFormPostback(request)) {
    IdentityStoreHandler identityStoreHandler = CDI.current().select(IdentityStoreHandler.class).get();
    
    return httpMessageContext.notifyContainerAboutLogin(
        identityStoreHandler.validate(
        new UsernamePasswordCredential(
          request.getParameter("j_username"), 
          new Password(request.getParameter("j_password")))));
  }
  
  return httpMessageContext.doNothing();
}

origin: javaee-samples/javaee8-samples

/**
 * To validate the JWT token e.g Signature check, JWT claims
 * check(expiration) etc
 *
 * @param token The JWT access tokens
 * @param context
 * @return the AuthenticationStatus to notify the container
 */
private AuthenticationStatus validateToken(String token, HttpMessageContext context) {
  try {
    if (tokenProvider.validateToken(token)) {
      JWTCredential credential = tokenProvider.getCredential(token);
      return context.notifyContainerAboutLogin(credential.getPrincipal(), credential.getAuthorities());
    }
    // if token invalid, response with unauthorized status
    return context.responseUnauthorized();
  } catch (ExpiredJwtException eje) {
    LOGGER.log(Level.INFO, "Security exception for user {0} - {1}", new String[]{eje.getClaims().getSubject(), eje.getMessage()});
    return context.responseUnauthorized();
  }
}
origin: javaee-samples/javaee8-samples

/**
 * Create the JWT using CredentialValidationResult received from
 * IdentityStoreHandler
 *
 * @param result the result from validation of UsernamePasswordCredential
 * @param context
 * @return the AuthenticationStatus to notify the container
 */
private AuthenticationStatus createToken(CredentialValidationResult result, HttpMessageContext context) {
  if (!isRememberMe(context)) {
    String jwt = tokenProvider.createToken(result.getCallerPrincipal().getName(), result.getCallerGroups(), false);
    context.getResponse().setHeader(AUTHORIZATION_HEADER, BEARER + jwt);
  }
  return context.notifyContainerAboutLogin(result.getCallerPrincipal(), result.getCallerGroups());
}
origin: javaee-samples/javaee8-samples

/**
 * this function invoked using RememberMe.isRememberMeExpression EL
 * expression
 *
 * @param context
 * @return The remember me flag
 */
public Boolean isRememberMe(HttpMessageContext context) {
  return Boolean.valueOf(context.getRequest().getParameter("rememberme"));
}
origin: javax/javaee-web-api

@Override
public AuthenticationParameters getAuthParameters() {
  return getWrapped().getAuthParameters();
}
origin: javax/javaee-web-api

@Override
public AuthenticationStatus responseUnauthorized() {
  return getWrapped().responseUnauthorized();
}
origin: javax/javaee-web-api

@Override
public boolean isProtected() {
  return getWrapped().isProtected();
}
javax.security.enterprise.authentication.mechanism.httpHttpMessageContext

Javadoc

HttpMessageContext contains all of the per-request state information and encapsulates the client request, server response, container handler for authentication callbacks, and the subject representing the caller.

Most used methods

  • doNothing
    Instructs the container to "do nothing". When intending to do nothing, a JSR 375 authentication mech
  • getRequest
    Returns the request object associated with the current request.
  • getResponse
    Returns the response object associated with the current request.
  • isProtected
    Checks if the currently requested resource is protected or not. A protected resource is a resource (
  • notifyContainerAboutLogin
    Convenience method intended to pass the CredentialValidationResult result of an identity store direc
  • responseUnauthorized
    Sets the response status to 401 (unauthorized). As a convenience this method returns SEND_FAILURE, s
  • forward
    Forwards to another resource (servlet, JSP file, or HTML file) on the server. As a convenience this
  • getAuthParameters
    Returns the parameters that were provided with the SecurityContext#authenticate(AuthParameters) call
  • getCallerPrincipal
    Gets the Principal set by a call to notifyContainerAboutLogin().
  • getClientSubject
    Returns the subject for which authentication is to take place.Note: This is a low level object that
  • getGroups
    Gets the groups set by a call to notifyContainerAboutLogin().
  • getHandler
    Returns the low level JSR 196 handler that the runtime provided when creating this HttpMessageContex
  • getGroups,
  • getHandler,
  • getMessageInfo,
  • isAuthenticationRequest,
  • redirect,
  • withRequest,
  • cleanClientSubject,
  • isRegisterSession,
  • responseNotFound,
  • setRegisterSession

Popular in Java

  • Creating JSON documents from java classes using gson
  • runOnUiThread (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • compareTo (BigDecimal)
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • ImageIO (javax.imageio)
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JButton (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now