Search in sources :

Example 16 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testGetDate.

@Test
public void testGetDate() throws Exception {
    Message m = createMessage(createHeaders());
    HttpHeaders h = new HttpHeadersImpl(m);
    List<String> dateValues = h.getRequestHeader("Date");
    assertEquals(1, dateValues.size());
    assertEquals("Tue, 21 Oct 2008 17:00:00 GMT", dateValues.get(0));
    Date d = h.getDate();
    String theDateValue = HttpUtils.getHttpDateFormat().format(d);
    assertEquals(theDateValue, "Tue, 21 Oct 2008 17:00:00 GMT");
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) Date(java.util.Date) Test(org.junit.Test)

Example 17 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class WadlGenerator method doFilter.

protected void doFilter(ContainerRequestContext context, Message m) {
    if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
        return;
    }
    UriInfo ui = context.getUriInfo();
    if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
        if (stylesheetReference != null || !docLocationMap.isEmpty()) {
            String path = ui.getPath(false);
            if (path.startsWith("/") && !path.isEmpty()) {
                path = path.substring(1);
            }
            if (stylesheetReference != null && path.endsWith(".xsl") || docLocationMap.containsKey(path)) {
                context.abortWith(getExistingResource(m, ui, path));
            }
        }
        return;
    }
    if (ignoreRequests) {
        context.abortWith(Response.status(404).build());
        return;
    }
    if (allowList != null && !allowList.isEmpty()) {
        ServletRequest servletRequest = (ServletRequest) m.getContextualProperty("HTTP.REQUEST");
        final String remoteAddress;
        if (servletRequest != null) {
            remoteAddress = servletRequest.getRemoteAddr();
        } else {
            remoteAddress = "";
        }
        boolean foundMatch = false;
        for (String addr : allowList) {
            if (addr.equals(remoteAddress)) {
                foundMatch = true;
                break;
            }
        }
        if (!foundMatch) {
            context.abortWith(Response.status(404).build());
            return;
        }
    }
    HttpHeaders headers = new HttpHeadersImpl(m);
    List<MediaType> accepts = headers.getAcceptableMediaTypes();
    MediaType type = accepts.contains(WADL_TYPE) ? WADL_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE : defaultWadlResponseMediaType;
    Response response = getExistingWadl(m, ui, type);
    if (response != null) {
        context.abortWith(response);
        return;
    }
    boolean isJson = isJson(type);
    StringBuilder sbMain = generateWADL(getBaseURI(m, ui), getResourcesList(m, ui), isJson, m, ui);
    m.getExchange().put(JAXRSUtils.IGNORE_MESSAGE_WRITERS, !isJson && ignoreMessageWriters);
    Response r = Response.ok().type(type).entity(createResponseEntity(m, ui, sbMain.toString(), isJson)).build();
    context.abortWith(r);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ServletRequest(javax.servlet.ServletRequest) HttpHeaders(javax.ws.rs.core.HttpHeaders) MediaType(javax.ws.rs.core.MediaType) UriInfo(javax.ws.rs.core.UriInfo) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 18 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.

the class UserInfoEndpoint method issueUserInfoPost.

