예제 #1
0
  /**
   * Import a realm
   *
   * <p>Imports a realm from a full representation of that realm. Realm name must be unique.
   *
   * @param uriInfo
   * @param rep JSON representation of the realm
   * @return
   */
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) {
    RealmManager realmManager = new RealmManager(session);
    realmManager.setContextPath(keycloak.getContextPath());
    if (!auth.getRealm().equals(realmManager.getKeycloakAdminstrationRealm())) {
      throw new ForbiddenException();
    }
    if (!auth.hasRealmRole(AdminRoles.CREATE_REALM)) {
      throw new ForbiddenException();
    }

    logger.debugv("importRealm: {0}", rep.getRealm());

    try {
      RealmModel realm = realmManager.importRealm(rep);
      grantPermissionsToRealmCreator(realm);

      URI location = AdminRoot.realmsUrl(uriInfo).path(realm.getName()).build();
      logger.debugv("imported realm success, sending back: {0}", location.toString());

      return Response.created(location).build();
    } catch (ModelDuplicateException e) {
      return ErrorResponse.exists("Realm with same name exists");
    }
  }
 public static RealmModel baseAdapterTestInitialization(
     KeycloakSession session, RealmManager manager, RealmModel adminRealm, Class<?> clazz) {
   RealmRepresentation representation =
       KeycloakServer.loadJson(
           clazz.getResourceAsStream("/keycloak-saml/testsaml.json"), RealmRepresentation.class);
   RealmModel demoRealm = manager.importRealm(representation);
   return demoRealm;
 }
예제 #3
0
 @Override
 protected void configure(
     KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
   RealmRepresentation representation =
       KeycloakServer.loadJson(
           getClass().getResourceAsStream("/adapter-test/demorealm.json"),
           RealmRepresentation.class);
   RealmModel realm = manager.importRealm(representation);
 }
예제 #4
0
  @Test
  public void install2() throws Exception {
    RealmManager manager = realmManager;
    RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm-demo.json");
    rep.setId("demo");
    RealmModel realm = manager.importRealm(rep);

    Assert.assertEquals(600, realm.getAccessCodeLifespanUserAction());
    verifyRequiredCredentials(realm.getRequiredCredentials(), "password");
  }
예제 #5
0
  @Test
  public void install2() throws Exception {
    RealmManager manager = realmManager;
    RealmRepresentation rep = AbstractModelTest.loadJson("testrealm-demo.json");
    RealmModel realm = manager.createRealm("demo", rep.getRealm());
    manager.importRealm(rep, realm);

    Assert.assertFalse(realm.isUpdateProfileOnInitialSocialLogin());
    Assert.assertEquals(600, realm.getAccessCodeLifespanUserAction());
    verifyRequiredCredentials(realm.getRequiredCredentials(), "password");
  }
예제 #6
0
  @POST
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Response uploadRealm(MultipartFormDataInput input) throws IOException {
    Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    List<InputPart> inputParts = uploadForm.get("file");

    RealmManager realmManager = new RealmManager(session);
    for (InputPart inputPart : inputParts) {
      inputPart.setMediaType(MediaType.APPLICATION_JSON_TYPE);
      RealmRepresentation rep = inputPart.getBody(new GenericType<RealmRepresentation>() {});
      realmManager.importRealm(rep, admin);
    }
    return Response.noContent().build();
  }
예제 #7
0
  @POST
  @Consumes("application/json")
  public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) {
    logger.debug("importRealm: {0}", rep.getRealm());
    RealmManager realmManager = new RealmManager(session);
    if (realmManager.getRealm(rep.getRealm()) != null) {
      return Flows.errors().exists("Realm " + rep.getRealm() + " already exists");
    }

    RealmModel realm = realmManager.importRealm(rep, admin);
    URI location = realmUrl(uriInfo).build(realm.getId());
    logger.debug("imported realm success, sending back: {0}", location.toString());
    return Response.created(location).build();
  }
예제 #8
0
 public void install(RealmManager manager) {
   RealmRepresentation rep = loadJson("META-INF/testrealm.json");
   RealmModel realm = manager.createRealm("demo", rep.getRealm());
   manager.importRealm(rep, realm);
 }