KEYCLOAK-5119 (#4400)

This commit is contained in:
Stian Thorgersen 2017-08-22 08:07:36 +02:00 committed by GitHub
parent b5ed8961f7
commit 20ac70d3fd
9 changed files with 40 additions and 55 deletions

View file

@ -22,7 +22,6 @@ import org.keycloak.services.resource.RealmResourceProvider;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
@ -41,7 +40,7 @@ public class HelloResourceProvider implements RealmResourceProvider {
}
@GET
@Produces(MediaType.TEXT_PLAIN)
@Produces("text/plain; charset=utf-8")
public String get() {
String name = session.getContext().getRealm().getDisplayName();
if (name == null) {

View file

@ -58,6 +58,7 @@ import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.resources.RealmsResource;
import org.keycloak.services.util.CacheControlUtil;
import org.keycloak.utils.MediaType;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
@ -67,7 +68,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
@ -594,7 +594,7 @@ public class SamlService extends AuthorizationEndpointBase {
@GET
@Path("clients/{client}")
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML_UTF_8)
public Response idpInitiatedSSO(@PathParam("client") String clientUrlName, @QueryParam("RelayState") String relayState) {
event.event(EventType.LOGIN);
CacheControlUtil.noBackButtonCacheControlHeader();

View file

@ -59,9 +59,9 @@ import org.keycloak.services.validation.Validation;
import org.keycloak.sessions.AuthenticationSessionModel;
import org.keycloak.storage.ReadOnlyException;
import org.keycloak.util.JsonSerialization;
import org.keycloak.utils.MediaType;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
@ -252,20 +252,8 @@ public class AccountService extends AbstractSecuredLocalService {
*/
@Path("/")
@GET
@Produces(MediaType.TEXT_HTML)
public Response accountPage() {
return forwardToPage(null, AccountPages.ACCOUNT);
}
/**
* Get account information.
*
* @return
*/
@Path("/")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response accountPageJson() {
if (session.getContext().getRequestHeaders().getAcceptableMediaTypes().contains(MediaType.APPLICATION_JSON_TYPE)) {
requireOneOf(AccountRoles.MANAGE_ACCOUNT, AccountRoles.VIEW_PROFILE);
UserRepresentation rep = ModelToRepresentation.toRepresentation(session, realm, auth.getUser());
@ -278,7 +266,10 @@ public class AccountService extends AbstractSecuredLocalService {
}
}
return Cors.add(request, Response.ok(rep)).auth().allowedOrigins(auth.getToken()).build();
return Cors.add(request, Response.ok(rep).type(MediaType.APPLICATION_JSON_TYPE)).auth().allowedOrigins(auth.getToken()).build();
} else {
return forwardToPage(null, AccountPages.ACCOUNT);
}
}
public static UriBuilder totpUrl(UriBuilder base) {

View file

@ -40,4 +40,8 @@ public class MediaType {
public static final String APPLICATION_JWT = "application/jwt";
public static final javax.ws.rs.core.MediaType APPLICATION_JWT_TYPE = new javax.ws.rs.core.MediaType("application", "jwt");
public static final String APPLICATION_XML = javax.ws.rs.core.MediaType.APPLICATION_XML;
public static final String TEXT_XML = javax.ws.rs.core.MediaType.TEXT_XML;
}

View file

@ -17,7 +17,6 @@
package org.keycloak.testsuite.rest;
import org.jboss.resteasy.annotations.Query;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
@ -30,6 +29,7 @@ import org.keycloak.representations.adapters.action.TestAvailabilityAction;
import org.keycloak.services.resource.RealmResourceProvider;
import org.keycloak.services.resources.RealmsResource;
import org.keycloak.testsuite.rest.resource.TestingOIDCEndpointsApplicationResource;
import org.keycloak.utils.MediaType;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -38,7 +38,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
@ -69,21 +68,21 @@ public class TestApplicationResourceProvider implements RealmResourceProvider {
}
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
@Path("/admin/k_logout")
public void adminLogout(String data) throws JWSInputException {
adminLogoutActions.add(new JWSInput(data).readJsonContent(LogoutAction.class));
}
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
@Path("/admin/k_push_not_before")
public void adminPushNotBefore(String data) throws JWSInputException {
adminPushNotBeforeActions.add(new JWSInput(data).readJsonContent(PushNotBeforeAction.class));
}
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
@Path("/admin/k_test_available")
public void testAvailable(String data) throws JWSInputException {
adminTestAvailabilityAction.add(new JWSInput(data).readJsonContent(TestAvailabilityAction.class));
@ -119,7 +118,7 @@ public class TestApplicationResourceProvider implements RealmResourceProvider {
}
@POST
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML_UTF_8)
@Path("/{action}")
public String post(@PathParam("action") String action) {
String title = "APP_REQUEST";
@ -148,7 +147,7 @@ public class TestApplicationResourceProvider implements RealmResourceProvider {
}
@GET
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML_UTF_8)
@Path("/{action}")
public String get(@PathParam("action") String action) {
//String requestUri = session.getContext().getUri().getRequestUri().toString();
@ -171,7 +170,7 @@ public class TestApplicationResourceProvider implements RealmResourceProvider {
@GET
@NoCache
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML_UTF_8)
@Path("/get-account-profile")
public String getAccountProfile(@QueryParam("token") String token, @QueryParam("account-uri") String accountUri) {
StringBuilder sb = new StringBuilder();

View file

@ -27,18 +27,17 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.infinispan.Cache;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.remoting.transport.Transport;
import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
import org.jgroups.JChannel;
import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity;
import org.keycloak.models.sessions.infinispan.util.InfinispanUtil;
import org.keycloak.testsuite.rest.representation.JGroupsStats;
import org.keycloak.utils.MediaType;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -82,7 +81,7 @@ public class TestCacheResource {
@GET
@Path("/clear")
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
public void clear() {
cache.clear();
}

View file

@ -17,18 +17,16 @@
package org.keycloak.testsuite.client.resources;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.keycloak.representations.adapters.action.LogoutAction;
import org.keycloak.representations.adapters.action.PushNotBeforeAction;
import org.keycloak.representations.adapters.action.TestAvailabilityAction;
import org.keycloak.utils.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
@ -56,7 +54,7 @@ public interface TestApplicationResource {
void clearAdminActions();
@GET
@Produces(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_HTML_UTF_8)
@Path("/get-account-profile")
String getAccountProfile(@QueryParam("token") String token, @QueryParam("account-uri") String accountUri);

View file

@ -17,18 +17,16 @@
package org.keycloak.testsuite.client.resources;
import java.util.Map;
import java.util.Set;
import org.keycloak.testsuite.rest.representation.JGroupsStats;
import org.keycloak.testsuite.rest.representation.RemoteCacheStats;
import org.keycloak.utils.MediaType;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.keycloak.testsuite.rest.representation.JGroupsStats;
import org.keycloak.testsuite.rest.representation.RemoteCacheStats;
import java.util.Set;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -55,7 +53,7 @@ public interface TestingCacheResource {
@GET
@Path("/clear")
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
void clear();
@GET

View file

@ -18,14 +18,13 @@
package org.keycloak.testsuite.client.resources;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.representations.idm.AdminEventRepresentation;
import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
import org.keycloak.representations.idm.EventRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.testsuite.components.TestProvider;
import org.keycloak.testsuite.rest.representation.AuthenticatorState;
import org.keycloak.testsuite.rest.resource.TestCacheResource;
import org.keycloak.utils.MediaType;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -35,8 +34,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
@ -259,8 +256,8 @@ public interface TestingResource {
@POST
@Path("/run-on-server")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN_UTF_8)
@Produces(MediaType.TEXT_PLAIN_UTF_8)
String runOnServer(String runOnServer);
}