Merge pull request #28 from stianst/generics

Added generic type to Transaction class to remove warnings
This commit is contained in:
Bill Burke 2013-08-15 05:44:53 -07:00
commit fa90a8fd6b
10 changed files with 36 additions and 36 deletions

View file

@ -41,7 +41,7 @@ public class PublicRealmResource {
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public PublishedRealmRepresentation getRealm(@PathParam("realm") String id) { public PublishedRealmRepresentation getRealm(@PathParam("realm") String id) {
return new Transaction() { return new Transaction<PublishedRealmRepresentation>() {
protected PublishedRealmRepresentation callImpl() { protected PublishedRealmRepresentation callImpl() {
return realmRep(realm, uriInfo); return realmRep(realm, uriInfo);
} }
@ -53,7 +53,7 @@ public class PublicRealmResource {
@Path("html") @Path("html")
@Produces("text/html") @Produces("text/html")
public String getRealmHtml(@PathParam("realm") String id) { public String getRealmHtml(@PathParam("realm") String id) {
return new Transaction() { return new Transaction<String>() {
protected String callImpl() { protected String callImpl() {
StringBuffer html = new StringBuffer(); StringBuffer html = new StringBuffer();

View file

@ -53,7 +53,7 @@ public class RealmsResource {
@Path("{realm}/tokens") @Path("{realm}/tokens")
public TokenService getTokenService(final @PathParam("realm") String id) { public TokenService getTokenService(final @PathParam("realm") String id) {
return new Transaction(false) { return new Transaction<TokenService>(false) {
@Override @Override
protected TokenService callImpl() { protected TokenService callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -72,7 +72,7 @@ public class RealmsResource {
@Path("{realm}") @Path("{realm}")
public PublicRealmResource getRealmResource(final @PathParam("realm") String id) { public PublicRealmResource getRealmResource(final @PathParam("realm") String id) {
return new Transaction(false) { return new Transaction<PublicRealmResource>(false) {
@Override @Override
protected PublicRealmResource callImpl() { protected PublicRealmResource callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);

View file

@ -79,7 +79,7 @@ public class SaasService {
@NoCache @NoCache
public Response keepalive(final @Context HttpHeaders headers) { public Response keepalive(final @Context HttpHeaders headers) {
logger.info("keepalive"); logger.info("keepalive");
return new Transaction() { return new Transaction<Response>() {
@Override @Override
public Response callImpl() { public Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -101,7 +101,7 @@ public class SaasService {
@Produces("application/json") @Produces("application/json")
@NoCache @NoCache
public Response whoAmI(final @Context HttpHeaders headers) { public Response whoAmI(final @Context HttpHeaders headers) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
public Response callImpl() { public Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -122,7 +122,7 @@ public class SaasService {
@Produces("application/javascript") @Produces("application/javascript")
@NoCache @NoCache
public String isLoggedIn(final @Context HttpHeaders headers) { public String isLoggedIn(final @Context HttpHeaders headers) {
return new Transaction() { return new Transaction<String>() {
@Override @Override
public String callImpl() { public String callImpl() {
logger.info("WHOAMI Javascript start."); logger.info("WHOAMI Javascript start.");
@ -152,7 +152,7 @@ public class SaasService {
@Path("admin/realms") @Path("admin/realms")
public RealmsAdminResource getRealmsAdmin(@Context final HttpHeaders headers) { public RealmsAdminResource getRealmsAdmin(@Context final HttpHeaders headers) {
return new Transaction(false) { return new Transaction<RealmsAdminResource>(false) {
@Override @Override
protected RealmsAdminResource callImpl() { protected RealmsAdminResource callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -239,7 +239,7 @@ public class SaasService {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response processLogin(final MultivaluedMap<String, String> formData) { public Response processLogin(final MultivaluedMap<String, String> formData) {
logger.info("processLogin start"); logger.info("processLogin start");
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -283,7 +283,7 @@ public class SaasService {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Response register(final UserRepresentation newUser) { public Response register(final UserRepresentation newUser) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -302,7 +302,7 @@ public class SaasService {
@POST @POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response processRegister(final MultivaluedMap<String, String> formData) { public Response processRegister(final MultivaluedMap<String, String> formData) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);

View file

@ -91,7 +91,7 @@ public class SocialResource {
@GET @GET
@Path("callback") @Path("callback")
public Response callback() throws URISyntaxException { public Response callback() throws URISyntaxException {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
Map<String, String[]> queryParams = getQueryParams(); Map<String, String[]> queryParams = getQueryParams();

View file

@ -118,7 +118,7 @@ public class TokenService {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response grantIdentityToken(final MultivaluedMap<String, String> form) { public Response grantIdentityToken(final MultivaluedMap<String, String> form) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
String username = form.getFirst(AuthenticationManager.FORM_USERNAME); String username = form.getFirst(AuthenticationManager.FORM_USERNAME);
if (username == null) { if (username == null) {
@ -151,7 +151,7 @@ public class TokenService {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response grantAccessToken(final MultivaluedMap<String, String> form) { public Response grantAccessToken(final MultivaluedMap<String, String> form) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
String username = form.getFirst(AuthenticationManager.FORM_USERNAME); String username = form.getFirst(AuthenticationManager.FORM_USERNAME);
if (username == null) { if (username == null) {
@ -185,7 +185,7 @@ public class TokenService {
public Response processLogin(@QueryParam("client_id") final String clientId, @QueryParam("scope") final String scopeParam, public Response processLogin(@QueryParam("client_id") final String clientId, @QueryParam("scope") final String scopeParam,
@QueryParam("state") final String state, @QueryParam("redirect_uri") final String redirect, @QueryParam("state") final String state, @QueryParam("redirect_uri") final String redirect,
final MultivaluedMap<String, String> formData) { final MultivaluedMap<String, String> formData) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager); OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager);
@ -229,7 +229,7 @@ public class TokenService {
public Response processRegister(@QueryParam("client_id") final String clientId, public Response processRegister(@QueryParam("client_id") final String clientId,
@QueryParam("scope") final String scopeParam, @QueryParam("state") final String state, @QueryParam("scope") final String scopeParam, @QueryParam("state") final String state,
@QueryParam("redirect_uri") final String redirect, final MultivaluedMap<String, String> formData) { @QueryParam("redirect_uri") final String redirect, final MultivaluedMap<String, String> formData) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager); OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager);
@ -310,7 +310,7 @@ public class TokenService {
@POST @POST
@Produces("application/json") @Produces("application/json")
public Response accessCodeToToken(final MultivaluedMap<String, String> formData) { public Response accessCodeToToken(final MultivaluedMap<String, String> formData) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
logger.info("accessRequest <---"); logger.info("accessRequest <---");
if (!realm.isEnabled()) { if (!realm.isEnabled()) {
@ -438,7 +438,7 @@ public class TokenService {
public Response loginPage(final @QueryParam("response_type") String responseType, public Response loginPage(final @QueryParam("response_type") String responseType,
final @QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId, final @QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId,
final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state) { final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager); OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager);
@ -486,7 +486,7 @@ public class TokenService {
public Response registerPage(final @QueryParam("response_type") String responseType, public Response registerPage(final @QueryParam("response_type") String responseType,
final @QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId, final @QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId,
final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state) { final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager); OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager);
@ -517,7 +517,7 @@ public class TokenService {
@GET @GET
@NoCache @NoCache
public Response logout(final @QueryParam("redirect_uri") String redirectUri) { public Response logout(final @QueryParam("redirect_uri") String redirectUri) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
// todo do we care if anybody can trigger this? // todo do we care if anybody can trigger this?
@ -537,7 +537,7 @@ public class TokenService {
@POST @POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response processOAuth(final MultivaluedMap<String, String> formData) { public Response processOAuth(final MultivaluedMap<String, String> formData) {
return new Transaction() { return new Transaction<Response>() {
protected Response callImpl() { protected Response callImpl() {
OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager); OAuthFlows oauth = Flows.oauth(realm, request, uriInfo, authManager, tokenManager);

View file

@ -13,7 +13,7 @@ import javax.ws.rs.core.Application;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class Transaction { public class Transaction<T> {
protected KeycloakSession session; protected KeycloakSession session;
protected KeycloakTransaction transaction; protected KeycloakTransaction transaction;
protected boolean closeSession; protected boolean closeSession;
@ -83,7 +83,7 @@ public class Transaction {
} }
} }
protected <T> T callImpl() { protected T callImpl() {
return null; return null;
} }
@ -91,7 +91,7 @@ public class Transaction {
* Will not begin or end a transaction or close a session if the transaction was already active when called * Will not begin or end a transaction or close a session if the transaction was already active when called
* *
*/ */
public <T> T call() { public T call() {
boolean wasActive = transaction.isActive(); boolean wasActive = transaction.isActive();
if (!wasActive) transaction.begin(); if (!wasActive) transaction.begin();
try { try {

View file

@ -36,7 +36,7 @@ public class ApplicationResource {
@PUT @PUT
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void update(final ApplicationRepresentation rep) { public void update(final ApplicationRepresentation rep) {
new Transaction() { new Transaction<Void>() {
@Override @Override
protected void runImpl() { protected void runImpl() {
ResourceManager resourceManager = new ResourceManager(new RealmManager(session)); ResourceManager resourceManager = new ResourceManager(new RealmManager(session));
@ -50,7 +50,7 @@ public class ApplicationResource {
@NoCache @NoCache
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public ApplicationRepresentation getResource(final @PathParam("id") String id) { public ApplicationRepresentation getResource(final @PathParam("id") String id) {
return new Transaction() { return new Transaction<ApplicationRepresentation>() {
@Override @Override
protected ApplicationRepresentation callImpl() { protected ApplicationRepresentation callImpl() {
ResourceManager resourceManager = new ResourceManager(new RealmManager(session)); ResourceManager resourceManager = new ResourceManager(new RealmManager(session));

View file

@ -42,7 +42,7 @@ public class ApplicationsResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@NoCache @NoCache
public List<ApplicationRepresentation> getResources() { public List<ApplicationRepresentation> getResources() {
return new Transaction() { return new Transaction<List<ApplicationRepresentation>>() {
@Override @Override
protected List<ApplicationRepresentation> callImpl() { protected List<ApplicationRepresentation> callImpl() {
List<ApplicationRepresentation> rep = new ArrayList<ApplicationRepresentation>(); List<ApplicationRepresentation> rep = new ArrayList<ApplicationRepresentation>();
@ -59,7 +59,7 @@ public class ApplicationsResource {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Response createResource(final @Context UriInfo uriInfo, final ApplicationRepresentation rep) { public Response createResource(final @Context UriInfo uriInfo, final ApplicationRepresentation rep) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
ResourceManager resourceManager = new ResourceManager(new RealmManager(session)); ResourceManager resourceManager = new ResourceManager(new RealmManager(session));
@ -71,7 +71,7 @@ public class ApplicationsResource {
@Path("{id}") @Path("{id}")
public ApplicationResource getResource(final @PathParam("id") String id) { public ApplicationResource getResource(final @PathParam("id") String id) {
return new Transaction(false) { return new Transaction<ApplicationResource>(false) {
@Override @Override
protected ApplicationResource callImpl() { protected ApplicationResource callImpl() {
ApplicationModel applicationModel = realm.getApplicationById(id); ApplicationModel applicationModel = realm.getApplicationById(id);

View file

@ -49,7 +49,7 @@ public class RealmAdminResource {
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public RealmRepresentation getRealm() { public RealmRepresentation getRealm() {
return new Transaction() { return new Transaction<RealmRepresentation>() {
@Override @Override
protected RealmRepresentation callImpl() { protected RealmRepresentation callImpl() {
return new RealmManager(session).toRepresentation(realm); return new RealmManager(session).toRepresentation(realm);
@ -63,7 +63,7 @@ public class RealmAdminResource {
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public List<RoleRepresentation> getRoles() { public List<RoleRepresentation> getRoles() {
return new Transaction() { return new Transaction<List<RoleRepresentation>>() {
@Override @Override
protected List<RoleRepresentation> callImpl() { protected List<RoleRepresentation> callImpl() {
List<RoleModel> roleModels = realm.getRoles(); List<RoleModel> roleModels = realm.getRoles();
@ -95,7 +95,7 @@ public class RealmAdminResource {
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public RoleRepresentation getRole(final @PathParam("id") String id) { public RoleRepresentation getRole(final @PathParam("id") String id) {
return new Transaction() { return new Transaction<RoleRepresentation>() {
@Override @Override
protected RoleRepresentation callImpl() { protected RoleRepresentation callImpl() {
RoleModel roleModel = realm.getRoleById(id); RoleModel roleModel = realm.getRoleById(id);
@ -132,7 +132,7 @@ public class RealmAdminResource {
@POST @POST
@Consumes("application/json") @Consumes("application/json")
public Response createRole(final @Context UriInfo uriInfo, final RoleRepresentation rep) { public Response createRole(final @Context UriInfo uriInfo, final RoleRepresentation rep) {
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
if (realm.getRole(rep.getName()) != null) { if (realm.getRole(rep.getName()) != null) {

View file

@ -54,7 +54,7 @@ public class RealmsAdminResource {
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
public List<RealmRepresentation> getRealms() { public List<RealmRepresentation> getRealms() {
return new Transaction() { return new Transaction<List<RealmRepresentation>>() {
@Override @Override
protected List<RealmRepresentation> callImpl() { protected List<RealmRepresentation> callImpl() {
logger.info(("getRealms()")); logger.info(("getRealms()"));
@ -81,7 +81,7 @@ public class RealmsAdminResource {
@Consumes("application/json") @Consumes("application/json")
public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) { public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) {
logger.info("importRealm: " + rep.getRealm()); logger.info("importRealm: " + rep.getRealm());
return new Transaction() { return new Transaction<Response>() {
@Override @Override
protected Response callImpl() { protected Response callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);
@ -96,7 +96,7 @@ public class RealmsAdminResource {
@Path("{id}") @Path("{id}")
public RealmAdminResource getRealmAdmin(@Context final HttpHeaders headers, public RealmAdminResource getRealmAdmin(@Context final HttpHeaders headers,
@PathParam("id") final String id) { @PathParam("id") final String id) {
return new Transaction(false) { return new Transaction<RealmAdminResource>(false) {
@Override @Override
protected RealmAdminResource callImpl() { protected RealmAdminResource callImpl() {
RealmManager realmManager = new RealmManager(session); RealmManager realmManager = new RealmManager(session);