Creates an audit entry for the 'plan updated' event.
@param bean the bean
@param data the updated data
@param securityContext the security context
@return the audit entry
431381
public static AuditEntryBean planUpdated(PlanBean bean, EntityUpdatedData data,
            ISecurityContext securityContext) {
        if (data.getChanges().isEmpty()) {
            return null;
        }
        AuditEntryBean entry = newEntry(bean.getOrganization().getId(), AuditEntityType.Plan, securityContext);
        entry.setEntityId(bean.getId());
        entry.setEntityVersion(null);
        entry.setWhat(AuditEntryType.Update);
        entry.setData(toJSON(data));
        return entry;
    }
36861
public Resolution intercept(ExecutionContext executionContext)
			throws Exception
	{
		Resolution resolution;

		if (securityManager != null)
		{
			// Add the security manager to the request.
			// This is used (for example) by the security tag.
			executionContext.getActionBeanContext().getRequest().setAttribute(SecurityInterceptor.SECURITY_MANAGER,
                    securityManager);
			
			switch (executionContext.getLifecycleStage())
			{
				case BindingAndValidation:
				case CustomValidation:
					resolution = interceptBindingAndValidation(executionContext);
					break;
				case EventHandling:
					resolution = interceptEventHandling(executionContext);
					break;
				case ResolutionExecution:
					resolution = interceptResolutionExecution(executionContext);
					break;
				default: // Should not happen (see @Intercepts annotation on class)
					resolution = executionContext.proceed();
					break;
			}
		}
		else
		{
			// There is no security manager, so everything is allowed.

			resolution = executionContext.proceed();
		}

		return resolution;
	}
1023067
public Principal createUser(final SecurityContext securityContext, final PropertyKey credentialKey, final String credentialValue, final String confKey) {

		return createUser(securityContext, credentialKey, credentialValue, Collections.EMPTY_MAP, confKey);

	}
1136377
public void setSecurityContext(final SecurityContext sc) {

		if (securityContext == null) {

			if (sc.isSuperUserSecurityContext() == Boolean.FALSE) {

				securityContext = sc;
			}
		}
	}
1358430
protected ContractBean createContractInternal(String organizationId, String clientId,
            String version, NewContractBean bean) throws StorageException, Exception {
        ContractBean contract;
        ClientVersionBean cvb;
        cvb = storage.getClientVersion(organizationId, clientId, version);
        if (cvb == null) {
            throw ExceptionFactory.clientVersionNotFoundException(clientId, version);
        }
        if (cvb.getStatus() == ClientStatus.Retired) {
            throw ExceptionFactory.invalidClientStatusException();
        }
        ApiVersionBean avb = storage.getApiVersion(bean.getApiOrgId(), bean.getApiId(), bean.getApiVersion());
        if (avb == null) {
            throw ExceptionFactory.apiNotFoundException(bean.getApiId());
        }
        if (avb.getStatus() != ApiStatus.Published) {
            throw ExceptionFactory.invalidApiStatusException();
        }
        Set<ApiPlanBean> plans = avb.getPlans();
        String planVersion = null;
        if (plans != null) {
            for (ApiPlanBean apiPlanBean : plans) {
                if (apiPlanBean.getPlanId().equals(bean.getPlanId())) {
                    planVersion = apiPlanBean.getVersion();
                }
            }
        }
        if (planVersion == null) {
            throw ExceptionFactory.planNotFoundException(bean.getPlanId());
        }
        PlanVersionBean pvb = storage.getPlanVersion(bean.getApiOrgId(), bean.getPlanId(), planVersion);
        if (pvb == null) {
            throw ExceptionFactory.planNotFoundException(bean.getPlanId());
        }
        if (pvb.getStatus() != PlanStatus.Locked) {
            throw ExceptionFactory.invalidPlanStatusException();
        }

        contract = new ContractBean();
        contract.setClient(cvb);
        contract.setApi(avb);
        contract.setPlan(pvb);
        contract.setCreatedBy(securityContext.getCurrentUser());
        contract.setCreatedOn(new Date());

        // Move the client to the "Ready" state if necessary.
        if (cvb.getStatus() == ClientStatus.Created && clientValidator.isReady(cvb, true)) {
            cvb.setStatus(ClientStatus.Ready);
        }

        storage.createContract(contract);
        storage.createAuditEntry(AuditUtils.contractCreatedFromClient(contract, securityContext));
        storage.createAuditEntry(AuditUtils.contractCreatedToApi(contract, securityContext));

        // Update the version with new meta-data (e.g. modified-by)
        cvb.setModifiedBy(securityContext.getCurrentUser());
        cvb.setModifiedOn(new Date());
        storage.updateClientVersion(cvb);

        return contract;
    }
