Search in sources :

Example 61 with HttpServletResponse

use of javax.servlet.http.HttpServletResponse in project cas by apereo.

the class ServiceWarningAction method doExecute.

@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    final Service service = WebUtils.getService(context);
    final String ticketGrantingTicket = WebUtils.getTicketGrantingTicketId(context);
    final Authentication authentication = this.ticketRegistrySupport.getAuthenticationFrom(ticketGrantingTicket);
    if (authentication == null) {
        throw new InvalidTicketException(new AuthenticationException("No authentication found for ticket " + ticketGrantingTicket), ticketGrantingTicket);
    }
    final Credential credential = WebUtils.getCredential(context);
    final AuthenticationResultBuilder authenticationResultBuilder = authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication, credential);
    final AuthenticationResult authenticationResult = authenticationResultBuilder.build(service);
    final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicket, service, authenticationResult);
    WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
    if (request.getParameterMap().containsKey("ignorewarn")) {
        if (Boolean.valueOf(request.getParameter("ignorewarn").toString())) {
            this.warnCookieGenerator.removeCookie(response);
        }
    }
    return new Event(this, CasWebflowConstants.STATE_ID_REDIRECT);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Authentication(org.apereo.cas.authentication.Authentication) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) HttpServletResponse(javax.servlet.http.HttpServletResponse) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) Event(org.springframework.webflow.execution.Event) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 62 with HttpServletResponse

use of javax.servlet.http.HttpServletResponse in project cas by apereo.

the class BasicAuthenticationAction method constructCredentialsFromRequest.

@Override
protected Credential constructCredentialsFromRequest(final RequestContext requestContext) {
    try {
        final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
        final HttpServletResponse response = WebUtils.getHttpServletResponse(requestContext);
        final BasicAuthExtractor extractor = new BasicAuthExtractor(this.getClass().getSimpleName());
        final WebContext webContext = WebUtils.getPac4jJ2EContext(request, response);
        final UsernamePasswordCredentials credentials = extractor.extract(webContext);
        if (credentials != null) {
            LOGGER.debug("Received basic authentication request from credentials [{}]", credentials);
            return new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
        }
    } catch (final Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BasicAuthExtractor(org.pac4j.core.credentials.extractor.BasicAuthExtractor) WebContext(org.pac4j.core.context.WebContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials)

Example 63 with HttpServletResponse

use of javax.servlet.http.HttpServletResponse in project cas by apereo.

the class FrontChannelLogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) throws Exception {
    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
    final Map<LogoutRequest, LogoutHttpMessage> logoutUrls = new HashMap<>();
    if (logoutRequests != null) {
        logoutRequests.stream().filter(r -> r.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED).forEach(r -> {
            LOGGER.debug("Using logout url [{}] for front-channel logout requests", r.getLogoutUrl().toExternalForm());
            final String logoutMessage = this.logoutManager.createFrontChannelLogoutMessage(r);
            LOGGER.debug("Front-channel logout message to send is [{}]", logoutMessage);
            final LogoutHttpMessage msg = new LogoutHttpMessage(r.getLogoutUrl(), logoutMessage, true);
            logoutUrls.put(r, msg);
            r.setStatus(LogoutRequestStatus.SUCCESS);
            r.getService().setLoggedOutAlready(true);
        });
        if (!logoutUrls.isEmpty()) {
            context.getFlowScope().put("logoutUrls", logoutUrls);
            return new EventFactorySupport().event(this, "propagate");
        }
    }
    return new EventFactorySupport().event(this, FINISH_EVENT);
}
Also used : LogoutManager(org.apereo.cas.logout.LogoutManager) LogoutRequest(org.apereo.cas.logout.LogoutRequest) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogoutRequestStatus(org.apereo.cas.logout.LogoutRequestStatus) HashMap(java.util.HashMap) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) RequestContext(org.springframework.webflow.execution.RequestContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Map(java.util.Map) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) HashMap(java.util.HashMap) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) LogoutRequest(org.apereo.cas.logout.LogoutRequest) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 64 with HttpServletResponse

use of javax.servlet.http.HttpServletResponse in project che by eclipse.

the class CacheDisablingFilter method doFilter.

/** {@inheritDoc} */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (response instanceof HttpServletResponse) {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        Date now = new Date();
        httpResponse.setDateHeader("Date", now.getTime());
        httpResponse.setDateHeader("Expires", now.getTime() + ONE_DAY_IN_MILISECONDS);
        httpResponse.setHeader("Pragma", "no-cache");
        httpResponse.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
    }
    chain.doFilter(request, response);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Date(java.util.Date)

Example 65 with HttpServletResponse

use of javax.servlet.http.HttpServletResponse in project che by eclipse.

the class CacheForcingFilter method doFilter.

/** {@inheritDoc} */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (response instanceof HttpServletResponse) {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        Date now = new Date();
        httpResponse.setDateHeader("Date", now.getTime());
        httpResponse.setDateHeader("Expires", now.getTime() + ONE_MONTH_IN_MILISECONDS);
        httpResponse.setHeader("Pragma", "no-cache");
        httpResponse.setHeader("Cache-control", "public, max-age=" + ONE_MONTH_IN_SECONDS);
    }
    chain.doFilter(request, response);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Date(java.util.Date)

Aggregations

HttpServletResponse (javax.servlet.http.HttpServletResponse)1635 HttpServletRequest (javax.servlet.http.HttpServletRequest)1312 Test (org.junit.Test)705 IOException (java.io.IOException)576 ServletException (javax.servlet.ServletException)491 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)223 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)195 Request (org.eclipse.jetty.server.Request)186 HttpServlet (javax.servlet.http.HttpServlet)157 CountDownLatch (java.util.concurrent.CountDownLatch)156 FilterChain (javax.servlet.FilterChain)148 PrintWriter (java.io.PrintWriter)138 Test (org.testng.annotations.Test)127 HashMap (java.util.HashMap)106 ServletOutputStream (javax.servlet.ServletOutputStream)105 InterruptedIOException (java.io.InterruptedIOException)97 InputStream (java.io.InputStream)85 OutputStream (java.io.OutputStream)81 HttpSession (javax.servlet.http.HttpSession)75 ServletResponse (javax.servlet.ServletResponse)74