remove filters

This commit is contained in:
Bill Burke 2013-08-02 23:36:25 -04:00
parent 540385fec5
commit 8b00fff5ee
5 changed files with 25 additions and 13 deletions

View file

@ -49,10 +49,10 @@ public class KeycloakApplication extends Application {
public KeycloakApplication() {
KeycloakSessionFactory f = createSessionFactory();
this.factory = f;
KeycloakSessionRequestFilter filter = new KeycloakSessionRequestFilter(factory);
//KeycloakSessionRequestFilter filter = new KeycloakSessionRequestFilter(factory);
//singletons.add(filter);
//classes.add(KeycloakSessionResponseFilter.class);
singletons.add(new RealmsResource(new TokenManager(), new SocialRequestManager()));
singletons.add(filter);
classes.add(KeycloakSessionResponseFilter.class);
classes.add(SkeletonKeyContextResolver.class);
classes.add(SaasService.class);
}

View file

@ -17,8 +17,8 @@ import javax.ws.rs.core.UriInfo;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RealmSubResource {
protected static final Logger logger = Logger.getLogger(RealmSubResource.class);
public class PublicRealmResource {
protected static final Logger logger = Logger.getLogger(PublicRealmResource.class);
public static final String ADMIN_ROLE = "$REALM-ADMIN$";
@Context
@ -26,7 +26,7 @@ public class RealmSubResource {
protected RealmModel realm;
public RealmSubResource(RealmModel realm) {
public PublicRealmResource(RealmModel realm) {
this.realm = realm;
}

View file

@ -92,17 +92,17 @@ public class RealmsResource {
}
@Path("{realm}")
public RealmSubResource getRealmResource(final @PathParam("realm") String id) {
public PublicRealmResource getRealmResource(final @PathParam("realm") String id) {
return new Transaction(false) {
@Override
protected RealmSubResource callImpl() {
protected PublicRealmResource callImpl() {
RealmManager realmManager = new RealmManager(session);
RealmModel realm = realmManager.getRealm(id);
if (realm == null) {
logger.debug("realm not found");
throw new NotFoundException();
}
RealmSubResource realmResource = new RealmSubResource(realm);
PublicRealmResource realmResource = new PublicRealmResource(realm);
resourceContext.initResource(realmResource);
return realmResource;
}
@ -127,7 +127,7 @@ public class RealmsResource {
RealmModel realm = realmManager.importRealm(rep, realmCreator);
UriBuilder builder = uriInfo.getRequestUriBuilder().path(realm.getId());
return Response.created(builder.build())
.entity(RealmSubResource.realmRep(realm, uriInfo))
.entity(PublicRealmResource.realmRep(realm, uriInfo))
.type(MediaType.APPLICATION_JSON_TYPE).build();
}
}.call();

View file

@ -9,7 +9,6 @@ import org.keycloak.representations.idm.RequiredCredentialRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.models.KeycloakSession;
import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.RoleModel;
import org.keycloak.services.models.UserModel;

View file

@ -5,6 +5,8 @@ import org.keycloak.services.models.KeycloakSession;
import org.keycloak.services.models.KeycloakSessionFactory;
import org.keycloak.services.models.KeycloakTransaction;
import javax.ws.rs.core.Application;
/**
* Meant to be used as an inner class wrapper (I forget the pattern name, its been awhile).
*
@ -15,6 +17,7 @@ public class Transaction {
protected KeycloakSession session;
protected KeycloakTransaction transaction;
protected boolean closeSession;
protected boolean created;
/**
* Pull KeycloakSession from @Context
@ -29,10 +32,16 @@ public class Transaction {
/**
* Pull KeycloakSession from @Context
*
* @param close whether to close the session or not after completion
* @param close whether to close the session or not after successful completion
*/
public Transaction(boolean close) {
this.session = ResteasyProviderFactory.getContextData(KeycloakSession.class);
if (session == null) {
KeycloakApplication app = (KeycloakApplication)ResteasyProviderFactory.getContextData(Application.class);
session = app.getFactory().createSession();
created = true;
ResteasyProviderFactory.pushContext(KeycloakSession.class, session);
}
transaction = session.getTransaction();
closeSession = close;
@ -65,9 +74,12 @@ public class Transaction {
if (!wasActive && transaction.isActive()) transaction.commit();
} catch (RuntimeException e) {
if (!wasActive && transaction.isActive()) transaction.rollback();
if (created) closeSession = true;
throw e;
} finally {
if (!wasActive && closeSession) session.close();
if (!wasActive && closeSession) {
session.close();
}
}
}
@ -88,6 +100,7 @@ public class Transaction {
return rtn;
} catch (RuntimeException e) {
if (!wasActive && transaction.isActive()) transaction.rollback();
if (created) closeSession = true; // close if there was a failure
throw e;
} finally {
if (!wasActive && closeSession) session.close();