protected void checkKerberosServerAvailable(LoginException le) { String message = le.getMessage().toUpperCase(); if (message.contains("PORT UNREACHABLE") || message.contains("CANNOT LOCATE") || message.contains("CANNOT CONTACT") || message.contains("CANNOT FIND") || message.contains("UNKNOWN ERROR")) { throw new ModelException("Kerberos unreachable", le); } }
public static ModelException convertException(MongoException e) { if (e instanceof DuplicateKeyException) { return new ModelDuplicateException(e); } else { return new ModelException(e); } }
@Override public void removeAuthenticationFlow(AuthenticationFlowModel model) { if (KeycloakModelUtils.isFlowUsed(this, model)) { throw new ModelException("Cannot remove authentication flow, it is currently in use"); } AuthenticationFlowEntity entity = em.find(AuthenticationFlowEntity.class, model.getId()); em.remove(entity); em.flush(); }
public static ModelException convert(Throwable t) { if (t.getCause() != null && t.getCause() instanceof ConstraintViolationException) { throw new ModelDuplicateException(t); } if (t instanceof EntityExistsException || t instanceof ConstraintViolationException) { throw new ModelDuplicateException(t); } else { throw new ModelException(t); } }
public static ModelException convert(Throwable t) { if (t.getCause() != null && t.getCause() instanceof ConstraintViolationException) { throw new ModelDuplicateException(t); } if (t instanceof EntityExistsException) { throw new ModelDuplicateException(t); } else { throw new ModelException(t); } }
public static ModelException convert(Throwable t) { if (t.getCause() != null && t.getCause() instanceof ConstraintViolationException) { throw new ModelDuplicateException(t); } if (t instanceof EntityExistsException) { throw new ModelDuplicateException(t); } else { throw new ModelException(t); } }
public static ModelException convert(Throwable t) { if (t.getCause() != null && t.getCause() instanceof ConstraintViolationException) { throw new ModelDuplicateException(t); } if (t instanceof EntityExistsException) { throw new ModelDuplicateException(t); } else { throw new ModelException(t); } }
private PersistentUserSessionData getData() { if (data == null) { try { data = JsonSerialization.readValue(model.getData(), PersistentUserSessionData.class); } catch (IOException ioe) { throw new ModelException(ioe); } } return data; }
private PersistentClientSessionData getData() { if (data == null) { try { data = JsonSerialization.readValue(model.getData(), PersistentClientSessionData.class); } catch (IOException ioe) { throw new ModelException(ioe); } } return data; }
public PersistentUserSessionModel getUpdatedModel() { try { String updatedData = JsonSerialization.writeValueAsString(getData()); this.model.setData(updatedData); } catch (IOException ioe) { throw new ModelException(ioe); } return this.model; }
public PersistentClientSessionModel getUpdatedModel() { try { String updatedData = JsonSerialization.writeValueAsString(getData()); this.model.setData(updatedData); } catch (IOException ioe) { throw new ModelException(ioe); } return this.model; }
@Override public ResourceServer create(String clientId) { if (!StorageId.isLocalStorage(clientId)) { throw new ModelException("Creating resource server from federated ClientModel not supported"); } ResourceServerEntity entity = new ResourceServerEntity(); entity.setId(clientId); this.entityManager.persist(entity); return new ResourceServerAdapter(entity, entityManager, provider.getStoreFactory()); }
@Override public boolean removeClientTemplate(String id) { if (id == null) return false; ClientTemplateModel client = getClientTemplateById(id); if (client == null) return false; if (KeycloakModelUtils.isClientTemplateUsed(this, client)) { throw new ModelException("Cannot remove client template, it is currently in use"); } return getMongoStore().removeEntity(MongoClientTemplateEntity.class, id, invocationContext); }
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); UserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } updateGrantedConsentEntity(consentEntity, consent); }
@Override public void removeAuthenticationFlow(AuthenticationFlowModel model) { if (KeycloakModelUtils.isFlowUsed(this, model)) { throw new ModelException("Cannot remove authentication flow, it is currently in use"); } AuthenticationFlowEntity toDelete = getFlowEntity(model.getId()); if (toDelete == null) return; getMongoEntity().getAuthenticationFlows().remove(toDelete); updateMongoEntity(); }
@Override public ResourceServer create(String clientId) { if (!StorageId.isLocalStorage(clientId)) { throw new ModelException("Creating resource server from federated ClientModel not supported"); } ResourceServer server = getResourceServerStoreDelegate().create(clientId); registerResourceServerInvalidation(server.getId()); return server; }
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { createIndex(realm, userId); String clientId = consent.getClient().getId(); FederatedUserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } updateGrantedConsentEntity(consentEntity, consent); }
public void updateCredential(RealmModel realm, UserModel user, UserCredentialModel credential) { if (credential.getType().equals(UserCredentialModel.PASSWORD)) { if (realm.getPasswordPolicy() != null) { PasswordPolicy.Error error = realm.getPasswordPolicy().validate(session, user, credential.getValue()); if (error != null) throw new ModelException(error.getMessage(), error.getParameters()); } } user.updateCredential(credential); }
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); MongoUserConsentEntity consentEntity = getConsentEntityByClientId(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } else { fillEntityFromModel(consent, consentEntity); getMongoStore().updateEntity(consentEntity, invocationContext); } }
public static UserFederationMapperModel toModel(RealmModel realm, UserFederationMapperRepresentation rep) { UserFederationMapperModel model = new UserFederationMapperModel(); model.setId(rep.getId()); model.setName(rep.getName()); model.setFederationMapperType(rep.getFederationMapperType()); model.setConfig(rep.getConfig()); UserFederationProviderModel fedProvider = KeycloakModelUtils.findUserFederationProviderByDisplayName(rep.getFederationProviderDisplayName(), realm); if (fedProvider == null) { throw new ModelException("Couldn't find federation provider with display name [" + rep.getFederationProviderDisplayName() + "] referenced from mapper [" + rep.getName()); } model.setFederationProviderId(fedProvider.getId()); return model; }