Realm update validation for incorrect timeout values (#32137)
closes #31595 Signed-off-by: Himanshi Gupta <higupta@redhat.com>
This commit is contained in:
parent
43de7d6121
commit
7459992e40
2 changed files with 18 additions and 0 deletions
|
@ -439,6 +439,12 @@ public class RealmAdminResource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rep.getAccessCodeLifespanLogin() != null && rep.getAccessCodeLifespanUserAction() != null) {
|
||||||
|
if (rep.getAccessCodeLifespanLogin() < 1 || rep.getAccessCodeLifespanUserAction() < 1) {
|
||||||
|
throw ErrorResponse.error("AccessCodeLifespanLogin or AccessCodeLifespanUserAction cannot be 0", Status.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RepresentationToModel.updateRealm(rep, realm, session);
|
RepresentationToModel.updateRealm(rep, realm, session);
|
||||||
|
|
||||||
// Refresh periodic sync tasks for configured federationProviders
|
// Refresh periodic sync tasks for configured federationProviders
|
||||||
|
@ -457,6 +463,8 @@ public class RealmAdminResource {
|
||||||
throw ErrorResponse.error(e.getMessage(), Status.INTERNAL_SERVER_ERROR);
|
throw ErrorResponse.error(e.getMessage(), Status.INTERNAL_SERVER_ERROR);
|
||||||
} catch (ModelException e) {
|
} catch (ModelException e) {
|
||||||
throw ErrorResponse.error(e.getMessage(), Status.BAD_REQUEST);
|
throw ErrorResponse.error(e.getMessage(), Status.BAD_REQUEST);
|
||||||
|
} catch (org.keycloak.services.ErrorResponseException e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
throw ErrorResponse.error("Failed to update realm", Response.Status.INTERNAL_SERVER_ERROR);
|
throw ErrorResponse.error("Failed to update realm", Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
|
|
|
@ -692,6 +692,16 @@ public class RealmTest extends AbstractAdminTest {
|
||||||
assertEquals(Boolean.FALSE, rep.isRegistrationEmailAsUsername());
|
assertEquals(Boolean.FALSE, rep.isRegistrationEmailAsUsername());
|
||||||
assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
|
assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
|
||||||
assertEquals(Boolean.FALSE, rep.isUserManagedAccessAllowed());
|
assertEquals(Boolean.FALSE, rep.isUserManagedAccessAllowed());
|
||||||
|
|
||||||
|
rep.setAccessCodeLifespanLogin(0);
|
||||||
|
rep.setAccessCodeLifespanUserAction(0);
|
||||||
|
try {
|
||||||
|
realm.update(rep);
|
||||||
|
Assert.fail("Not expected to successfully update the realm");
|
||||||
|
} catch (Exception expected) {
|
||||||
|
// Expected exception
|
||||||
|
assertEquals("HTTP 400 Bad Request", expected.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue