Creates an {@link AuditEntryBean} for the 'organization created' event.
@param bean the bean
@param securityContext the security context
@return the audit entry
160189
public static AuditEntryBean organizationCreated(OrganizationBean bean, ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getId(), AuditEntityType.Organization, securityContext);
        entry.setEntityId(null);
        entry.setEntityVersion(null);
        entry.setWhat(AuditEntryType.Create);
        return entry;
    }
660192
protected @Nonnull <T> T createBean(@Nullable BeanResolutionContext resolutionContext, @Nonnull Class<T> beanType, @Nullable Qualifier<T> qualifier) {
        ArgumentUtils.requireNonNull("beanType", beanType);

        Optional<BeanDefinition<T>> concreteCandidate = findConcreteCandidate(beanType, qualifier, true, false);
        if (concreteCandidate.isPresent()) {
            BeanDefinition<T> candidate = concreteCandidate.get();
            if (resolutionContext == null) {
                resolutionContext = new DefaultBeanResolutionContext(this, candidate);
            }
            T createBean = doCreateBean(resolutionContext, candidate, qualifier, false, null);
            if (createBean == null) {
                throw new NoSuchBeanException(beanType);
            }
            return createBean;
        }
        throw new NoSuchBeanException(beanType);
    }
612560
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if( bean instanceof AuthenticationAware || bean instanceof LoginAware ) {

            // If the bean isn't a singleton, then add it to our list
            if( beanName == null || !getApplicationContext().containsBean( beanName )
                    || !getApplicationContext().isSingleton( beanName ) ) {
                addToNonSingletonListeners( bean );
            }

            // Install the last known authentication token
            if( bean instanceof AuthenticationAware ) {
                if( logger.isDebugEnabled() )
                    logger.debug( "NOTIFY bean '" + bean + "' of new authorization for '" + currentAuthentication
                            + "'" );

                AuthenticationAware aab = (AuthenticationAware) bean;
                aab.setAuthenticationToken(currentAuthentication);
            }
        }
        return bean;
    }
1336248
private MBeanPluginContext createMBeanPluginContext() {
        return new MBeanPluginContext() {
            public ObjectName registerMBean(Object pMBean, String... pOptionalName) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException {
                return MBeanServerHandler.this.registerMBean(pMBean, pOptionalName);
            }

            public void each(ObjectName pObjectName, MBeanEachCallback pCallback) throws IOException, ReflectionException, MBeanException {
                mBeanServerManager.each(pObjectName,pCallback);
            }

            public <R> R call(ObjectName pObjectName, MBeanAction<R> pMBeanAction, Object... pExtraArgs) throws IOException, ReflectionException, MBeanException, AttributeNotFoundException, InstanceNotFoundException {
                return mBeanServerManager.call(pObjectName,pMBeanAction,pExtraArgs);
            }

            public Set<ObjectName> queryNames(ObjectName pObjectName) throws IOException {
                return mBeanServerManager.queryNames(pObjectName);
            }

            public boolean hasMBeansListChangedSince(long pTimestamp) {
                return mBeanServerManager.hasMBeansListChangedSince(pTimestamp);
            }
        };
    }
1288194
@Override
    public String format(AuditEvent event) {
        String formatText = super.format(event);

        try {
            return util.encrypt(formatText);
        } catch (InvalidKeyException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (IllegalBlockSizeException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (BadPaddingException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (UnsupportedEncodingException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (InvalidAlgorithmParameterException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (NoSuchAlgorithmException e) {
            throw new Audit4jRuntimeException("", e);
        } catch (NoSuchPaddingException e) {
            throw new Audit4jRuntimeException("", e);
        }
    }
387804
public static AuditEntryBean contractBrokenFromClient(ContractBean bean, ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getClient().getClient().getOrganization().getId(), AuditEntityType.Client, securityContext);
        entry.setWhat(AuditEntryType.BreakContract);
        entry.setEntityId(bean.getClient().getClient().getId());
        entry.setEntityVersion(bean.getClient().getVersion());
        ContractData data = new ContractData(bean);
        entry.setData(toJSON(data));
        return entry;
    }
570432
@Internal
    @SuppressWarnings({"WeakerAccess", "unused"})
    @UsedByGeneratedCode
    protected Object injectBean(BeanResolutionContext resolutionContext, BeanContext context, Object bean) {
        return bean;
    }
1299077
public static AuditEntryBean clientRegistered(ClientVersionBean bean,
            ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getClient().getOrganization().getId(), AuditEntityType.Client, securityContext);
        entry.setEntityId(bean.getClient().getId());
        entry.setEntityVersion(bean.getVersion());
        entry.setWhat(AuditEntryType.Register);
        return entry;
    }
82349
public static AuditEntryBean planCreated(PlanBean bean, ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getOrganization().getId(), AuditEntityType.Plan, securityContext);
        entry.setEntityId(bean.getId());
        entry.setEntityVersion(null);
        entry.setData(null);
        entry.setWhat(AuditEntryType.Create);
        return entry;
    }
1107917
@Override
    public AuditOutputStream<AuditEvent> write(AuditEvent event) {
         outputStream.write(handler.enhanceFromMetadata(event));
         return outputStream;
    }
637985
private void addAuditRecord(Context context,
                                DOWriter w,
                                String action,
                                String componentID,
                                String justification,
                                Date nowUTC) throws ServerException {
        AuditRecord audit = new AuditRecord();
        audit.id = w.newAuditRecordID();
        audit.processType = "Fedora API-M";
        audit.action = action;
        audit.componentID = componentID;
        audit.responsibility =
                context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri);
        audit.date = nowUTC;
        audit.justification = justification;
        w.getAuditRecords().add(audit);
    }
1370264
@Override
    public JMSContext createContext(String userName, String password, int sessionMode) throws JMSRuntimeException, JMSSecurityRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createContext", new Object[] { userName, password, sessionMode });

        JmsConnectionImpl jmsConnection = null;
        JMSContext jmsContext = null;
        try {

            //CTS test failure was reported when the session mode was passed as -1,  so adding the validation
            switch (sessionMode)
            {
                case JMSContext.AUTO_ACKNOWLEDGE:
                case JMSContext.CLIENT_ACKNOWLEDGE:
                case JMSContext.DUPS_OK_ACKNOWLEDGE:
                case JMSContext.SESSION_TRANSACTED: {
                    break;
                }
                default:
                    throw (JMSRuntimeException) JmsErrorUtils.newThrowable(JMSRuntimeException.class,
                                                                           "INVALID_ACKNOWLEDGE_MODE_CWSIA0514",
                                                                           new Object[] { sessionMode },
                                                                           tc
                                    );
            }

            // Create JMSConnection to pass into JMSContext
            jmsConnection = (JmsConnectionImpl) createConnection(userName, password);
            jmsContext = new JmsJMSContextImpl(jmsConnection, sessionMode, true);
        } catch (JMSSecurityException jmsse) {
            throw (JMSSecurityRuntimeException) JmsErrorUtils.getJMS2Exception(jmsse, JMSSecurityRuntimeException.class);
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createContext", jmsContext);
        }
        return jmsContext;

    }
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;
	}
