Skip to content

Commit

Permalink
new repo class - RSecurityPolicy, objects.xml - object securityPolicy…
Browse files Browse the repository at this point in the history
…, valuePolicy
  • Loading branch information
garbika committed Mar 21, 2014
1 parent af17e9d commit 7c16e7c
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 1 deletion.
60 changes: 60 additions & 0 deletions repo/repo-sql-impl-test/src/test/resources/basic/objects.xml
Expand Up @@ -1340,4 +1340,64 @@
<r:type>c:UserType</r:type>
</configuration>
</report>

<valuePolicy oid="SECURITY-0000-0000-0000-000000000003"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-2a"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-2"
version="0">
<name>Default Password Policy</name>
<description>Default password policy</description>
<lifetime>
<expiration>999</expiration>
<warnBeforeExpiration>9</warnBeforeExpiration>
<lockAfterExpiration>0</lockAfterExpiration>
<minPasswordAge>0</minPasswordAge>
<passwordHistoryLength>0</passwordHistoryLength>
</lifetime>
<stringPolicy>
<description>Testing string policy</description>
<limitations>
<minLength>5</minLength>
<maxLength>8</maxLength>
<minUniqueChars>3</minUniqueChars>
<checkAgainstDictionary>true</checkAgainstDictionary>
<checkPattern />
<limit>
<description>Alphas</description>
<minOccurs>1</minOccurs>
<maxOccurs>5</maxOccurs>
<mustBeFirst>false</mustBeFirst>
<characterClass>
<value>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</value>
</characterClass>
</limit>
<limit>
<description>Numbers</description>
<minOccurs>1</minOccurs>
<maxOccurs>5</maxOccurs>
<mustBeFirst>false</mustBeFirst>
<characterClass>
<value>1234567890</value>
</characterClass>
</limit>
</limitations>
</stringPolicy>
</valuePolicy>
<securityPolicy xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-2a">
<name>Security policy</name>
<description>Security policy example</description>
<authentication>
</authentication>
<credentials>
<password>
<passwordPolicyRef oid="SECURITY-0000-0000-0000-000000000003" type="c:ValuePolicyType"/>
</password>
<securityQuestions>
<question>
<identifier>http://example.com/uri3</identifier>
<enabled>false</enabled>
</question>
</securityQuestions>
</credentials>
</securityPolicy>
</objects>
Expand Up @@ -45,6 +45,7 @@ public class RReport extends RObject<ReportType> {
private String configuration;
private String configurationSchema;

@Embedded
public RPolyString getName() {
return name;
}
Expand Down
@@ -0,0 +1,144 @@
package com.evolveum.midpoint.repo.sql.data.common;

import java.util.Collection;
import java.util.List;

import javax.persistence.*;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.repo.sql.data.common.embedded.RDataSource;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.*;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RExportType;
import com.evolveum.midpoint.repo.sql.data.common.enums.ROrientationType;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.prism.xml.ns._public.query_2.QueryType;

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"name_norm"}))
@org.hibernate.annotations.Table(appliesTo = "m_security_policy",
indexes = {@Index(name = "iSecurityPolicyName", columnNames = "name_orig")})
@ForeignKey(name = "fk_security_policy")
public class RSecurityPolicy extends RObject<SecurityPolicyType> {

private RPolyString name;
private String authentication;
private String credentials;

@Embedded
public RPolyString getName() {
return name;
}

public void setName(RPolyString name) {
this.name = name;
}

@Lob
@Type(type = RUtil.LOB_STRING_TYPE)
public String getAuthentication() {
return authentication;
}

public void setAuthentication(String authentication) {
this.authentication = authentication;
}

@Lob
@Type(type = RUtil.LOB_STRING_TYPE)
public String getCredentials() {
return credentials;
}

public void setCredentials(String credentials) {
this.credentials = credentials;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

RSecurityPolicy that = (RSecurityPolicy) o;

if (name != null ? !name.equals(that.name) : that.name != null)
return false;
if (authentication != null ? !authentication.equals(that.authentication) : that.authentication != null)
return false;
if (credentials != null ? !credentials.equals(that.credentials) : that.credentials != null)
return false;
return true;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (authentication != null ? authentication.hashCode() : 0);
result = 31 * result + (credentials != null ? credentials.hashCode() : 0);
return result;
}

public static void copyFromJAXB(SecurityPolicyType jaxb, RSecurityPolicy repo, PrismContext prismContext)
throws DtoTranslationException {

RObject.copyFromJAXB(jaxb, repo, prismContext);

repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));

try {
repo.setAuthentication(RUtil.toRepo(jaxb.getAuthentication(), prismContext));
repo.setCredentials(RUtil.toRepo(jaxb.getCredentials(), prismContext));
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
}

public static void copyToJAXB(RSecurityPolicy repo, SecurityPolicyType jaxb, PrismContext prismContext,
Collection<SelectorOptions<GetOperationOptions>> options)
throws DtoTranslationException {

RObject.copyToJAXB(repo, jaxb, prismContext, options);

jaxb.setName(RPolyString.copyToJAXB(repo.getName()));

try {
if (StringUtils.isNotEmpty(repo.getAuthentication())) {
jaxb.setAuthentication(RUtil.toJAXB(SecurityPolicyType.class, new ItemPath(SecurityPolicyType.F_AUTHENTICATION),
repo.getAuthentication(), AuthenticationPolicyType.class, prismContext));
}
if (StringUtils.isNotEmpty(repo.getCredentials())) {
jaxb.setCredentials(RUtil.toJAXB(SecurityPolicyType.class, new ItemPath(SecurityPolicyType.F_CREDENTIALS),
repo.getCredentials(), CredentialsPolicyType.class, prismContext));
}

} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
}

@Override
public SecurityPolicyType toJAXB(PrismContext prismContext,
Collection<SelectorOptions<GetOperationOptions>> options)
throws DtoTranslationException {

SecurityPolicyType object = new SecurityPolicyType();
RUtil.revive(object, prismContext);
RSecurityPolicy.copyToJAXB(this, object, prismContext, options);

return object;
}
}

Expand Up @@ -45,7 +45,8 @@ public enum RContainerType {
ABSTRACT_ROLE(RAbstractRole.class),
AUTHORIZATION(RAuthorization.class),
FOCUS(RFocus.class),
TRIGGER(RTrigger.class);
TRIGGER(RTrigger.class),
SECURITY_POLICY(RSecurityPolicy.class);

private Class<? extends RContainer> clazz;

Expand Down
Expand Up @@ -58,6 +58,7 @@ private ClassMapper() {
types.put(ObjectTypes.ORG, RContainerType.ORG);
types.put(ObjectTypes.ABSTRACT_ROLE, RContainerType.ABSTRACT_ROLE);
types.put(ObjectTypes.FOCUS_TYPE, RContainerType.FOCUS);
types.put(ObjectTypes.SECURITY_POLICY, RContainerType.SECURITY_POLICY);

for (ObjectTypes type : ObjectTypes.values()) {
if (!types.containsKey(type)) {
Expand Down

0 comments on commit 7c16e7c

Please sign in to comment.