Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 9, 2014
2 parents 02a282d + c7422ea commit 5b9af1b
Show file tree
Hide file tree
Showing 36 changed files with 3,821 additions and 108 deletions.
54 changes: 54 additions & 0 deletions custom/pom.xml
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2014 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>midPoint Customizations</name>
<artifactId>custom</artifactId>
<packaging>pom</packaging>
<parent>
<artifactId>parent</artifactId>
<groupId>com.evolveum.midpoint</groupId>
<version>3.1-SNAPSHOT</version>
<relativePath>../build-system/pom.xml</relativePath>
</parent>
<organization>
<name>Evolveum</name>
<url>http://www.evolveum.com</url>
</organization>
<licenses>
<license>
<name>Apache License v2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<issueManagement>
<system>Atlassian JIRA</system>
<url>http://jira.evolveum.com/</url>
</issueManagement>
<scm>
<connection>https://github.com/Evolveum/midpoint.git</connection>
<developerConnection>git@github.com:Evolveum/midpoint.git</developerConnection>
<url>https://fisheye.evolveum.com/browse/midPoint</url>
</scm>
<modules>
<!-- add submodule here:
<module>custom-foo</module>
-->
</modules>
</project>
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.schema.util;

import java.util.UUID;

/**
* @author semancik
*
*/
public class OidUtil {

public static String generateOid() {
return UUID.randomUUID().toString();
}

}
Expand Up @@ -46,7 +46,7 @@
<a href="https://wiki.evolveum.com/display/midPoint/Data+Model">https://wiki.evolveum.com/display/midPoint/Data+Model</a>
for more details.

<p>Version: 3.0-SNAPSHOT</p>
<p>Version: 3.1-SNAPSHOT</p>

<p>Recommended namespace prefix: (default), c</p>
</xsd:documentation>
Expand Down Expand Up @@ -4648,6 +4648,7 @@
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="mode" type="tns:GenerateExpressionEvaluatorModeType" minOccurs="0" default="policy"/>
<xsd:element name="valuePolicyRef" type="tns:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand All @@ -4662,6 +4663,43 @@
</xsd:complexType>

<xsd:element name="generate" type="tns:GenerateExpressionEvaluatorType" substitutionGroup="tns:expressionEvaluator"/>

<xsd:simpleType name="GenerateExpressionEvaluatorModeType">
<xsd:annotation>
<xsd:documentation>
Value generator mode.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="policy">
<xsd:annotation>
<xsd:documentation>
Generator generates the value according to the applicable value policy (e.g. a password policy).
The it generates a random string that satisfies the policy. If no policy can be determined then
a reasonable default policy is assumed.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="POLICY"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="uuid">
<xsd:annotation>
<xsd:documentation>
The generator generates a random Universally Unique Identifier (UUID) string.
The generated UUID is currently version 4 and complies with ISO/IEC 11578:1996, but this
can change in the future.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="UUID"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="script" type="tns:ScriptExpressionEvaluatorType" substitutionGroup="tns:expressionEvaluator"/>