@Path("/")
@POST
@NoCache
public Response issueUserInfoPost() {
    // Try header first
    HttpHeaders headers = request.getHttpHeaders();
    String accessToken = this.appAuthManager.extractAuthorizationHeaderTokenOrReturnNull(headers);
    // Fallback to form parameter
    if (accessToken == null) {
        accessToken = request.getDecodedFormParameters().getFirst("access_token");
    }
    return issueUserInfo(accessToken);
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 19 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.

the class AuthenticationManager method browserLogoutAllClients.

private static Response browserLogoutAllClients(UserSessionModel userSession, KeycloakSession session, RealmModel realm, HttpHeaders headers, UriInfo uriInfo, AuthenticationSessionModel logoutAuthSession) {
    Map<Boolean, List<AuthenticatedClientSessionModel>> acss = userSession.getAuthenticatedClientSessions().values().stream().filter(clientSession -> !Objects.equals(AuthenticationSessionModel.Action.LOGGED_OUT.name(), clientSession.getAction()) && !Objects.equals(AuthenticationSessionModel.Action.LOGGING_OUT.name(), clientSession.getAction())).filter(clientSession -> clientSession.getProtocol() != null).collect(Collectors.partitioningBy(clientSession -> clientSession.getClient().isFrontchannelLogout()));
    final List<AuthenticatedClientSessionModel> backendLogoutSessions = acss.get(false) == null ? Collections.emptyList() : acss.get(false);
    backendLogoutSessions.forEach(acs -> backchannelLogoutClientSession(session, realm, acs, logoutAuthSession, uriInfo, headers));
    final List<AuthenticatedClientSessionModel> redirectClients = acss.get(true) == null ? Collections.emptyList() : acss.get(true);
    for (AuthenticatedClientSessionModel nextRedirectClient : redirectClients) {
        Response response = frontchannelLogoutClientSession(session, realm, nextRedirectClient, logoutAuthSession, uriInfo, headers);
        if (response != null) {
            return response;
        }
    }
    return null;
}
Also used : DefaultClientSessionContext(org.keycloak.services.util.DefaultClientSessionContext) ActionTokenStoreProvider(org.keycloak.models.ActionTokenStoreProvider) Error(org.keycloak.protocol.LoginProtocol.Error) ErrorResponseException(org.keycloak.services.ErrorResponseException) Map(java.util.Map) ClientConnection(org.keycloak.common.ClientConnection) UriBuilder(javax.ws.rs.core.UriBuilder) Time(org.keycloak.common.util.Time) AuthenticationSessionModel(org.keycloak.sessions.AuthenticationSessionModel) AuthenticationProcessor(org.keycloak.authentication.AuthenticationProcessor) Set(java.util.Set) AbstractUsernameFormAuthenticator(org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator) SecretGenerator(org.keycloak.common.util.SecretGenerator) Stream(java.util.stream.Stream) AuthenticationFlowException(org.keycloak.authentication.AuthenticationFlowException) SessionTimeoutHelper(org.keycloak.models.utils.SessionTimeoutHelper) LoginActionsService(org.keycloak.services.resources.LoginActionsService) UriInfo(javax.ws.rs.core.UriInfo) OAuth2Constants(org.keycloak.OAuth2Constants) LoginProtocol(org.keycloak.protocol.LoginProtocol) Constants(org.keycloak.models.Constants) TokenManager(org.keycloak.protocol.oidc.TokenManager) TokenUtil(org.keycloak.util.TokenUtil) UserModel(org.keycloak.models.UserModel) ClientSessionContext(org.keycloak.models.ClientSessionContext) Predicate(org.keycloak.TokenVerifier.Predicate) TokenVerifier(org.keycloak.TokenVerifier) CommonClientSessionModel(org.keycloak.sessions.CommonClientSessionModel) Base64Url(org.keycloak.common.util.Base64Url) BackchannelLogoutResponse(org.keycloak.protocol.oidc.BackchannelLogoutResponse) AuthenticationFlowError(org.keycloak.authentication.AuthenticationFlowError) ConsoleDisplayMode(org.keycloak.authentication.ConsoleDisplayMode) IdentityBrokerService(org.keycloak.services.resources.IdentityBrokerService) KeycloakSession(org.keycloak.models.KeycloakSession) AuthorizationDetails(org.keycloak.rar.AuthorizationDetails) HttpRequest(org.jboss.resteasy.spi.HttpRequest) EventType(org.keycloak.events.EventType) P3PHelper(org.keycloak.services.util.P3PHelper) RequiredActionProvider(org.keycloak.authentication.RequiredActionProvider) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) LoginFormsProvider(org.keycloak.forms.login.LoginFormsProvider) URLDecoder(java.net.URLDecoder) ActionTokenKeyModel(org.keycloak.models.ActionTokenKeyModel) RequiredActionContextResult(org.keycloak.authentication.RequiredActionContextResult) RequiredActionFactory(org.keycloak.authentication.RequiredActionFactory) NewCookie(javax.ws.rs.core.NewCookie) Messages(org.keycloak.services.messages.Messages) DefaultActionTokenKey(org.keycloak.authentication.actiontoken.DefaultActionTokenKey) SignatureVerifierContext(org.keycloak.crypto.SignatureVerifierContext) AccessToken(org.keycloak.representations.AccessToken) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel) URI(java.net.URI) SystemClientUtil(org.keycloak.models.utils.SystemClientUtil) VerificationException(org.keycloak.common.VerificationException) DeviceGrantType.isOAuth2DeviceVerificationFlow(org.keycloak.protocol.oidc.grants.device.DeviceGrantType.isOAuth2DeviceVerificationFlow) ClientScopeModel(org.keycloak.models.ClientScopeModel) RealmModel(org.keycloak.models.RealmModel) InitiatedActionSupport(org.keycloak.authentication.InitiatedActionSupport) AuthenticatorUtil(org.keycloak.authentication.AuthenticatorUtil) Collectors(java.util.stream.Collectors) Cookie(javax.ws.rs.core.Cookie) Objects(java.util.Objects) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Details(org.keycloak.events.Details) RootAuthenticationSessionModel(org.keycloak.sessions.RootAuthenticationSessionModel) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) ClientModel(org.keycloak.models.ClientModel) RealmsResource(org.keycloak.services.resources.RealmsResource) Profile(org.keycloak.common.Profile) SameSiteAttributeValue(org.keycloak.common.util.ServerCookie.SameSiteAttributeValue) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) Logger(org.jboss.logging.Logger) ServicesLogger(org.keycloak.services.ServicesLogger) TokenTypeCheck(org.keycloak.TokenVerifier.TokenTypeCheck) RequiredActionContext(org.keycloak.authentication.RequiredActionContext) SignatureProvider(org.keycloak.crypto.SignatureProvider) EventBuilder(org.keycloak.events.EventBuilder) CookieHelper(org.keycloak.services.util.CookieHelper) UserConsentModel(org.keycloak.models.UserConsentModel) OIDCAdvancedConfigWrapper(org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper) LinkedList(java.util.LinkedList) DisplayTypeRequiredActionFactory(org.keycloak.authentication.DisplayTypeRequiredActionFactory) IdentityProvider(org.keycloak.broker.provider.IdentityProvider) Errors(org.keycloak.events.Errors) CORRESPONDING_SESSION_ID(org.keycloak.models.UserSessionModel.CORRESPONDING_SESSION_ID) UserSessionModel(org.keycloak.models.UserSessionModel) AuthorizationContextUtil(org.keycloak.services.util.AuthorizationContextUtil) URLEncoder(java.net.URLEncoder) LogoutRequestContext(org.keycloak.services.clientpolicy.context.LogoutRequestContext) CookieHelper.getCookie(org.keycloak.services.util.CookieHelper.getCookie) Urls(org.keycloak.services.Urls) Collections(java.util.Collections) BackchannelLogoutResponse(org.keycloak.protocol.oidc.BackchannelLogoutResponse) Response(javax.ws.rs.core.Response) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel) List(java.util.List) LinkedList(java.util.LinkedList)