822598
@SuppressWarnings("unchecked")
    @Override
    @FFDCIgnore({ EntryNotFoundException.class, RegistryException.class })
    public Root search(Root root) throws WIMException {
        final String METHODNAME = "search";
        String uniqueName = null;
        Root returnRoot = new Root();

        AuditManager auditManager = new AuditManager();

        List<Entity> entitys = root.getEntities();
        if (entitys != null && !entitys.isEmpty()) {
            Entity entitee = entitys.get(0);
            if (entitee != null) {
                IdentifierType identifier = entitee.getIdentifier();
                if (identifier != null)
                    uniqueName = identifier.getUniqueName();
            }
        }

        try {
            int countLimit = 0;

            Map<String, Control> ctrlMap = ControlsHelper.getControlMap(root);
            SearchControl searchControl = (SearchControl) ctrlMap.get(SchemaConstants.DO_SEARCH_CONTROL);

            if (searchControl.isSetCountLimit()) {
                countLimit = searchControl.getCountLimit();
            }

            String expression = searchControl.getExpression();
            if (expression == null || expression.trim().length() == 0) {
                Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.SEARCH_AUDIT, reposId, uniqueName,
                            userRegistry.getRealm(),
                            returnRoot,
                            Integer.valueOf("217"), AuditConstants.URBRIDGE);
                throw new SearchControlException(WIMMessageKey.MISSING_SEARCH_EXPRESSION, Tr.formatMessage(tc, WIMMessageKey.MISSING_SEARCH_EXPRESSION));
            }

            URBridgeXPathHelper xpathHelper = new URBridgeXPathHelper(expression);
            expression = xpathHelper.getExpression();

            boolean returnSubType = searchControl.isReturnSubType();
            List<String> entityTypes = xpathHelper.getEntityTypes();
            Set<String> entityTypeSet = new HashSet<String>();
            List<String> entityTypeList = null;

            if (returnSubType) {
                for (int i = 0; i < entityTypes.size(); i++) {
                    String type = entityTypes.get(i);
                    Set<String> subTypes = Entity.getSubEntityTypes(type);
                    entityTypeSet.add(type);
                    if (subTypes != null) {
                        entityTypeSet.addAll(subTypes);
                    }
                }
            } else {
                entityTypeSet.addAll(entityTypes);
            }
            entityTypeList = new ArrayList<String>(entityTypeSet);

            if (tc.isDebugEnabled())
                Tr.debug(tc, METHODNAME + " entityType List: " + entityTypeList);

            String type;
            for (int i = 0; i < entityTypeList.size(); i++) {
                type = entityTypeList.get(i);
                if (Service.DO_GROUP.equalsIgnoreCase(type) || Entity.getSubEntityTypes(Service.DO_GROUP).contains(type)) {
                    List<String> searchAttrs = getAttributes(searchControl, type);
                    List<String> returnNames = new ArrayList<String>();

                    if (isSafRegistry() && !expression.endsWith(SchemaConstants.VALUE_WILD_CARD)) {
                        try {
                            returnNames.add(userRegistry.getGroupSecurityName(expression));
                        } catch (EntryNotFoundException enfe) {
                        } catch (RegistryException re) {
                        }
                    } else {
                        if (!expression.contains(SchemaConstants.VALUE_WILD_CARD)) {
                            countLimit = 1;
                        }

                        returnNames = searchGroups(expression, countLimit).getList();
                    }
                    if (returnNames.size() > 0) {
                        URBridgeEntityFactory osEntityFactory = new URBridgeEntityFactory();
                        for (int j = 0; j < returnNames.size(); j++) {
                            Entity matchDO = null;

                            if (type.equalsIgnoreCase(Service.DO_PERSON_ACCOUNT))
                                matchDO = new PersonAccount();
                            else
                                matchDO = new Group();

                            returnRoot.getEntities().add(matchDO);
                            IdentifierType id = new IdentifierType();
                            matchDO.setIdentifier(id);
                            // Populate the entity with all requested attributes.
                            URBridgeEntity osEntity = osEntityFactory.createObject(matchDO, this, propsMap, baseEntryName,
                                                                                   entityConfigMap);
                            osEntity.setSecurityNameProp(returnNames.get(j));
                            osEntity.populateEntity(searchAttrs);
                            //set identifier
                            id.setRepositoryId(reposId);
                        }
                    }
                    break;
                }
            }
            for (int i = 0; i < entityTypeList.size(); i++) {
                type = entityTypeList.get(i);
                if (Entity.getSubEntityTypes(Service.DO_LOGIN_ACCOUNT).contains(type)) {
                    List<String> searchAttrs = getAttributes(searchControl, type);
                    List<String> returnNames = new ArrayList<String>();

                    if (isSafRegistry() && !expression.endsWith(SchemaConstants.VALUE_WILD_CARD)) {
                        try {
                            returnNames.add(userRegistry.getUserSecurityName(expression));
                        } catch (EntryNotFoundException enfe) {
                        } catch (RegistryException re) {
                        }
                    } else {
                        if (!expression.contains(SchemaConstants.VALUE_WILD_CARD)) {
                            countLimit = 1;
                        }
                        returnNames = searchUsers(expression, countLimit).getList();
                    }
                    if (returnNames.size() > 0) {
                        URBridgeEntityFactory osEntityFactory = new URBridgeEntityFactory();
                        if (type.equalsIgnoreCase(Service.DO_LOGIN_ACCOUNT)) {
                            type = URBridgeHelper.getPersonAccountType();
                        }

                        for (int j = 0; j < returnNames.size(); j++) {
                            Entity matchDO = new PersonAccount();
                            returnRoot.getEntities().add(matchDO);
                            IdentifierType id = new IdentifierType();
                            matchDO.setIdentifier(id);
                            // Populate the entity with all requested attributes.
                            URBridgeEntity osEntity = osEntityFactory.createObject(matchDO, this, propsMap, baseEntryName,
                                                                                   entityConfigMap);
                            osEntity.setSecurityNameProp(returnNames.get(j));
                            osEntity.populateEntity(searchAttrs);
                            //set identifier
                            id.setRepositoryId(reposId);
                        }
                    }
                    break;
                }
            }
        } catch (WIMException we) {
            throw we;
        } catch (Exception e) {
            Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.SEARCH_AUDIT, reposId, uniqueName, userRegistry.getRealm(),
                        returnRoot,
                        Integer.valueOf("221"), AuditConstants.URBRIDGE);
            throw new WIMApplicationException(WIMMessageKey.ENTITY_SEARCH_FAILED, Tr.formatMessage(tc, WIMMessageKey.ENTITY_SEARCH_FAILED,
                                                                                                   WIMMessageHelper.generateMsgParms(e.toString())));
        }

        if (returnRoot != null && !returnRoot.getEntities().isEmpty()) {
            auditManager.setRealm(userRegistry.getRealm());
            Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.SEARCH_AUDIT, reposId, uniqueName, userRegistry.getRealm(),
                        returnRoot,
                        Integer.valueOf("200"), AuditConstants.URBRIDGE);
        }
        return returnRoot;
    }
