@Override public String disable(final ScalarModel scalarModel) { final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(); final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(); try { final AuthenticationSession session = scalarModel.getAuthenticationSession(); final Consent usable = property.isUsable(session, parentAdapter); return usable.isAllowed() ? null : usable.getReason(); } catch (final Exception ex) { return ex.getLocalizedMessage(); } }
@Override public String whetherDisabled(final ScalarModel scalarModel, final Where where) { final ObjectAdapter parentAdapter = scalarModel.getParentEntityModel().load(); final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(scalarModel.getSpecificationLoader()); try { final Consent usable = property.isUsable(parentAdapter, InteractionInitiatedBy.USER, where); return usable.isAllowed() ? null : usable.getReason(); } catch (final Exception ex) { return ex.getLocalizedMessage(); } }
@Override public String disable(final ScalarModel scalarModel, final Where where) { final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter( ConcurrencyChecking.CHECK, scalarModel.getPersistenceSession(), scalarModel.getSpecificationLoader()); final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(scalarModel.getSpecificationLoader()); try { final Consent usable = property.isUsable(parentAdapter, InteractionInitiatedBy.USER, where); return usable.isAllowed() ? null : usable.getReason(); } catch (final Exception ex) { return ex.getLocalizedMessage(); } }
final Consent usable = property.isUsable(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere()); if (usable.isVetoed()) { propertyRepr.mapPut("invalidReason", usable.getReason());
final JsonRepresentation propertyRepr = propertiesList.getRepresentation(id); final Consent visibility = property.isVisible(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere()); final Consent usability = property.isUsable(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere());
resourceContext.getInteractionInitiatedBy(), resourceContext.getWhere()); final Consent usability = property.isUsable( objectAdapter, resourceContext.getInteractionInitiatedBy(),
@Test(expected = DisabledException.class) public void shouldNotBeAbleToModifyProperty() { // given final DisabledFacet disabledFacet = new DisabledFacetAbstractAlwaysEverywhere(mockPasswordMember){}; facets = Arrays.asList(disabledFacet, new PropertySetterFacetViaSetterMethod(setPasswordMethod, mockPasswordMember)); final Consent visibilityConsent = new Allow(new InteractionResult(new PropertyVisibilityEvent(employeeDO, null))); final InteractionResult usabilityInteractionResult = new InteractionResult(new PropertyUsabilityEvent(employeeDO, null)); usabilityInteractionResult.advise("disabled", disabledFacet); final Consent usabilityConsent = new Veto(usabilityInteractionResult); context.checking(new Expectations() { { allowing(mockPasswordMember).streamFacets(); will(returnValue(facets.stream())); allowing(mockPasswordMember).isVisible(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE); will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent)); } }); // when employeeWO.setPassword(passwordValue); // then should throw exception }
@Test(expected = DisabledException.class) public void shouldNotBeAbleToModifyProperty() { // given final DisabledFacet disabledFacet = new DisabledFacetAbstractAlwaysEverywhere(mockPasswordMember){}; facets = Arrays.asList(disabledFacet, new PropertySetterFacetViaSetterMethod(setPasswordMethod, mockPasswordMember)); final Consent visibilityConsent = new Allow(new InteractionResult(new PropertyVisibilityEvent(employeeDO, null))); final InteractionResult usabilityInteractionResult = new InteractionResult(new PropertyUsabilityEvent(employeeDO, null)); usabilityInteractionResult.advise("disabled", disabledFacet); final Consent usabilityConsent = new Veto(usabilityInteractionResult); context.checking(new Expectations() { { allowing(mockPasswordMember).getFacets(with(any(Filter.class))); will(returnValue(facets)); allowing(mockPasswordMember).isVisible(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE); will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent)); } }); // when employeeWO.setPassword(passwordValue); // then should throw exception }
will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent));
will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent));