List of usage examples for org.apache.commons.lang BooleanUtils isTrue
public static boolean isTrue(Boolean bool)
Checks if a Boolean
value is true
, handling null
by returning false
.
BooleanUtils.isTrue(Boolean.TRUE) = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null) = false
From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java
@Override public boolean saveSettings(Element element) { Boolean changed = false;/*from w ww.j a v a 2 s. c om*/ Element e = element.element("defaultFilter"); if (e == null) e = element.addElement("defaultFilter"); UUID defaultId = null; Boolean applyDefault = false; for (FilterEntity filter : filterEntities) { if (BooleanUtils.isTrue(filter.getIsDefault())) { defaultId = filter.getId(); applyDefault = filter.getApplyDefault(); break; } } String newDef = defaultId != null ? defaultId.toString() : null; Attribute attr = e.attribute("id"); String oldDef = attr != null ? attr.getValue() : null; if (!Objects.equals(oldDef, newDef)) { if (newDef == null && attr != null) { e.remove(attr); } else { if (attr == null) e.addAttribute("id", newDef); else attr.setValue(newDef); } changed = true; } Boolean newApplyDef = BooleanUtils.isTrue(applyDefault); Attribute applyDefaultAttr = e.attribute("applyDefault"); Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false; if (!Objects.equals(oldApplyDef, newApplyDef)) { if (applyDefaultAttr != null) { applyDefaultAttr.setValue(newApplyDef.toString()); } else { e.addAttribute("applyDefault", newApplyDef.toString()); } changed = true; } Element groupBoxExpandedEl = element.element("groupBoxExpanded"); if (groupBoxExpandedEl == null) groupBoxExpandedEl = element.addElement("groupBoxExpanded"); Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText()); Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded(); if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) { groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString()); changed = true; } return changed; }
From source file:com.evolveum.midpoint.testing.rest.TestAbstractRestService.java
@Test public void test612ResetPassword() throws Exception { final String TEST_NAME = "test612ResetPassword"; displayTestTitle(this, TEST_NAME); WebClient client = prepareClient();/*from w ww . j a v a2 s . c o m*/ client.path("/users/" + USER_DARTHADDER_OID + "/credential"); getDummyAuditService().clear(); TestUtil.displayWhen(TEST_NAME); // ExecuteCredentialResetRequestType executeCredentialResetRequest = new ExecuteCredentialResetRequestType(); // executeCredentialResetRequest.setResetMethod("passwordReset"); // executeCredentialResetRequest.setUserEntry("123passwd456"); Response response = client.post(getRequestFile(EXECUTE_CREDENTIAL_RESET)); TestUtil.displayThen(TEST_NAME); displayResponse(response); traceResponse(response); assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus()); display("Audit", getDummyAuditService()); getDummyAuditService().assertRecords(4); getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI); getDummyAuditService().assertHasDelta(1, ChangeType.MODIFY, UserType.class); TestUtil.displayWhen(TEST_NAME); client = prepareClient(); response = client.path("/users/" + USER_DARTHADDER_OID).get(); TestUtil.displayThen(TEST_NAME); displayResponse(response); assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus()); UserType userDarthadder = response.readEntity(UserType.class); CredentialsType credentials = userDarthadder.getCredentials(); assertNotNull("No credentials in user. Something is wrong.", credentials); PasswordType passwordType = credentials.getPassword(); assertNotNull("No password defined for user. Something is wrong.", passwordType); ProtectedStringType passwordValue = passwordType.getValue(); assertNotNull("No value for password defined for user. Something is wrong.", passwordValue); String passwordClearValue = getPrismContext().getDefaultProtector().decryptString(passwordValue); assertEquals("Password doesn't match. Expected P4ssw0rd, but was " + passwordClearValue, "P4ssw0rd", passwordClearValue); assertTrue(BooleanUtils.isTrue(passwordType.isForceChange())); }
From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java
/** * Adds actions of 'Entities Set' functionality to Table component *///from www . j a v a 2 s. c om protected void fillTableActions() { Table table; if ((applyTo != null) && (Table.class.isAssignableFrom(applyTo.getClass()))) { table = (Table) applyTo; } else { return; } ButtonsPanel buttons = table.getButtonsPanel(); if (buttons == null) { return; // in lookup windows, there is no button panel } com.haulmont.cuba.gui.components.Button addToSetBtn = (Button) buttons.getComponent("addToSetBtn"); com.haulmont.cuba.gui.components.Button addToCurSetBtn = (Button) buttons.getComponent("addToCurSetBtn"); com.haulmont.cuba.gui.components.Button removeFromCurSetBtn = (Button) buttons .getComponent("removeFromCurSetBtn"); Action addToSet = table.getAction("filter.addToSet"); Action addToCurrSet = table.getAction("filter.addToCurSet"); Action removeFromCurrSet = table.getAction("filter.removeFromCurSet"); if (addToSet != null) table.removeAction(addToSet); if (addToSetBtn != null) addToSetBtn.setVisible(false); if (addToCurrSet != null) { table.removeAction(addToCurrSet); } if (addToCurSetBtn != null) { addToCurSetBtn.setVisible(false); } if (removeFromCurrSet != null) { table.removeAction(removeFromCurrSet); } if (removeFromCurSetBtn != null) { removeFromCurSetBtn.setVisible(false); } if ((filterEntity != null) && (BooleanUtils.isTrue(filterEntity.getIsSet()))) { addToCurrSet = new AddToCurrSetAction(); if (addToCurSetBtn == null) { addToCurSetBtn = componentsFactory.createComponent(Button.class); addToCurSetBtn.setId("addToCurSetBtn"); addToCurSetBtn.setCaption(getMainMessage("filter.addToCurSet")); buttons.add(addToCurSetBtn); } else { addToCurSetBtn.setVisible(true); } if (StringUtils.isEmpty(addToCurSetBtn.getIcon())) { addToCurSetBtn.setIcon("icons/join-to-set.png"); } addToCurSetBtn.setAction(addToCurrSet); table.addAction(addToCurrSet); removeFromCurrSet = new RemoveFromSetAction(table); if (removeFromCurSetBtn == null) { removeFromCurSetBtn = componentsFactory.createComponent(Button.class); removeFromCurSetBtn.setId("removeFromCurSetBtn"); removeFromCurSetBtn.setCaption(getMainMessage("filter.removeFromCurSet")); buttons.add(removeFromCurSetBtn); } else { removeFromCurSetBtn.setVisible(true); } if (StringUtils.isEmpty(removeFromCurSetBtn.getIcon())) { removeFromCurSetBtn.setIcon("icons/delete-from-set.png"); } removeFromCurSetBtn.setAction(removeFromCurrSet); table.addAction(removeFromCurrSet); } else { addToSet = new AddToSetAction(table); if (addToSetBtn == null) { addToSetBtn = componentsFactory.createComponent(Button.class); addToSetBtn.setId("addToSetBtn"); addToSetBtn.setCaption(getMainMessage("filter.addToSet")); buttons.add(addToSetBtn); } else { addToSetBtn.setVisible(true); } if (StringUtils.isEmpty(addToSetBtn.getIcon())) { addToSetBtn.setIcon("icons/insert-to-set.png"); } addToSetBtn.setAction(addToSet); table.addAction(addToSet); } }
From source file:gov.nih.nci.cabig.caaers.domain.ExpeditedAdverseEventReport.java
@Transient public List<AdverseEvent> getUnReportedAdverseEvents() { List<AdverseEvent> aes = new ArrayList<AdverseEvent>(); for (AdverseEvent ae : getActiveAdverseEvents()) { if (!BooleanUtils.isTrue(ae.getReported())) aes.add(ae);//from www . j av a2 s. c o m } return aes; }
From source file:com.evolveum.midpoint.security.enforcer.impl.SecurityEnforcerImpl.java
private <T extends ObjectType, O extends ObjectType> ObjectFilter preProcessObjectFilterInternal( MidPointPrincipal principal, String operationUrl, AuthorizationPhaseType phase, boolean includeNullPhase, Class<T> objectType, PrismObject<O> object, boolean includeSpecial, ObjectFilter origFilter, String limitAuthorizationAction, String desc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException { Collection<Authorization> authorities = getAuthorities(principal); ObjectFilter securityFilterAllow = null; ObjectFilter securityFilterDeny = null; QueryAutzItemPaths queryItemsSpec = new QueryAutzItemPaths(); queryItemsSpec.addRequiredItems(origFilter); // MID-3916 if (LOGGER.isTraceEnabled()) { LOGGER.trace(" phase={}, initial query items spec {}", phase, queryItemsSpec.shortDump()); }//from w w w. jav a 2 s.co m boolean hasAllowAll = false; if (authorities != null) { for (GrantedAuthority authority : authorities) { if (authority instanceof Authorization) { Authorization autz = (Authorization) authority; String autzHumanReadableDesc = autz.getHumanReadableDesc(); LOGGER.trace(" Evaluating {}", autzHumanReadableDesc); // action if (!autz.getAction().contains(operationUrl) && !autz.getAction().contains(AuthorizationConstants.AUTZ_ALL_URL)) { LOGGER.trace(" Authorization not applicable for operation {}", operationUrl); continue; } // phase if (autz.getPhase() == phase || (includeNullPhase && autz.getPhase() == null)) { LOGGER.trace(" Authorization is applicable for phases {} (continuing evaluation)", phase); } else { LOGGER.trace(" Authorization is not applicable for phase {}", phase); continue; } if (!isApplicableLimitations(autz, limitAuthorizationAction)) { LOGGER.trace( " Authorization is limited to other action, not applicable for operation {}", operationUrl); continue; } // object or target String objectTargetSpec; ObjectFilter autzObjSecurityFilter = null; List<OwnedObjectSelectorType> objectSpecTypes; if (object == null) { // object not present. Therefore we are looking for object here objectSpecTypes = autz.getObject(); objectTargetSpec = "object"; } else { // object present. Therefore we are looking for target objectSpecTypes = autz.getTarget(); objectTargetSpec = "target"; // .. but we need to decide whether this authorization is applicable to the object if (isApplicable(autz.getObject(), object, principal, null, "object", autzHumanReadableDesc, task, result)) { LOGGER.trace(" Authorization is applicable for object {}", object); } else { LOGGER.trace(" Authorization is not applicable for object {}", object); continue; } } boolean applicable = true; if (objectSpecTypes == null || objectSpecTypes.isEmpty()) { LOGGER.trace( " No {} specification in authorization (authorization is universaly applicable)", objectTargetSpec); autzObjSecurityFilter = AllFilter.createAll(); } else { applicable = false; for (OwnedObjectSelectorType objectSpecType : objectSpecTypes) { ObjectFilter objSpecSecurityFilter = null; TypeFilter objSpecTypeFilter = null; SearchFilterType specFilterType = objectSpecType.getFilter(); ObjectReferenceType specOrgRef = objectSpecType.getOrgRef(); OrgRelationObjectSpecificationType specOrgRelation = objectSpecType.getOrgRelation(); RoleRelationObjectSpecificationType specRoleRelation = objectSpecType.getRoleRelation(); QName specTypeQName = objectSpecType.getType(); PrismObjectDefinition<T> objectDefinition = null; // Type if (specTypeQName != null) { specTypeQName = prismContext.getSchemaRegistry().qualifyTypeName(specTypeQName); PrismObjectDefinition<?> specObjectDef = prismContext.getSchemaRegistry() .findObjectDefinitionByType(specTypeQName); if (specObjectDef == null) { throw new SchemaException("Unknown object type " + specTypeQName + " in " + autzHumanReadableDesc); } Class<?> specObjectClass = specObjectDef.getCompileTimeClass(); if (!objectType.isAssignableFrom(specObjectClass)) { LOGGER.trace( " Authorization not applicable for object because of type mismatch, authorization {}, query {}", new Object[] { specObjectClass, objectType }); continue; } else { LOGGER.trace( " Authorization is applicable for object because of type match, authorization {}, query {}", new Object[] { specObjectClass, objectType }); // The spec type is a subclass of requested type. So it might be returned from the search. // We need to use type filter. objSpecTypeFilter = TypeFilter.createType(specTypeQName, null); // and now we have a more specific object definition to use later in filter processing objectDefinition = (PrismObjectDefinition<T>) specObjectDef; } } // Owner if (objectSpecType.getOwner() != null) { if (objectDefinition == null) { objectDefinition = prismContext.getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(objectType); } // TODO: MID-3899 if (AbstractRoleType.class.isAssignableFrom(objectType)) { objSpecSecurityFilter = applyOwnerFilterOwnerRef( new ItemPath(AbstractRoleType.F_OWNER_REF), objSpecSecurityFilter, principal, objectDefinition); } else if (TaskType.class.isAssignableFrom(objectType)) { objSpecSecurityFilter = applyOwnerFilterOwnerRef( new ItemPath(TaskType.F_OWNER_REF), objSpecSecurityFilter, principal, objectDefinition); } else { LOGGER.trace( " Authorization not applicable for object because it has owner specification (this is not applicable for search)"); continue; } } // // Delegator // if (objectSpecType.getDelegator() != null) { // if (objectDefinition == null) { // objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectType); // } // // TODO: MID-3899 // if (UserType.class.isAssignableFrom(objectType)) { TODO // objSpecSecurityFilter = applyOwnerFilterOwnerRef(new ItemPath(AbstractRoleType.F_OWNER_REF), objSpecSecurityFilter, principal, objectDefinition); // } else if (TaskType.class.isAssignableFrom(objectType)) { // objSpecSecurityFilter = applyOwnerFilterOwnerRef(new ItemPath(TaskType.F_OWNER_REF), objSpecSecurityFilter, principal, objectDefinition); // } else { // LOGGER.trace(" Authorization not applicable for object because it has owner specification (this is not applicable for search)"); // continue; // } // } applicable = true; // Special List<SpecialObjectSpecificationType> specSpecial = objectSpecType.getSpecial(); if (specSpecial != null && !specSpecial.isEmpty()) { if (!includeSpecial) { LOGGER.trace(" Skipping authorization, because specials are present: {}", specSpecial); applicable = false; } if (specFilterType != null || specOrgRef != null || specOrgRelation != null || specRoleRelation != null) { throw new SchemaException( "Both filter/org/role and special object specification specified in authorization"); } ObjectFilter specialFilter = null; for (SpecialObjectSpecificationType special : specSpecial) { if (special == SpecialObjectSpecificationType.SELF) { String principalOid = principal.getOid(); specialFilter = ObjectQueryUtil.filterOr(specialFilter, InOidFilter.createInOid(principalOid)); } else { throw new SchemaException( "Unsupported special object specification specified in authorization: " + special); } } objSpecSecurityFilter = specTypeQName != null ? TypeFilter.createType(specTypeQName, specialFilter) : specialFilter; } else { LOGGER.trace(" specials empty: {}", specSpecial); } // Filter if (specFilterType != null) { if (objectDefinition == null) { objectDefinition = prismContext.getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(objectType); } ObjectFilter specFilter = parseAndEvaluateFilter(principal, objectDefinition, specFilterType, objectTargetSpec, autzHumanReadableDesc, task, result); if (specFilter != null) { ObjectQueryUtil.assertNotRaw(specFilter, "Filter in authorization object has undefined items. Maybe a 'type' specification is missing in the authorization?"); ObjectQueryUtil.assertPropertyOnly(specFilter, "Filter in authorization object is not property-only filter"); } LOGGER.trace(" applying property filter {}", specFilter); objSpecSecurityFilter = ObjectQueryUtil.filterAnd(objSpecSecurityFilter, specFilter); } else { LOGGER.trace(" filter empty"); } // Org if (specOrgRef != null) { ObjectFilter orgFilter = QueryBuilder.queryFor(ObjectType.class, prismContext) .isChildOf(specOrgRef.getOid()).buildFilter(); objSpecSecurityFilter = ObjectQueryUtil.filterAnd(objSpecSecurityFilter, orgFilter); LOGGER.trace(" applying org filter {}", orgFilter); } else { LOGGER.trace(" org empty"); } // orgRelation if (specOrgRelation != null) { ObjectFilter objSpecOrgRelationFilter = null; QName subjectRelation = specOrgRelation.getSubjectRelation(); for (ObjectReferenceType subjectParentOrgRef : principal.getUser() .getParentOrgRef()) { if (MiscSchemaUtil.compareRelation(subjectRelation, subjectParentOrgRef.getRelation())) { S_FilterEntryOrEmpty q = QueryBuilder.queryFor(ObjectType.class, prismContext); S_AtomicFilterExit q2; if (specOrgRelation.getScope() == null || specOrgRelation.getScope() == OrgScopeType.ALL_DESCENDANTS) { q2 = q.isChildOf(subjectParentOrgRef.getOid()); } else if (specOrgRelation.getScope() == OrgScopeType.DIRECT_DESCENDANTS) { q2 = q.isDirectChildOf(subjectParentOrgRef.getOid()); } else if (specOrgRelation.getScope() == OrgScopeType.ALL_ANCESTORS) { q2 = q.isParentOf(subjectParentOrgRef.getOid()); } else { throw new UnsupportedOperationException( "Unknown orgRelation scope " + specOrgRelation.getScope()); } if (BooleanUtils.isTrue(specOrgRelation.isIncludeReferenceOrg())) { q2 = q2.or().id(subjectParentOrgRef.getOid()); } objSpecOrgRelationFilter = ObjectQueryUtil .filterOr(objSpecOrgRelationFilter, q2.buildFilter()); } } if (objSpecOrgRelationFilter == null) { objSpecOrgRelationFilter = NoneFilter.createNone(); } objSpecSecurityFilter = ObjectQueryUtil.filterAnd(objSpecSecurityFilter, objSpecOrgRelationFilter); LOGGER.trace(" applying orgRelation filter {}", objSpecOrgRelationFilter); } else { LOGGER.trace(" orgRelation empty"); } // roleRelation if (specRoleRelation != null) { ObjectFilter objSpecRoleRelationFilter = processRoleRelationFilter(principal, autz, specRoleRelation, queryItemsSpec, origFilter); if (objSpecRoleRelationFilter == null) { if (autz.maySkipOnSearch()) { LOGGER.trace( " not applying roleRelation filter {} because it is not efficient and maySkipOnSearch is set", objSpecRoleRelationFilter); applicable = false; } else { objSpecRoleRelationFilter = NoneFilter.createNone(); } } if (objSpecRoleRelationFilter != null) { objSpecSecurityFilter = ObjectQueryUtil.filterAnd(objSpecSecurityFilter, objSpecRoleRelationFilter); LOGGER.trace(" applying roleRelation filter {}", objSpecRoleRelationFilter); } } else { LOGGER.trace(" roleRelation empty"); } if (objSpecTypeFilter != null) { objSpecTypeFilter.setFilter(objSpecSecurityFilter); objSpecSecurityFilter = objSpecTypeFilter; } traceFilter("objSpecSecurityFilter", objectSpecType, objSpecSecurityFilter); autzObjSecurityFilter = ObjectQueryUtil.filterOr(autzObjSecurityFilter, objSpecSecurityFilter); } } traceFilter("autzObjSecurityFilter", autz, autzObjSecurityFilter); if (applicable) { autzObjSecurityFilter = ObjectQueryUtil.simplify(autzObjSecurityFilter); // authority is applicable to this situation. now we can process the decision. AuthorizationDecisionType decision = autz.getDecision(); if (decision == null || decision == AuthorizationDecisionType.ALLOW) { // allow if (ObjectQueryUtil.isAll(autzObjSecurityFilter)) { // this is "allow all" authorization. hasAllowAll = true; } else { securityFilterAllow = ObjectQueryUtil.filterOr(securityFilterAllow, autzObjSecurityFilter); } if (!ObjectQueryUtil.isNone(autzObjSecurityFilter)) { queryItemsSpec.collectItems(autz); } } else { // deny if (autz.hasItemSpecification()) { // This is a tricky situation. We have deny authorization, but it only denies access to // some items. Therefore we need to find the objects and then filter out the items. // Therefore do not add this authorization into the filter. } else { if (ObjectQueryUtil.isAll(autzObjSecurityFilter)) { // This is "deny all". We cannot have anything stronger than that. // There is no point in continuing the evaluation. if (LOGGER.isTraceEnabled()) { LOGGER.trace("AUTZ {} done: principal={}, operation={}, phase={}: deny all", desc, getUsername(principal), prettyActionUrl(operationUrl), phase); } NoneFilter secFilter = NoneFilter.createNone(); traceFilter("secFilter", null, secFilter); return secFilter; } securityFilterDeny = ObjectQueryUtil.filterOr(securityFilterDeny, autzObjSecurityFilter); } } } traceFilter("securityFilterAllow", autz, securityFilterAllow); traceFilter("securityFilterDeny", autz, securityFilterDeny); } else { LOGGER.warn("Unknown authority type {} in user {}", authority.getClass(), getUsername(principal)); } } } traceFilter("securityFilterAllow", null, securityFilterAllow); traceFilter("securityFilterDeny", null, securityFilterDeny); if (LOGGER.isTraceEnabled()) { LOGGER.trace(" Final items: {}", queryItemsSpec.shortDump()); } List<ItemPath> unsatisfiedItems = queryItemsSpec.evaluateUnsatisfierItems(); if (!unsatisfiedItems.isEmpty()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace( "AUTZ {} done: principal={}, operation={}, phase={}: deny because items {} are not allowed", desc, getUsername(principal), prettyActionUrl(operationUrl), phase, unsatisfiedItems); } NoneFilter secFilter = NoneFilter.createNone(); traceFilter("secFilter", null, secFilter); return secFilter; } ObjectFilter origWithAllowFilter; if (hasAllowAll) { origWithAllowFilter = origFilter; } else if (securityFilterAllow == null) { // Nothing has been allowed. This means default deny. if (LOGGER.isTraceEnabled()) { LOGGER.trace("AUTZ {} done: principal={}, operation={}, phase={}: default deny", desc, getUsername(principal), prettyActionUrl(operationUrl), phase); } NoneFilter secFilter = NoneFilter.createNone(); traceFilter("secFilter", null, secFilter); return secFilter; } else { origWithAllowFilter = ObjectQueryUtil.filterAnd(origFilter, securityFilterAllow); } if (securityFilterDeny == null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("AUTZ {} done: principal={}, operation={}, phase={}: allow\n Filter:\n{}", desc, getUsername(principal), prettyActionUrl(operationUrl), phase, origWithAllowFilter == null ? "null" : origWithAllowFilter.debugDump(2)); } traceFilter("origWithAllowFilter", null, origWithAllowFilter); return origWithAllowFilter; } else { ObjectFilter secFilter = ObjectQueryUtil.filterAnd(origWithAllowFilter, NotFilter.createNot(securityFilterDeny)); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "AUTZ {} done: principal={}, operation={}, phase={}: allow (with deny clauses)\n Filter:\n{}", desc, getUsername(principal), prettyActionUrl(operationUrl), phase, secFilter == null ? "null" : secFilter.debugDump(2)); } traceFilter("secFilter", null, secFilter); return secFilter; } }
From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java
private void makeVcloudData(Farm farm, Long instanceNo, String instanceName, String instanceType, PlatformVcloud platformVcloud) { // VCloud??/* w w w . j a v a2s.c o m*/ VcloudInstance vcloudInstance = new VcloudInstance(); vcloudInstance.setInstanceNo(instanceNo); //VM?? //????????????NULL //(VCloud???????????) vcloudInstance.setVmName(null); // //??????? List<VcloudKeyPair> vcloudKeyPairs = vcloudKeyPairDao.readByUserNoAndPlatformNo(farm.getUserNo(), platformVcloud.getPlatformNo()); Long keyPairNo = vcloudKeyPairs.get(0).getKeyNo(); vcloudInstance.setKeyPairNo(keyPairNo); // List<PlatformVcloudStorageType> storageTypes = platformVcloudStorageTypeDao .readByPlatformNo(platformVcloud.getPlatformNo()); Collections.sort(storageTypes, Comparators.COMPARATOR_PLATFORM_VCLOUD_STORAGE_TYPE); vcloudInstance.setStorageTypeNo(storageTypes.get(0).getStorageTypeNo()); // vcloudInstance.setInstanceType(instanceType); //VCLOUD_INSTANCE? vcloudInstanceDao.create(vcloudInstance); //? //???PCC?????? //IaasGateWay???PCC???? //VCLOUD_INSTANCE_NETWORKPCC??? Boolean showPublicIp = BooleanUtils.toBooleanObject(Config.getProperty("ui.showPublicIp")); List<NetworkDto> networkDtos = iaasDescribeService.getNetworks(farm.getUserNo(), platformVcloud.getPlatformNo()); for (int i = 0; i < networkDtos.size(); i++) { NetworkDto networkDto = networkDtos.get(i); //PCC?? ???? //???IaasGateWay?????NULL //IP???????IaasGateWay?????NULL //PCC?????????1??? if (networkDto.isPcc() || (!networkDto.isPcc() && StringUtils.equals(networkDto.getNetworkName(), platformVcloud.getDefNetwork()))) { VcloudInstanceNetwork vcloudInstanceNetwork = new VcloudInstanceNetwork(); vcloudInstanceNetwork.setPlatformNo(platformVcloud.getPlatformNo()); vcloudInstanceNetwork.setInstanceNo(instanceNo); vcloudInstanceNetwork.setFarmNo(farm.getFarmNo()); vcloudInstanceNetwork.setNetworkName(networkDto.getNetworkName()); vcloudInstanceNetwork.setNetworkIndex(null); vcloudInstanceNetwork.setIpMode("POOL"); vcloudInstanceNetwork.setIpAddress(null); //config.properties?showPublicIp?= true PCC?? //config.properties?showPublicIp?= false ?(?)? if (networkDto.isPcc()) { vcloudInstanceNetwork.setIsPrimary(BooleanUtils.isTrue(showPublicIp)); } else if (StringUtils.equals(networkDto.getNetworkName(), platformVcloud.getDefNetwork())) { vcloudInstanceNetwork.setIsPrimary(BooleanUtils.isNotTrue(showPublicIp)); } //VCLOUD_INSTANCE_NETWORK? vcloudInstanceNetworkDao.create(vcloudInstanceNetwork); } } }
From source file:com.square.core.service.implementations.PersonneServiceImplementation.java
private Telephone creerOuMettreAJourTelephone(Set<Personne> personnes, TelephoneDto telephoneDto, Boolean impacterFamille) { // Vrification des dpendances final NatureTelephone natureTelephone = natureTelephoneDao .rechercherNatureTelephoneParId(telephoneDto.getNature().getIdentifiant()); if (natureTelephone == null) { throw new BusinessException(messageSourceUtil .get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_NATURE_TELEPHONE_INEXISTENT_EN_BD)); }//from w ww . j a v a2s . c o m final Pays paysTelephone = paysDao.rechercherPaysParId(telephoneDto.getPays().getId()); if (paysTelephone == null) { throw new BusinessException( messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PAYS_INEXISTENT_EN_BD)); } // On construit la liste des identifiants des persones de la famille final Set<Long> idsPersonnes = new LinkedHashSet<Long>(); for (Personne personne : personnes) { idsPersonnes.add(personne.getId()); } // On construit la liste des personnes associes au tlphone en cas de restauration final Set<Personne> nouvellesPersonnes = new LinkedHashSet<Personne>(); Long idPersonneModifie = null; for (Personne personne : personnes) { if (idPersonneModifie == null) { idPersonneModifie = personne.getId(); } nouvellesPersonnes.add(personne); if (BooleanUtils.isFalse(impacterFamille)) { break; } } // On supprime le formatage du numro de tlphone pour stocker les donnes brutes seulement final String numeroTelephone = formatUtil.supprimerFormatNumTel(telephoneDto.getNumero()); Telephone telephone; final Calendar maintenant = Calendar.getInstance(); if (telephoneDto.getId() != null) { // si le tlphone est supprimer if (BooleanUtils.isTrue(telephoneDto.getSupprime())) { final Telephone tel = telephoneDao.rechercherTelephoneParId(telephoneDto.getId()); supprimerTelephone(tel, maintenant); return tel; } else { // MODE MISE A JOUR // On rcupre le tlphone mettre jour telephone = telephoneDao.rechercherTelephoneParId(telephoneDto.getId()); if (telephone == null) { throw new BusinessException(messageSourceUtil .get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_TELEPHONE_INEXISTENT_EN_BD)); } // On vrifie que le tlphone n'existe pas dj dans la liste des tlphones de la personne final CritereRechercheTelephone critereTel = new CritereRechercheTelephone(); critereTel.setIdsPersonnes(idsPersonnes); critereTel.getIdsTelExclus().add(telephoneDto.getId()); critereTel.setNumeroTelephone(numeroTelephone); critereTel.setIsSupprime(null); final List<Telephone> listeTelephones = telephoneDao.rechercherTelephoneParCritere(critereTel); if (listeTelephones != null && listeTelephones.size() > 0) { // Ce tlphone existe dj, on le rcupre final Telephone telExistant = listeTelephones.get(0); // On le restaure restaurerTelephone(telExistant, nouvellesPersonnes, maintenant); // On supprime l'ancien tlphone supprimerTelephone(telephone, maintenant); return telExistant; } else { // MISE A JOUR DU TELEPHONE telephone.setDateModification(maintenant); telephone.setNumTelephone(numeroTelephone); telephone.setPays(paysTelephone); telephone.setNatureTelephone(natureTelephone); return telephone; } } } else { // MODE CREATION // On vrifie que le tlphone n'existe pas dj dans la liste des tlphones de la personne final CritereRechercheTelephone critereTel = new CritereRechercheTelephone(); critereTel.setIdsPersonnes(idsPersonnes); critereTel.setNumeroTelephone(numeroTelephone); critereTel.setIsSupprime(null); final List<Telephone> listeTelephones = telephoneDao.rechercherTelephoneParCritere(critereTel); if (listeTelephones != null && listeTelephones.size() > 0) { // Le tlphone existe dj, on le rcupre telephone = listeTelephones.get(0); // si le tlphone est de diffrente nature on lui change sa nature if (telephoneDto.getNature() != null && (telephone.getNatureTelephone() == null || !telephone .getNatureTelephone().getId().equals(telephoneDto.getNature().getIdentifiant()))) { telephone.setNatureTelephone(natureTelephone); return telephone; } // Mantis 8288 On vrifie que la liste des personnes rataches au numro ne contient // que la personne sur laquelle on veux changer le numro final List<String> listeNumerosPersonneFamilleConcernees = new ArrayList<String>(); for (Personne personneTel : telephone.getPersonnes()) { if (!idPersonneModifie.equals(personneTel.getId())) { listeNumerosPersonneFamilleConcernees.add(personneTel.getNum()); } } if (listeNumerosPersonneFamilleConcernees.size() > 0 && !telephone.isSupprime()) { String messageErreur = "Certains membres de la famille possdent dj le numro de tlphone " + telephone.getNumTelephone() + ", veuillez d'abord leur supprimer ou bien ne pas demander les impacter. Les numros des personnes concernes sont : "; final int nbNum = listeNumerosPersonneFamilleConcernees.size(); int compteur = 0; for (String num : listeNumerosPersonneFamilleConcernees) { compteur++; messageErreur = messageErreur + num + (compteur == nbNum ? "." : ", "); } throw new BusinessException(messageErreur); } // On restaure le tlphone restaurerTelephone(telephone, nouvellesPersonnes, maintenant); return telephone; } else { // CREATION D'UN NOUVEAU TELEPHONE telephone = new Telephone(); telephone.setDateCreation(maintenant); telephone.setNumTelephone(numeroTelephone); telephone.setPays(paysTelephone); telephone.setNatureTelephone(natureTelephone); if (telephoneDto.getIdext() != null) { telephone.setIdentifiantExterieur(telephoneDto.getIdext()); } return telephone; } } }
From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java
/** * Method sets default = false to all filters except the current one *//*from w w w .j a v a 2 s .c o m*/ protected void resetDefaultFilters() { for (FilterEntity filter : filterEntities) { if (!Objects.equals(filter, filterEntity)) { if (BooleanUtils.isTrue(filter.getIsDefault())) { filter.setIsDefault(false); } } } }
From source file:com.evolveum.midpoint.security.enforcer.impl.SecurityEnforcerImpl.java
/** * Very rudimentary and experimental implementation. *//*from w w w . ja va2s .c om*/ private ObjectFilter processRoleRelationFilter(MidPointPrincipal principal, Authorization autz, RoleRelationObjectSpecificationType specRoleRelation, AutzItemPaths queryItemsSpec, ObjectFilter origFilter) { ObjectFilter refRoleFilter = null; if (BooleanUtils.isTrue(specRoleRelation.isIncludeReferenceRole())) { // This could mean that we will need to add filters for all roles in // subject's roleMembershipRef. There may be thousands of these. if (!autz.maySkipOnSearch()) { throw new UnsupportedOperationException( "Inefficient roleRelation search (includeReferenceRole=true) is not supported yet"); } } ObjectFilter membersFilter = null; if (!BooleanUtils.isFalse(specRoleRelation.isIncludeMembers())) { List<PrismReferenceValue> queryRoleRefs = getRoleOidsFromFilter(origFilter); if (queryRoleRefs == null || queryRoleRefs.isEmpty()) { // Cannot find specific role OID in original query. This could mean that we // will need to add filters for all roles in subject's roleMembershipRef. // There may be thousands of these. if (!autz.maySkipOnSearch()) { throw new UnsupportedOperationException( "Inefficient roleRelation search (includeMembers=true without role in the original query) is not supported yet"); } } else { QName subjectRelation = specRoleRelation.getSubjectRelation(); boolean isRoleOidOk = false; for (ObjectReferenceType subjectRoleMembershipRef : principal.getUser().getRoleMembershipRef()) { if (!MiscSchemaUtil.compareRelation(subjectRelation, subjectRoleMembershipRef.getRelation())) { continue; } if (!PrismReferenceValue.containsOid(queryRoleRefs, subjectRoleMembershipRef.getOid())) { continue; } isRoleOidOk = true; break; } if (isRoleOidOk) { // There is already a good filter in the origFilter // TODO: mind the objectRelation membersFilter = AllFilter.createAll(); } else { membersFilter = NoneFilter.createNone(); } } } return ObjectQueryUtil.filterOr(refRoleFilter, membersFilter); }
From source file:com.evolveum.midpoint.model.impl.controller.ModelInteractionServiceImpl.java
@Override public ExecuteCredentialResetResponseType executeCredentialsReset(PrismObject<UserType> user, ExecuteCredentialResetRequestType executeCredentialResetRequest, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, PolicyViolationException { LocalizableMessageBuilder builder = new LocalizableMessageBuilder(); ExecuteCredentialResetResponseType response = new ExecuteCredentialResetResponseType(prismContext); String resetMethod = executeCredentialResetRequest.getResetMethod(); if (StringUtils.isBlank(resetMethod)) { LocalizableMessage localizableMessage = builder .fallbackMessage("Failed to execute reset password. Bad request.") .key("execute.reset.credential.bad.request").build(); response = response.message(LocalizationUtil.createLocalizableMessageType(localizableMessage)); throw new SchemaException(localizableMessage); }/*from w w w.j av a 2 s . co m*/ SecurityPolicyType securityPolicy = getSecurityPolicy(user, task, parentResult); CredentialsResetPolicyType resetPolicyType = securityPolicy.getCredentialsReset(); //TODO: search according tot he credentialID and others if (resetPolicyType == null) { LocalizableMessage localizableMessage = builder .fallbackMessage("Failed to execute reset password. Bad configuration.") .key("execute.reset.credential.bad.configuration").build(); response = response.message(LocalizationUtil.createLocalizableMessageType(localizableMessage)); throw new SchemaException(localizableMessage); } if (!resetMethod.equals(resetPolicyType.getName())) { LocalizableMessage localizableMessage = builder .fallbackMessage("Failed to execute reset password. Bad method.") .key("execute.reset.credential.bad.method").build(); response = response.message(LocalizationUtil.createLocalizableMessageType(localizableMessage)); throw new SchemaException(localizableMessage); } CredentialSourceType credentialSourceType = resetPolicyType.getNewCredentialSource(); if (credentialSourceType == null) { //TODO: go through deprecated functionality LocalizableMessage localizableMessage = builder .fallbackMessage("Failed to execute reset password. No credential source.") .key("execute.reset.credential.no.credential.source").build(); response = response.message(LocalizationUtil.createLocalizableMessageType(localizableMessage)); //for now just let the user know that he needs to specify it return response; } ValuePolicyType valuePolicy = getValuePolicy(user, task, parentResult); ObjectDelta<UserType> userDelta = null; if (credentialSourceType.getUserEntry() != null) { PolicyItemDefinitionType policyItemDefinitione = new PolicyItemDefinitionType(); policyItemDefinitione.setValue(executeCredentialResetRequest.getUserEntry()); if (!validateValue(user, valuePolicy, policyItemDefinitione, task, parentResult)) { LOGGER.error("Cannot execute reset password. New password doesn't satisfy policy constraints"); parentResult.recordFatalError( "Cannot execute reset password. New password doesn't satisfy policy constraints"); LocalizableMessage localizableMessage = builder .fallbackMessage("New password doesn't satisfy policy constraints.") .key("execute.reset.credential.validation.failed").build(); throw new PolicyViolationException(localizableMessage); } ProtectedStringType newProtectedPassword = new ProtectedStringType(); newProtectedPassword.setClearValue(executeCredentialResetRequest.getUserEntry()); userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, user.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, prismContext, newProtectedPassword); } if (BooleanUtils.isTrue(resetPolicyType.isForceChange())) { if (userDelta != null) { userDelta.addModificationReplaceProperty(SchemaConstants.PATH_PASSWORD_FORCE_CHANGE, Boolean.TRUE); } } try { Collection<ObjectDeltaOperation<? extends ObjectType>> result = modelService.executeChanges( MiscUtil.createCollection(userDelta), ModelExecuteOptions.createRaw(), task, parentResult); } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException | ObjectAlreadyExistsException | PolicyViolationException e) { response.message( LocalizationUtil.createForFallbackMessage("Failed to reset credential: " + e.getMessage())); throw e; } parentResult.recomputeStatus(); LocalizableMessage message = builder.fallbackMessage("Reset password was successful") .key("execute.reset.credential.successful").fallbackLocalizableMessage(null).build(); response.setMessage(LocalizationUtil.createLocalizableMessageType(message)); return response; }