879533
public static AuditEntryBean unmarshallAuditEntry(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        AuditEntryBean bean = new AuditEntryBean();
        bean.setId(asLong(source.get("id")));
        bean.setOrganizationId(asString(source.get("organizationId")));
        bean.setCreatedOn(asDate(source.get("createdOn")));
        bean.setData(asString(source.get("data")));
        bean.setEntityId(asString(source.get("entityId")));
        bean.setEntityType(asEnum(source.get("entityType"), AuditEntityType.class));
        bean.setEntityVersion(asString(source.get("entityVersion")));
        bean.setWhat(asEnum(source.get("what"), AuditEntryType.class));
        bean.setWho(asString(source.get("who")));
        postMarshall(bean);
        return bean;
    }
863134
public static AuditEntryBean organizationUpdated(OrganizationBean bean, EntityUpdatedData data,
            ISecurityContext securityContext) {
        if (data.getChanges().isEmpty()) {
            return null;
        }
        AuditEntryBean entry = newEntry(bean.getId(), AuditEntityType.Organization, securityContext);
        entry.setEntityId(null);
        entry.setEntityVersion(null);
        entry.setWhat(AuditEntryType.Update);
        entry.setData(toJSON(data));
        return entry;
    }
959374
public <T> Object getBeanKey(Contextual<T> bean)
    {
        if (passivationCapable)
        {
            // if the
            return ((PassivationCapable) bean).getId();
        }

        return bean;
    }