1230854
@Override
  public boolean writeEvent(AuditEvent event) throws HandlerException {
    StringBuilder elements = new StringBuilder();
    for (Field element : event.getFields()) {
      elements.append(
        element.getName() + " " + element.getType() + ":" + element.getValue() + ", ");
    }

    try (Connection conn = getConnection()) {
      try (PreparedStatement statement = conn.prepareStatement(insertQuery)) {
        statement.setString(1, event.getUuid().toString());
        statement.setTimestamp(2, new Timestamp(event.getTimestamp().getTime()));
        statement.setString(3, event.getActor());
        statement.setString(4, event.getOrigin());
        statement.setString(5, event.getAction());
        statement.setString(6, elements.toString());

        return statement.execute();
      }
    } catch (SQLException e) {
      throw new HandlerException("SQL Exception", DatabaseAuditHandler.class, e);
    }
  }
989238
public synchronized void setBeanContext(BeanContext beanContext)
        throws PropertyVetoException
    {
        ControlBeanContext cbcs = null;

        if (beanContext != null)
        {
            //
            // ControlBeans can only be nested in context service instances that derive
            // from ControlBeanContext.
            //
            if (!(beanContext instanceof ControlBeanContext))
            {
                PropertyChangeEvent pce = new PropertyChangeEvent(_bean, "beanContext", getBeanContext(), beanContext);
                throw new PropertyVetoException("Context does not support nesting controls: " +
                                                beanContext.getClass(), pce);
            }

            cbcs = (ControlBeanContext)beanContext;
        }


        _beanContextServicesDelegate.setBeanContext(beanContext);

        resetControlID();

        _hasSingleThreadedParent = cbcs != null ? cbcs.isSingleThreadedContainer() : false;

        //
        // Notify the bean that its context (container) has been set.
        //
        if (_bean != null)
            _bean.setBeanContext(beanContext);
    }
217249
public static AuditEntryBean planVersionUpdated(PlanVersionBean bean, EntityUpdatedData data,
            ISecurityContext securityContext) {
        if (data.getChanges().isEmpty()) {
            return null;
        }
        AuditEntryBean entry = newEntry(bean.getPlan().getOrganization().getId(), AuditEntityType.Plan, securityContext);
        entry.setEntityId(bean.getPlan().getId());
        entry.setEntityVersion(bean.getVersion());
        entry.setWhat(AuditEntryType.Update);
        entry.setData(toJSON(data));
        return entry;
    }
863850
public void setContextParameters(
            Map<String, String> principals,
            Map<String, String> credentials,
            String ctxName,
            ISecurityContext securityContext) {

        if (log.isDebugEnabled()) {
            final StringBuilder msg = new StringBuilder();
            msg.append("Preparing to authenticate;  setting parameters for context name '")
                    .append(ctxName)
                    .append("', context class '")
                    .append(securityContext.getClass().getName())
                    .append("'");
            // Display principalTokens...
            msg.append("\n\t Available Principal Tokens");
            for (final Object o : principals.entrySet()) {
                final Map.Entry<?, ?> y = (Map.Entry<?, ?>) o;
                msg.append("\n\t\t").append(y.getKey()).append("=").append(y.getValue());
            }
            // Keep credentialTokens secret, but indicate whether they were provided...
            msg.append("\n\t Available Credential Tokens");
            for (final Object o : credentials.entrySet()) {
                final Map.Entry<?, ?> y = (Map.Entry<?, ?>) o;
                final String val = (String) y.getValue();
                String valWasSpecified = null;
                if (val != null) {
                    valWasSpecified = val.trim().length() == 0 ? "empty" : "provided";
                }
                msg.append("\n\t\t").append(y.getKey()).append(" was ").append(valWasSpecified);
            }
            log.debug(msg.toString());
        }

        String username = principals.get(ctxName);
        String credential = credentials.get(ctxName);
        // If username or credential are null, this indicates that the token was not
        // set in security.properties. We will then use the value for root.
        username = username != null ? username : (String) principals.get(BASE_CONTEXT_NAME);
        credential = credential != null ? credential : (String) credentials.get(BASE_CONTEXT_NAME);
        if (log.isDebugEnabled()) {
            log.debug("Authentication::setContextParameters() username: " + username);
        }
        // Retrieve and populate an instance of the principal object
        final IPrincipal principalInstance = securityContext.getPrincipalInstance();
        if (username != null && !username.equals("")) {
            principalInstance.setUID(username);
        }
        // Retrieve and populate an instance of the credentials object
        final IOpaqueCredentials credentialsInstance =
                securityContext.getOpaqueCredentialsInstance();
        if (credentialsInstance != null) {
            credentialsInstance.setCredentials(credential);
        }
    }