Expand Down Expand Up @@ -7193,6 +7231,13 @@
<a:objectReferenceTargetType>tns:ObjectTemplateType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="oidNameBoundMode" type="xsd:boolean" minOccurs="0" default="false">
<xsd:annotation>
<xsd:documentation>
A mode in which OID and name of the speciefied object are the same.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Expand Down
Expand Up @@ -17,6 +17,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
Expand Down Expand Up @@ -53,6 +54,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorModeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType;
Expand Down Expand Up @@ -116,25 +118,36 @@ public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext params)
// stringPolicyType = elementStringPolicy;
// }
//
// TODO: generate value based on stringPolicyType (if not null)
String stringValue = null;
if (stringPolicyType != null) {
if (isNotEmptyMinLength(stringPolicyType)) {
stringValue = ValuePolicyGenerator.generate(stringPolicyType, DEFAULT_LENGTH, true, params.getResult());
} else{
stringValue = ValuePolicyGenerator.generate(stringPolicyType, DEFAULT_LENGTH, false, params.getResult());
GenerateExpressionEvaluatorModeType mode = generateEvaluatorType.getMode();
if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {

// TODO: generate value based on stringPolicyType (if not null)
if (stringPolicyType != null) {
if (isNotEmptyMinLength(stringPolicyType)) {
stringValue = ValuePolicyGenerator.generate(stringPolicyType, DEFAULT_LENGTH, true, params.getResult());
} else{
stringValue = ValuePolicyGenerator.generate(stringPolicyType, DEFAULT_LENGTH, false, params.getResult());
}
params.getResult().computeStatus();
if (params.getResult().isError()){
throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() +". "+ params.getResult().getMessage());
}
}
params.getResult().computeStatus();
if (params.getResult().isError()){
throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() +". "+ params.getResult().getMessage());
}
}

if (stringValue == null){
int length = DEFAULT_LENGTH;
RandomString randomString = new RandomString(length);
stringValue= randomString.nextString();
}

if (stringValue == null){
int length = DEFAULT_LENGTH;
RandomString randomString = new RandomString(length);
stringValue = randomString.nextString();
}

} else if (mode == GenerateExpressionEvaluatorModeType.UUID) {
UUID randomUUID = UUID.randomUUID();
stringValue = randomUUID.toString();

} else {
throw new ExpressionEvaluationException("Unknown mode for generate expression: "+mode);
}

Object value;
QName outputType = outputDefinition.getTypeName();
Expand Down
@@ -0,0 +1,119 @@
/**
* Copyright (c) 2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.model.common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
* Abstract superclass that provides methods common to all web service implementations that
* use ModelService.
*
* @author Radovan Semancik
*
*/
public abstract class AbstractModelWebService {

@Autowired(required = true)
protected ModelService modelService;

@Autowired(required = true)
protected TaskManager taskManager;

@Autowired(required = true)
protected AuditService auditService;

@Autowired(required = true)
protected PrismContext prismContext;

protected void setTaskOwner(Task task) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
throw new SystemException("Failed to get authentication object");
}
UserType userType = (UserType) ((MidPointPrincipal)(SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getUser();
if (userType == null) {
throw new SystemException("Failed to get user from authentication object");
}
task.setOwner(userType.asPrismObject());
}

protected Task createTaskInstance(String operationName) {
// TODO: better task initialization
Task task = taskManager.createTaskInstance(operationName);
setTaskOwner(task);
task.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
return task;
}

protected void auditLogin(Task task) {
AuditEventRecord record = new AuditEventRecord(AuditEventType.CREATE_SESSION, AuditEventStage.REQUEST);
PrismObject<UserType> owner = task.getOwner();
if (owner != null) {
record.setInitiator(owner);
PolyStringType name = owner.asObjectable().getName();
if (name != null) {
record.setParameter(name.getOrig());
}
}

record.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
record.setTimestamp(System.currentTimeMillis());
record.setSessionIdentifier(task.getTaskIdentifier());

record.setOutcome(OperationResultStatus.SUCCESS);

auditService.audit(record, task);
}

protected void auditLogout(Task task) {
AuditEventRecord record = new AuditEventRecord(AuditEventType.TERMINATE_SESSION, AuditEventStage.REQUEST);
PrismObject<UserType> owner = task.getOwner();
if (owner != null) {
record.setInitiator(owner);
PolyStringType name = owner.asObjectable().getName();
if (name != null) {
record.setParameter(name.getOrig());
}
}

record.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
record.setTimestamp(System.currentTimeMillis());
record.setSessionIdentifier(task.getTaskIdentifier());

record.setOutcome(OperationResultStatus.SUCCESS);

auditService.audit(record, task);
}

}

0 comments on commit 5b9af1b

Please sign in to comment.