From f3aff6e2192571c66f10c6615758626e776f34ee Mon Sep 17 00:00:00 2001 From: strehle Date: Fri, 6 Dec 2024 21:24:31 +0100 Subject: [PATCH] Remove IdP classes left-overs from https://github.com/cloudfoundry/uaa/pull/2638 --- .../saml/idp/SamlServiceProvider.java | 294 ------------------ .../idp/SamlServiceProviderDefinition.java | 281 ----------------- .../SamlServiceProviderDefinitionTest.java | 169 ---------- .../event/ServiceProviderModifiedEvent.java | 57 ---- .../ServiceProviderModifiedEventTest.java | 63 ---- 5 files changed, 864 deletions(-) delete mode 100644 model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProvider.java delete mode 100644 model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinition.java delete mode 100644 model/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinitionTest.java delete mode 100644 server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java delete mode 100644 server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java diff --git a/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProvider.java b/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProvider.java deleted file mode 100644 index 488c5f6db8e..00000000000 --- a/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProvider.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * ***************************************************************************** - * Cloud Foundry - * Copyright (c) [2009-2014] Pivotal Software, Inc. All Rights Reserved. - * - * This product is licensed to you under the Apache License, Version 2.0 (the "License"). - * You may not use this product except in compliance with the License. - * - * This product includes a number of subcomponents with - * separate copyright notices and license terms. Your use of these - * subcomponents is subject to the terms and conditions of the - * subcomponent's license, as noted in the LICENSE file. - *******************************************************************************/ -package org.cloudfoundry.identity.uaa.provider.saml.idp; - -import java.io.IOException; -import java.util.Date; - -import javax.validation.constraints.NotNull; - -import org.cloudfoundry.identity.uaa.util.JsonUtils; -import org.springframework.util.StringUtils; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonSerialize(using = SamlServiceProvider.SamlServiceProviderSerializer.class) -@JsonDeserialize(using = SamlServiceProvider.SamlServiceProviderDeserializer.class) -public class SamlServiceProvider { - - public static final String FIELD_ID = "id"; - public static final String FIELD_ENTITY_ID = "entityId"; - public static final String FIELD_NAME = "name"; - public static final String FIELD_VERSION = "version"; - public static final String FIELD_CREATED = "created"; - public static final String FIELD_LAST_MODIFIED = "lastModified"; - public static final String FIELD_ACTIVE = "active"; - public static final String FIELD_IDENTITY_ZONE_ID = "identityZoneId"; - public static final String FIELD_CONFIG = "config"; - - // see deserializer at the bottom - private String id; - @NotNull - private String entityId; - @NotNull - private String name; - private SamlServiceProviderDefinition config; - private int version = 0; - private Date created = new Date(); - private Date lastModified = new Date(); - private boolean active = true; - private String identityZoneId; - - public Date getCreated() { - return created; - } - - public SamlServiceProvider setCreated(Date created) { - this.created = created; - return this; - } - - public Date getLastModified() { - return lastModified; - } - - public SamlServiceProvider setLastModified(Date lastModified) { - this.lastModified = lastModified; - return this; - } - - public SamlServiceProvider setVersion(int version) { - this.version = version; - return this; - } - - public int getVersion() { - return version; - } - - public String getName() { - return name; - } - - public SamlServiceProvider setName(String name) { - this.name = name; - return this; - } - - public String getId() { - return id; - } - - public SamlServiceProvider setId(String id) { - this.id = id; - return this; - } - - public SamlServiceProviderDefinition getConfig() { - return config; - } - - public SamlServiceProvider setConfig(SamlServiceProviderDefinition config) { - - this.config = config; - return this; - } - - public String getEntityId() { - return entityId; - } - - public SamlServiceProvider setEntityId(String entityId) { - this.entityId = entityId; - return this; - } - - public boolean isActive() { - return active; - } - - public SamlServiceProvider setActive(boolean active) { - this.active = active; - return this; - } - - public String getIdentityZoneId() { - return identityZoneId; - } - - public SamlServiceProvider setIdentityZoneId(String identityZoneId) { - this.identityZoneId = identityZoneId; - return this; - } - - public boolean configIsValid() { - // There may be need for this method in the fugure but for now it does nothing. - return true; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((config == null) ? 0 : config.hashCode()); - result = prime * result + ((created == null) ? 0 : created.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((entityId == null) ? 0 : entityId.hashCode()); - result = prime * result + version; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SamlServiceProvider other = (SamlServiceProvider) obj; - if (config == null) { - if (other.config != null) - return false; - } else if (!config.equals(other.config)) - return false; - if (created == null) { - if (other.created != null) - return false; - } else if (!created.equals(other.created)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (lastModified == null) { - if (other.lastModified != null) - return false; - } else if (!lastModified.equals(other.lastModified)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (entityId == null) { - if (other.entityId != null) - return false; - } else if (!entityId.equals(other.entityId)) - return false; - if (version != other.version) - return false; - return true; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("SamlServiceProvider{"); - sb.append("id='").append(id).append('\''); - sb.append(", entityId='").append(entityId).append('\''); - sb.append(", name='").append(name).append('\''); - sb.append(", active=").append(active); - sb.append('}'); - return sb.toString(); - } - - public static class SamlServiceProviderSerializer extends JsonSerializer { - @Override - public void serialize(SamlServiceProvider value, JsonGenerator gen, SerializerProvider serializers) - throws IOException { - gen.writeStartObject(); - gen.writeStringField(FIELD_CONFIG, JsonUtils.writeValueAsString(value.getConfig())); - gen.writeStringField(FIELD_ID, value.getId()); - gen.writeStringField(FIELD_ENTITY_ID, value.getEntityId()); - gen.writeStringField(FIELD_NAME, value.getName()); - gen.writeNumberField(FIELD_VERSION, value.getVersion()); - writeDateField(FIELD_CREATED, value.getCreated(), gen); - writeDateField(FIELD_LAST_MODIFIED, value.getLastModified(), gen); - gen.writeBooleanField(FIELD_ACTIVE, value.isActive()); - gen.writeStringField(FIELD_IDENTITY_ZONE_ID, value.getIdentityZoneId()); - gen.writeEndObject(); - } - - public void writeDateField(String fieldName, Date value, JsonGenerator gen) throws IOException { - if (value != null) { - gen.writeNumberField(fieldName, value.getTime()); - } else { - gen.writeNullField(fieldName); - } - } - } - - public static class SamlServiceProviderDeserializer extends JsonDeserializer { - @Override - public SamlServiceProvider deserialize(JsonParser jp, DeserializationContext ctxt) { - SamlServiceProvider result = new SamlServiceProvider(); - // determine the type of IdentityProvider - JsonNode node = JsonUtils.readTree(jp); - // deserialize based on type - String config = getNodeAsString(node, FIELD_CONFIG, null); - SamlServiceProviderDefinition definition = null; - if (StringUtils.hasText(config)) { - definition = JsonUtils.readValue(config, SamlServiceProviderDefinition.class); - } - result.setConfig(definition); - - result.setId(getNodeAsString(node, FIELD_ID, null)); - result.setEntityId(getNodeAsString(node, FIELD_ENTITY_ID, null)); - result.setName(getNodeAsString(node, FIELD_NAME, null)); - result.setVersion(getNodeAsInt(node, FIELD_VERSION, 0)); - result.setCreated(getNodeAsDate(node, FIELD_CREATED)); - result.setLastModified(getNodeAsDate(node, FIELD_LAST_MODIFIED)); - result.setActive(getNodeAsBoolean(node, FIELD_ACTIVE, true)); - result.setIdentityZoneId(getNodeAsString(node, FIELD_IDENTITY_ZONE_ID, null)); - return result; - } - - protected String getNodeAsString(JsonNode node, String fieldName, String defaultValue) { - JsonNode typeNode = node.get(fieldName); - return typeNode == null ? defaultValue : typeNode.asText(defaultValue); - } - - protected int getNodeAsInt(JsonNode node, String fieldName, int defaultValue) { - JsonNode typeNode = node.get(fieldName); - return typeNode == null ? defaultValue : typeNode.asInt(defaultValue); - } - - protected boolean getNodeAsBoolean(JsonNode node, String fieldName, boolean defaultValue) { - JsonNode typeNode = node.get(fieldName); - return typeNode == null ? defaultValue : typeNode.asBoolean(defaultValue); - } - - protected Date getNodeAsDate(JsonNode node, String fieldName) { - JsonNode typeNode = node.get(fieldName); - long date = typeNode == null ? -1 : typeNode.asLong(-1); - if (date == -1) { - return null; - } else { - return new Date(date); - } - } - } - -} diff --git a/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinition.java b/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinition.java deleted file mode 100644 index 9de45605cf9..00000000000 --- a/model/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinition.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * ***************************************************************************** - * Cloud Foundry - * Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved. - * - * This product is licensed to you under the Apache License, Version 2.0 (the "License"). - * You may not use this product except in compliance with the License. - * - * This product includes a number of subcomponents with - * separate copyright notices and license terms. Your use of these - * subcomponents is subject to the terms and conditions of the - * subcomponent's license, as noted in the LICENSE file. - *******************************************************************************/ -package org.cloudfoundry.identity.uaa.provider.saml.idp; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import org.cloudfoundry.identity.uaa.util.ObjectUtils; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.StringReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class SamlServiceProviderDefinition { - - public enum MetadataLocation { - URL, - DATA, - UNKNOWN - } - - private String metaDataLocation; - private String nameID; - private int singleSignOnServiceIndex; - private boolean metadataTrustCheck; - private boolean skipSslValidation = false; - private Map attributeMappings = new HashMap<>(); - private boolean enableIdpInitiatedSso = false; - private Map staticCustomAttributes = new HashMap<>(); - - - public SamlServiceProviderDefinition clone() { - return new SamlServiceProviderDefinition(metaDataLocation, - nameID, - singleSignOnServiceIndex, - metadataTrustCheck, - skipSslValidation, - attributeMappings, - enableIdpInitiatedSso); - } - - public SamlServiceProviderDefinition() {} - - private SamlServiceProviderDefinition(String metaDataLocation, - String nameID, - int singleSignOnServiceIndex, - boolean metadataTrustCheck, - boolean skipSslValidation, - Map attributeMappings, - boolean enableIdpInitiatedSso) { - this.metaDataLocation = metaDataLocation; - this.nameID = nameID; - this.singleSignOnServiceIndex = singleSignOnServiceIndex; - this.metadataTrustCheck = metadataTrustCheck; - this.skipSslValidation = skipSslValidation; - this.attributeMappings = attributeMappings; - this.enableIdpInitiatedSso = enableIdpInitiatedSso; - } - - @JsonIgnore - public MetadataLocation getType() { - String trimmedLocation = metaDataLocation.trim(); - if (trimmedLocation.startsWith(" attributeMappings) { - this.attributeMappings = attributeMappings; - } - - public Map getAttributeMappings() { - return attributeMappings; - } - - public boolean isEnableIdpInitiatedSso() { - return enableIdpInitiatedSso; - } - - public void setEnableIdpInitiatedSso(boolean enableIdpInitiatedSso) { - this.enableIdpInitiatedSso = enableIdpInitiatedSso; - } - - public Map getStaticCustomAttributes() { - return staticCustomAttributes; - } - - public void setStaticCustomAttributes(Map staticCustomAttributes) { - this.staticCustomAttributes = staticCustomAttributes; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SamlServiceProviderDefinition that = (SamlServiceProviderDefinition) o; - - if (singleSignOnServiceIndex != that.singleSignOnServiceIndex) return false; - if (metadataTrustCheck != that.metadataTrustCheck) return false; - if (skipSslValidation != that.skipSslValidation) return false; - if (!Objects.equals(metaDataLocation, that.metaDataLocation)) - return false; - if (!Objects.equals(nameID, that.nameID)) return false; - return Objects.equals(attributeMappings, that.attributeMappings); - } - - @Override - public String toString() { - return "SamlServiceProviderDefinition{" + - "metaDataLocation='" + metaDataLocation + '\'' + - ", nameID='" + nameID + '\'' + - ", singleSignOnServiceIndex=" + singleSignOnServiceIndex + - ", metadataTrustCheck=" + metadataTrustCheck + - ", skipSslValidation=" + skipSslValidation + - ", attributeMappings=" + attributeMappings + - '}'; - } - - public static class Builder { - - private String metaDataLocation; - private String nameID; - private int singleSignOnServiceIndex; - private boolean metadataTrustCheck; - private boolean enableIdpInitiatedSso = false; - private boolean skipSslValidation = true; - - private Builder(){} - - public static Builder get() { - return new Builder(); - } - - public SamlServiceProviderDefinition build() { - SamlServiceProviderDefinition def = new SamlServiceProviderDefinition(); - def.setMetaDataLocation(metaDataLocation); - def.setNameID(nameID); - def.setSingleSignOnServiceIndex(singleSignOnServiceIndex); - def.setMetadataTrustCheck(metadataTrustCheck); - def.setEnableIdpInitiatedSso(enableIdpInitiatedSso); - def.setSkipSslValidation(skipSslValidation); - return def; - } - - public Builder setMetaDataLocation(String metaDataLocation) { - this.metaDataLocation = metaDataLocation; - return this; - } - - public Builder setNameID(String nameID) { - this.nameID = nameID; - return this; - } - - public Builder setSkipSSLValidation(boolean skipSslValidation) { - this.skipSslValidation = skipSslValidation; - return this; - } - - public Builder setSingleSignOnServiceIndex(int singleSignOnServiceIndex) { - this.singleSignOnServiceIndex = singleSignOnServiceIndex; - return this; - } - - public Builder setMetadataTrustCheck(boolean metadataTrustCheck) { - this.metadataTrustCheck = metadataTrustCheck; - return this; - } - - public Builder setEnableIdpInitiatedSso(boolean enableIdpInitiatedSso) { - this.enableIdpInitiatedSso = enableIdpInitiatedSso; - return this; - } - } -} diff --git a/model/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinitionTest.java b/model/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinitionTest.java deleted file mode 100644 index 9395d908000..00000000000 --- a/model/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/idp/SamlServiceProviderDefinitionTest.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.cloudfoundry.identity.uaa.provider.saml.idp; - -import org.junit.jupiter.api.Test; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -class SamlServiceProviderDefinitionTest { - - private static final String METADATA_URL_LOCATION = "https://www.cloudfoundry.org/"; - private static final String VALUE = "value"; - - @Test - void getType_validXml() { - var def = new SamlServiceProviderDefinition(); - - def.setMetaDataLocation(""" - - - """); - assertThat(def.getType()).isEqualTo(SamlServiceProviderDefinition.MetadataLocation.DATA); - } - - @Test - void getType_invalidXml() { - var def = new SamlServiceProviderDefinition(); - - def.setMetaDataLocation(""); - assertThat(def.getType()).isEqualTo(SamlServiceProviderDefinition.MetadataLocation.UNKNOWN); - } - - @Test - void getType_doctype() { - var def = new SamlServiceProviderDefinition(); - def.setMetaDataLocation(""" - - - """); - assertThat(def.getType()).isEqualTo(SamlServiceProviderDefinition.MetadataLocation.UNKNOWN); - } - - @Test - void getType_Url() { - var def = new SamlServiceProviderDefinition(); - def.setMetaDataLocation(METADATA_URL_LOCATION); - assertThat(def.getType()).isEqualTo(SamlServiceProviderDefinition.MetadataLocation.URL); - } - - @Test - void metaDataLocation() { - var def = new SamlServiceProviderDefinition(); - def.setMetaDataLocation(METADATA_URL_LOCATION); - - assertThat(def.getMetaDataLocation()).isEqualTo(METADATA_URL_LOCATION); - } - - @Test - void nameID() { - var def = new SamlServiceProviderDefinition(); - def.setNameID(VALUE); - assertThat(def.getNameID()).isEqualTo(VALUE); - } - - @Test - void singleSignOnServiceIndex() { - var def = new SamlServiceProviderDefinition(); - def.setSingleSignOnServiceIndex(2); - assertThat(def.getSingleSignOnServiceIndex()).isEqualTo(2); - } - - @Test - void metadataTrustCheck() { - var def = new SamlServiceProviderDefinition(); - assertThat(def.isMetadataTrustCheck()).isFalse(); - def.setMetadataTrustCheck(true); - assertThat(def.isMetadataTrustCheck()).isTrue(); - } - - @Test - void skipSslValidation() { - var def = new SamlServiceProviderDefinition(); - assertThat(def.isSkipSslValidation()).isFalse(); - def.setSkipSslValidation(true); - assertThat(def.isSkipSslValidation()).isTrue(); - } - - @Test - void enableIdpInitiatedSso() { - var def = new SamlServiceProviderDefinition(); - assertThat(def.isEnableIdpInitiatedSso()).isFalse(); - def.setEnableIdpInitiatedSso(true); - assertThat(def.isEnableIdpInitiatedSso()).isTrue(); - } - - @Test - void attributeMappings() { - var def = new SamlServiceProviderDefinition(); - assertThat(def.getAttributeMappings()).isEmpty(); - def.setAttributeMappings(Map.of("k1", "v1")); - assertThat(def.getAttributeMappings()).hasSize(1).containsEntry("k1", "v1"); - } - - @Test - void staticCustomAttributes() { - var def = new SamlServiceProviderDefinition(); - assertThat(def.getStaticCustomAttributes()).isEmpty(); - def.setStaticCustomAttributes(Map.of("k1", "v1")); - assertThat(def.getStaticCustomAttributes()).hasSize(1).containsEntry("k1", "v1"); - } - - @Test - void testHashCode() { - var def1 = new SamlServiceProviderDefinition(); - var def2 = new SamlServiceProviderDefinition(); - assertThat(def1).hasSameHashCodeAs(def2); - } - - @Test - void equals() { - var def1 = new SamlServiceProviderDefinition(); - var def2 = new SamlServiceProviderDefinition(); - assertThat(def1).isEqualTo(def2); - - def1.setNameID(VALUE); - assertThat(def1).isNotEqualTo(def2); - } - - @Test - void testToString() { - var def1 = new SamlServiceProviderDefinition(); - def1.setNameID(VALUE); - assertThat(def1).hasToString("SamlServiceProviderDefinition{metaDataLocation='null', nameID='value', singleSignOnServiceIndex=0, metadataTrustCheck=false, skipSslValidation=false, attributeMappings={}}"); - } - - @Test - void builder() { - var def1 = SamlServiceProviderDefinition.Builder.get() - .setMetaDataLocation(METADATA_URL_LOCATION) - .setNameID(VALUE) - .setSingleSignOnServiceIndex(3) - .setMetadataTrustCheck(true) - .setEnableIdpInitiatedSso(true) - .build(); - - assertThat(def1) - .returns( METADATA_URL_LOCATION, SamlServiceProviderDefinition::getMetaDataLocation) - .returns( VALUE, SamlServiceProviderDefinition::getNameID) - .returns( 3, SamlServiceProviderDefinition::getSingleSignOnServiceIndex) - .returns( true, SamlServiceProviderDefinition::isMetadataTrustCheck) - .returns( true, SamlServiceProviderDefinition::isSkipSslValidation) - .returns( true, SamlServiceProviderDefinition::isEnableIdpInitiatedSso); - - } - - @Test - void testClone() { - var def1 = SamlServiceProviderDefinition.Builder.get() - .setMetaDataLocation(METADATA_URL_LOCATION) - .setNameID(VALUE) - .setSingleSignOnServiceIndex(3) - .setMetadataTrustCheck(true) - .setEnableIdpInitiatedSso(true) - .build(); - - assertThat(def1.clone()).isEqualTo(def1); - } -} diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java deleted file mode 100644 index fcab2be726c..00000000000 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ***************************************************************************** - * Cloud Foundry - * Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved. - * - * This product is licensed to you under the Apache License, Version 2.0 (the "License"). - * You may not use this product except in compliance with the License. - * - * This product includes a number of subcomponents with - * separate copyright notices and license terms. Your use of these - * subcomponents is subject to the terms and conditions of the - * subcomponent's license, as noted in the LICENSE file. - *******************************************************************************/ -package org.cloudfoundry.identity.uaa.zone.event; - - -import org.cloudfoundry.identity.uaa.audit.AuditEvent; -import org.cloudfoundry.identity.uaa.audit.AuditEventType; -import org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent; -import org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProvider; -import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder; -import org.springframework.security.core.Authentication; - -public class ServiceProviderModifiedEvent extends AbstractUaaEvent { - - private static final long serialVersionUID = -204120790766086570L; - - private AuditEventType eventType; - - protected static final String dataFormat = "id=%s; name=%s; entityID=%s"; - - public ServiceProviderModifiedEvent(SamlServiceProvider serviceProvider, Authentication authentication, AuditEventType type, String zoneId) { - super(serviceProvider, authentication, zoneId); - eventType = type; - } - - @Override - public AuditEvent getAuditEvent() { - SamlServiceProvider provider = (SamlServiceProvider)source; - return createAuditRecord(getSource().toString(), - eventType, - getOrigin(getAuthentication()), - String.format(dataFormat, - provider.getId(), - provider.getName(), - provider.getEntityId())); - } - - public static ServiceProviderModifiedEvent serviceProviderCreated(SamlServiceProvider serviceProvider) { - return new ServiceProviderModifiedEvent(serviceProvider, getContextAuthentication(), AuditEventType.ServiceProviderCreatedEvent, IdentityZoneHolder.getCurrentZoneId()); - } - - public static ServiceProviderModifiedEvent serviceProviderModified(SamlServiceProvider serviceProvider) { - return new ServiceProviderModifiedEvent(serviceProvider, getContextAuthentication(), AuditEventType.ServiceProviderModifiedEvent, IdentityZoneHolder.getCurrentZoneId()); - } - -} diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java deleted file mode 100644 index bb76e44f9ee..00000000000 --- a/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * **************************************************************************** - * Cloud Foundry - * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. - * - * This product is licensed to you under the Apache License, Version 2.0 (the "License"). - * You may not use this product except in compliance with the License. - * - * This product includes a number of subcomponents with - * separate copyright notices and license terms. Your use of these - * subcomponents is subject to the terms and conditions of the - * subcomponent's license, as noted in the LICENSE file. - * **************************************************************************** - */ - -package org.cloudfoundry.identity.uaa.zone.event; - -import org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProvider; -import org.cloudfoundry.identity.uaa.util.AlphanumericRandomValueStringGenerator; -import org.cloudfoundry.identity.uaa.util.JsonUtils; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - - -public class ServiceProviderModifiedEventTest { - - private SamlServiceProvider provider; - - @Before - public void setup() { - String name = new AlphanumericRandomValueStringGenerator().generate(); - String requestBody = "{\n" + - " \"name\" : \"" + name + "\",\n" + - " \"entityId\" : \""+ name +".cloudfoundry-saml-login\",\n" + - " \"active\" : true,\n" + - " \"config\" : \"{\\\"metaDataLocation\\\" : \\\"zALgjEFJ7jJSwn2AOBH5H8CX93U=Rp5XH8eT0ek/vlFGzHgIFOeESchOwSYZ9oh4JA9WqQ0jJtvNQ9IttY2QY9XK3n6TbbtPcEKVgljyTfwD5ymp+oMKfIYQC9JsN8mPADN5rjLFgC+xGceWLbcjoNsCJ7x2ZjyWRblSxoOU5qnzxEA3k3Bu+OkV+ZXcSbmgMWoQACg=MIIDSTCCArKgAwIBAgIBADANBgkqhkiG9w0BAQQFADB8MQswCQYDVQQGEwJhdzEOMAwGA1UECBMF\\\\nYXJ1YmExDjAMBgNVBAoTBWFydWJhMQ4wDAYDVQQHEwVhcnViYTEOMAwGA1UECxMFYXJ1YmExDjAM\\\\nBgNVBAMTBWFydWJhMR0wGwYJKoZIhvcNAQkBFg5hcnViYUBhcnViYS5hcjAeFw0xNTExMjAyMjI2\\\\nMjdaFw0xNjExMTkyMjI2MjdaMHwxCzAJBgNVBAYTAmF3MQ4wDAYDVQQIEwVhcnViYTEOMAwGA1UE\\\\nChMFYXJ1YmExDjAMBgNVBAcTBWFydWJhMQ4wDAYDVQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmEx\\\\nHTAbBgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\\\\ngQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5L39WqS9u0hnA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format:unspecifiedurn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName\\\",\\\"metadataTrustCheck\\\" : true }\"" + - "}"; - provider = JsonUtils.readValue(requestBody, SamlServiceProvider.class); - - } - @Test - public void serviceProviderCreated() { - evaludateAuditEventData(ServiceProviderModifiedEvent.serviceProviderCreated(provider)); - } - - @Test - public void serviceProviderModified() { - evaludateAuditEventData(ServiceProviderModifiedEvent.serviceProviderModified(provider)); - } - - public void evaludateAuditEventData(ServiceProviderModifiedEvent event) { - assertEquals( - String.format(ServiceProviderModifiedEvent.dataFormat, - provider.getId(), - provider.getName(), - provider.getEntityId()), - event.getAuditEvent().getData() - ); - } - -} \ No newline at end of file