1238458
@Override
	public AuditFileWriter write(String event) {

		String str2 = event + CoreConstants.NEW_LINE;
		out.put(str2.getBytes(Charset.forName("UTF-8")));
		return this;
	}
1300221
@Transactional(MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN)
    @Override
    public BitIntegrityReport addReport(String account,
                                        String storeId,
                                        String spaceId,
                                        String reportSpaceId,
                                        String reportContentId,
                                        BitIntegrityReportResult result,
                                        Date completionDate) {
        BitIntegrityReport report = new BitIntegrityReport();
        report.setModified(new Date());
        report.setAccount(account);
        report.setStoreId(storeId);
        report.setSpaceId(spaceId);
        report.setReportSpaceId(reportSpaceId);
        report.setReportContentId(reportContentId);
        report.setCompletionDate(new Date());
        report.setResult(result);
        report.setDisplay(!result.equals(BitIntegrityReportResult.FAILURE));
        return this.bitReportRepo.saveAndFlush(report);
    }
223852
protected void store(SecurityEvent auditEvent) throws Exception {
		if (myDataStore == null)
			throw new InternalErrorException("No data store provided to persist audit events");
		myDataStore.store(auditEvent);
	}
393431
public static ServerSentEvent withEventId(ByteBuf eventId, ByteBuf data) {
        return new ServerSentEvent(eventId, null, data);
    }
528614
public static Object execute(final SecurityContext securityContext, final GraphObject entity, final String source, final String methodName, final ModificationQueue modificationEvents) throws FrameworkException, UnlicensedScriptException {

		final Map<String, Object> parameters = new LinkedHashMap<>();

		parameters.put("modifications", modificationEvents.getModifications(entity));

		return execute(securityContext, entity, source, parameters, methodName);
	}
1308819
public static XContentBuilder marshall(AuditEntryBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("organizationId", bean.getOrganizationId())
                    .field("entityId", bean.getEntityId())
                    .field("entityType", bean.getEntityType())
                    .field("entityVersion", bean.getEntityVersion())
                    .field("data", bean.getData())
                    .field("who", bean.getWho())
                    .field("what", bean.getWhat())
                    .field("createdOn", bean.getCreatedOn().getTime())
                .endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
7482
public static AuditEntryBean contractBrokenToApi(ContractBean bean, ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getApi().getApi().getOrganization().getId(), AuditEntityType.Api, securityContext);
        entry.setWhat(AuditEntryType.BreakContract);
        entry.setEntityId(bean.getApi().getApi().getId());
        entry.setEntityVersion(bean.getApi().getVersion());
        ContractData data = new ContractData(bean);
        entry.setData(toJSON(data));
        return entry;
    }
521138
public static AuditableExecutionResult of(final AuditableContext context) {
        val builder = AuditableExecutionResult.builder();
        context.getTicketGrantingTicket().ifPresent(builder::ticketGrantingTicket);
        context.getAuthentication().ifPresent(builder::authentication);
        context.getAuthenticationResult().ifPresent(builder::authenticationResult);
        context.getRegisteredService().ifPresent(builder::registeredService);
        context.getService().ifPresent(builder::service);
        context.getServiceTicket().ifPresent(builder::serviceTicket);
        builder.properties(context.getProperties());
        return builder.build();
    }