{ // test bearer-only
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
ApplicationModel clientModel = realm.getApplicationByName("test-app");
clientModel.setBearerOnly(true);
session.getTransaction().commit();
session.close();
}
Response response = executeGrantAccessTokenRequest(grantTarget);
Assert.assertEquals(400, response.getStatus());
response.close();
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
ApplicationModel clientModel = realm.getApplicationByName("test-app");
clientModel.setBearerOnly(false);
session.getTransaction().commit();
session.close();
}
}
{ // test realm disabled
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
realm.setEnabled(false);
session.getTransaction().commit();
session.close();
}
Response response = executeGrantAccessTokenRequest(grantTarget);
Assert.assertEquals(401, response.getStatus());
response.close();
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
realm.setEnabled(true);
session.getTransaction().commit();
session.close();
}
}
{ // test application disabled
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
ClientModel clientModel = realm.findClient("test-app");
clientModel.setEnabled(false);
session.getTransaction().commit();
session.close();
}
Response response = executeGrantAccessTokenRequest(grantTarget);
Assert.assertEquals(400, response.getStatus());
response.close();
{
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
ClientModel clientModel = realm.findClient("test-app");
clientModel.setEnabled(true);
session.getTransaction().commit();
session.close();
}
}