Example 20 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.

the class DefaultLocaleSelectorProvider method resolveLocale.

@Override
public Locale resolveLocale(RealmModel realm, UserModel user) {
    HttpHeaders requestHeaders = session.getContext().getRequestHeaders();
    AuthenticationSessionModel session = this.session.getContext().getAuthenticationSession();
    if (!realm.isInternationalizationEnabled()) {
        return Locale.ENGLISH;
    }
    Locale userLocale = getUserLocale(realm, session, user, requestHeaders);
    if (userLocale != null) {
        return userLocale;
    }
    String realmDefaultLocale = realm.getDefaultLocale();
    if (realmDefaultLocale != null) {
        return Locale.forLanguageTag(realmDefaultLocale);
    }
    return Locale.ENGLISH;
}
Also used : Locale(java.util.Locale) HttpHeaders(javax.ws.rs.core.HttpHeaders) AuthenticationSessionModel(org.keycloak.sessions.AuthenticationSessionModel)

Aggregations

HttpHeaders (javax.ws.rs.core.HttpHeaders)95 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 Optional (java.util.Optional)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 UriInfo (javax.ws.rs.core.UriInfo)12 CatalogFramework (ddf.catalog.CatalogFramework)10 Locale (java.util.Locale)10 Response (javax.ws.rs.core.Response)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 MediaType (javax.ws.rs.core.MediaType)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Map (java.util.Map)8 Cookie (javax.ws.rs.core.Cookie)8 IOException (java.io.IOException)7 Collections (java.util.Collections)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URI (java.net.URI)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6