remove filters
This commit is contained in:
parent
540385fec5
commit
8b00fff5ee
5 changed files with 25 additions and 13 deletions
|
@ -49,10 +49,10 @@ public class KeycloakApplication extends Application {
|
||||||
public KeycloakApplication() {
|
public KeycloakApplication() {
|
||||||
KeycloakSessionFactory f = createSessionFactory();
|
KeycloakSessionFactory f = createSessionFactory();
|
||||||
this.factory = f;
|
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(new RealmsResource(new TokenManager(), new SocialRequestManager()));
|
||||||
singletons.add(filter);
|
|
||||||
classes.add(KeycloakSessionResponseFilter.class);
|
|
||||||
classes.add(SkeletonKeyContextResolver.class);
|
classes.add(SkeletonKeyContextResolver.class);
|
||||||
classes.add(SaasService.class);
|
classes.add(SaasService.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ import javax.ws.rs.core.UriInfo;
|
||||||
* @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 RealmSubResource {
|
public class PublicRealmResource {
|
||||||
protected static final Logger logger = Logger.getLogger(RealmSubResource.class);
|
protected static final Logger logger = Logger.getLogger(PublicRealmResource.class);
|
||||||
public static final String ADMIN_ROLE = "$REALM-ADMIN$";
|
public static final String ADMIN_ROLE = "$REALM-ADMIN$";
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
|
@ -26,7 +26,7 @@ public class RealmSubResource {
|
||||||
|
|
||||||
protected RealmModel realm;
|
protected RealmModel realm;
|
||||||
|
|
||||||
public RealmSubResource(RealmModel realm) {
|
public PublicRealmResource(RealmModel realm) {
|
||||||
this.realm = realm;
|
this.realm = realm;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,17 +92,17 @@ public class RealmsResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("{realm}")
|
@Path("{realm}")
|
||||||
public RealmSubResource getRealmResource(final @PathParam("realm") String id) {
|
public PublicRealmResource getRealmResource(final @PathParam("realm") String id) {
|
||||||
return new Transaction(false) {
|
return new Transaction(false) {
|
||||||
@Override
|
@Override
|
||||||
protected RealmSubResource callImpl() {
|
protected PublicRealmResource callImpl() {
|
||||||
RealmManager realmManager = new RealmManager(session);
|
RealmManager realmManager = new RealmManager(session);
|
||||||
RealmModel realm = realmManager.getRealm(id);
|
RealmModel realm = realmManager.getRealm(id);
|
||||||
if (realm == null) {
|
if (realm == null) {
|
||||||
logger.debug("realm not found");
|
logger.debug("realm not found");
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
RealmSubResource realmResource = new RealmSubResource(realm);
|
PublicRealmResource realmResource = new PublicRealmResource(realm);
|
||||||
resourceContext.initResource(realmResource);
|
resourceContext.initResource(realmResource);
|
||||||
return realmResource;
|
return realmResource;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public class RealmsResource {
|
||||||
RealmModel realm = realmManager.importRealm(rep, realmCreator);
|
RealmModel realm = realmManager.importRealm(rep, realmCreator);
|
||||||
UriBuilder builder = uriInfo.getRequestUriBuilder().path(realm.getId());
|
UriBuilder builder = uriInfo.getRequestUriBuilder().path(realm.getId());
|
||||||
return Response.created(builder.build())
|
return Response.created(builder.build())
|
||||||
.entity(RealmSubResource.realmRep(realm, uriInfo))
|
.entity(PublicRealmResource.realmRep(realm, uriInfo))
|
||||||
.type(MediaType.APPLICATION_JSON_TYPE).build();
|
.type(MediaType.APPLICATION_JSON_TYPE).build();
|
||||||
}
|
}
|
||||||
}.call();
|
}.call();
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.keycloak.representations.idm.RequiredCredentialRepresentation;
|
||||||
import org.keycloak.representations.idm.UserRepresentation;
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
import org.keycloak.services.managers.AuthenticationManager;
|
import org.keycloak.services.managers.AuthenticationManager;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.services.models.KeycloakSession;
|
|
||||||
import org.keycloak.services.models.RealmModel;
|
import org.keycloak.services.models.RealmModel;
|
||||||
import org.keycloak.services.models.RoleModel;
|
import org.keycloak.services.models.RoleModel;
|
||||||
import org.keycloak.services.models.UserModel;
|
import org.keycloak.services.models.UserModel;
|
||||||
|
|
|
@ -5,6 +5,8 @@ import org.keycloak.services.models.KeycloakSession;
|
||||||
import org.keycloak.services.models.KeycloakSessionFactory;
|
import org.keycloak.services.models.KeycloakSessionFactory;
|
||||||
import org.keycloak.services.models.KeycloakTransaction;
|
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).
|
* 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 KeycloakSession session;
|
||||||
protected KeycloakTransaction transaction;
|
protected KeycloakTransaction transaction;
|
||||||
protected boolean closeSession;
|
protected boolean closeSession;
|
||||||
|
protected boolean created;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull KeycloakSession from @Context
|
* Pull KeycloakSession from @Context
|
||||||
|
@ -29,10 +32,16 @@ public class Transaction {
|
||||||
/**
|
/**
|
||||||
* Pull KeycloakSession from @Context
|
* 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) {
|
public Transaction(boolean close) {
|
||||||
this.session = ResteasyProviderFactory.getContextData(KeycloakSession.class);
|
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();
|
transaction = session.getTransaction();
|
||||||
closeSession = close;
|
closeSession = close;
|
||||||
|
|
||||||
|
@ -65,9 +74,12 @@ public class Transaction {
|
||||||
if (!wasActive && transaction.isActive()) transaction.commit();
|
if (!wasActive && transaction.isActive()) transaction.commit();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (!wasActive && transaction.isActive()) transaction.rollback();
|
if (!wasActive && transaction.isActive()) transaction.rollback();
|
||||||
|
if (created) closeSession = true;
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (!wasActive && closeSession) session.close();
|
if (!wasActive && closeSession) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +100,7 @@ public class Transaction {
|
||||||
return rtn;
|
return rtn;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (!wasActive && transaction.isActive()) transaction.rollback();
|
if (!wasActive && transaction.isActive()) transaction.rollback();
|
||||||
|
if (created) closeSession = true; // close if there was a failure
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (!wasActive && closeSession) session.close();
|
if (!wasActive && closeSession) session.close();
|
||||||
|
|
Loading…
Reference in a new issue