diff --git a/conf/Language-ext.properties b/conf/Language-ext.properties new file mode 100644 index 0000000..b0bba54 --- /dev/null +++ b/conf/Language-ext.properties @@ -0,0 +1,25 @@ +com.dotcms.repackage.javax.portlet.title.saml=SAML Configuration +add-idp=Add New SAML Configuration +disabled-sites=Disabled SAML Authentication +disable-site=Disable SAML per Site +download-sp-metadata=Download SP Metadata +idp-name=IdP Name +sp-metadata-file=SP Metadata File +idp-config-name-label=Configuration Name +idp-id=Configuration Id +idp-status-label=Enabled? +sp-issuer-url-label=SP Issuer URL +sp-endpoint-hostname-label=SP Endponint Hostname +private-key-label=Private Key +public-certificate-label=Public Cert +idp-metadata-label=IdP Metadata File +idp-validation-label=Validation Type +optional-properties-label=Override Properties +add-site=Sites +add-site-to-config=Add Site +site=Site +remove=Remove +add-edit-dialog-title=Add/Edit SAML Configuration +disabled-sites-dialog-title=Add/Remove Disabled SAML Sites +delete-dialog-title=Delete SAML Configuration Confirmation +delete-dialog-text=Are you sure you want to delete this SAML Configuration? (This operation cannot be undone) \ No newline at end of file diff --git a/conf/portlet-ext.xml b/conf/portlet-ext.xml new file mode 100644 index 0000000..27497be --- /dev/null +++ b/conf/portlet-ext.xml @@ -0,0 +1,12 @@ + + saml + SAML Configuration + com.liferay.portlet.JSPPortlet + + view-jsp + /plugins/plugin-com.dotcms.dotsaml/saml/view_saml_configuration.jsp + + + CMS Administrator + + diff --git a/conf/web-ext.xml b/conf/web-ext.xml index e60d9bb..a96bca6 100644 --- a/conf/web-ext.xml +++ b/conf/web-ext.xml @@ -1,6 +1,7 @@ SamlAccessFilter com.dotcms.plugin.saml.v3.filter.SamlAccessFilter + true diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/DotSamlResource.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/DotSamlResource.java new file mode 100644 index 0000000..def4e9e --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/DotSamlResource.java @@ -0,0 +1,346 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import com.dotcms.plugin.saml.v3.util.pagination.IdpConfigPaginator; +import com.dotcms.repackage.javax.ws.rs.*; +import com.dotcms.repackage.javax.ws.rs.core.Context; +import com.dotcms.repackage.javax.ws.rs.core.MediaType; +import com.dotcms.repackage.javax.ws.rs.core.Response; +import com.dotcms.repackage.org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import com.dotcms.repackage.org.glassfish.jersey.media.multipart.FormDataParam; +import com.dotcms.repackage.org.glassfish.jersey.server.JSONP; +import com.dotcms.rest.InitDataObject; +import com.dotcms.rest.ResponseEntityView; +import com.dotcms.rest.WebResource; +import com.dotcms.rest.annotation.NoCache; +import com.dotcms.rest.exception.mapper.ExceptionMapperUtil; +import com.dotcms.util.CollectionsUtils; +import com.dotcms.util.PaginationUtil; +import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.json.JSONException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.liferay.portal.model.User; +import org.apache.commons.io.IOUtils; + +import javax.servlet.http.HttpServletRequest; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +@Path("/v1/dotsaml") +public class DotSamlResource implements Serializable { + + private final IdpConfigHelper idpConfigHelper; + private final WebResource webResource; + private final PaginationUtil paginationUtil; + + public DotSamlResource() { + this.idpConfigHelper = IdpConfigHelper.getInstance(); + this.webResource = new WebResource(); + this.paginationUtil = new PaginationUtil(new IdpConfigPaginator()); + } + + @GET + @Path("/idps") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final Response getIdps(@Context final HttpServletRequest request, + @QueryParam(PaginationUtil.FILTER) final String filter, + @QueryParam(PaginationUtil.PAGE) final int page, + @QueryParam(PaginationUtil.PER_PAGE) final int perPage, + @DefaultValue("upper(name)") @QueryParam(PaginationUtil.ORDER_BY) String orderbyParam, + @DefaultValue("ASC") @QueryParam(PaginationUtil.DIRECTION) String direction) { + final InitDataObject initData = this.webResource.init(null, true, request, true, null); + final User user = initData.getUser(); + + Response response; + + try { + response = this.paginationUtil.getPage(request, user, filter, page, perPage, orderbyParam, direction); + + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting idps", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // getIdps. + + @GET + @Path("/idp/{id}") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response getIdp(@PathParam("id") final String id, @Context final HttpServletRequest req){ + final InitDataObject initData = this.webResource.init(null, false, req, false, null); + Response response; + + try{ + final IdpConfig idpConfig = idpConfigHelper.findIdpConfig(id); + response = Response.ok(new ResponseEntityView(idpConfig)).build(); + } catch (DotDataException e) { + Logger.error(this,"Idp not found (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp not found (" + e.getMessage() + ")"); + } catch (IOException e) { + Logger.error(this,"Idp is not valid (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting posting idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } //getIdp. + + @POST + @Path("/idp") + @JSONP + @NoCache + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final Response createIdpConfig(@Context final HttpServletRequest req, + @FormDataParam("id") String id, + @FormDataParam("idpName") String idpName, + @FormDataParam("enabled") boolean enabled, + @FormDataParam("sPIssuerURL") String sPIssuerURL, + @FormDataParam("sPEndponintHostname") String sPEndponintHostname, + @FormDataParam("privateKey") InputStream privateKeyStream, + @FormDataParam("privateKey") FormDataContentDisposition privateKeyFileDetail, + @FormDataParam("publicCert") InputStream publicCertStream, + @FormDataParam("publicCert") FormDataContentDisposition publicCertFileDetail, + @FormDataParam("idPMetadataFile") InputStream idPMetadataFileStream, + @FormDataParam("idPMetadataFile") FormDataContentDisposition idPMetadataFileDetail, + @FormDataParam("signatureValidationType") String signatureValidationType, + @FormDataParam("optionalProperties") String optionalProperties, + @FormDataParam("sites") String sites) { + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + IdpConfig.Builder idpBuilder; + + if (UtilMethods.isSet(id)){ + idpBuilder = IdpConfig.convertIdpConfigToBuilder(idpConfigHelper.findIdpConfig(id)); + } else { + idpBuilder = new IdpConfig.Builder(); + } + + idpBuilder.idpName(idpName); + idpBuilder.enabled(enabled); + idpBuilder.sPIssuerURL(sPIssuerURL); + idpBuilder.sPEndponintHostname(sPEndponintHostname); + + if (UtilMethods.isSet(privateKeyFileDetail) && UtilMethods.isSet(privateKeyFileDetail.getFileName())){ + File privateKey = File.createTempFile("privateKey", "key"); + Files.copy(privateKeyStream, privateKey.toPath(), StandardCopyOption.REPLACE_EXISTING); + IOUtils.closeQuietly(privateKeyStream); + idpBuilder.privateKey(privateKey); + } + if (UtilMethods.isSet(publicCertFileDetail) && UtilMethods.isSet(publicCertFileDetail.getFileName())){ + File publicCert = File.createTempFile("publicCert", "crt"); + Files.copy(publicCertStream, publicCert.toPath(), StandardCopyOption.REPLACE_EXISTING); + IOUtils.closeQuietly(publicCertStream); + idpBuilder.publicCert(publicCert); + } + if (UtilMethods.isSet(idPMetadataFileDetail) && UtilMethods.isSet(idPMetadataFileDetail.getFileName())){ + File idPMetadataFile = File.createTempFile("idPMetadataFile", "xml"); + Files.copy(idPMetadataFileStream, idPMetadataFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + IOUtils.closeQuietly(idPMetadataFileStream); + idpBuilder.idPMetadataFile(idPMetadataFile); + } + + idpBuilder.signatureValidationType(signatureValidationType); + + if (UtilMethods.isSet(optionalProperties)){ + final Properties parsedProperties = new Properties(); + parsedProperties.load(new StringReader(optionalProperties)); + idpBuilder.optionalProperties(parsedProperties); + } + + HashMap sitesMap = new ObjectMapper().readValue(sites, HashMap.class); + idpBuilder.sites(sitesMap); + + IdpConfig idpConfig = idpBuilder.build(); + idpConfig = idpConfigHelper.saveIdpConfig(idpConfig); + + response = Response.ok(new ResponseEntityView(idpConfig)).build(); + } catch (IOException e) { + Logger.error(this,"Idp is not valid (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting posting idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // createIdpConfig. + + @DELETE + @Path("/idp/{id}") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response deleteIdpConfig(@PathParam("id") final String id, @Context final HttpServletRequest req){ + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + IdpConfig idpConfig = new IdpConfig.Builder().id(id).build(); + + idpConfigHelper.deleteIdpConfig(idpConfig); + + response = Response.ok(new ResponseEntityView(CollectionsUtils.map("deleted", id))).build(); + } catch (IOException e) { + Logger.error(this,"Idp is not valid (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error deleting idps", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // deleteIdpConfig. + + @PUT + @Path("/default/{id}") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response setDefault(@PathParam("id") final String id, @Context final HttpServletRequest req){ + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + idpConfigHelper.setDefaultIdpConfig(id); + + response = Response.ok(new ResponseEntityView(CollectionsUtils.map("default", id))).build(); + } catch (DotDataException e) { + Logger.error(this,"Idp not found (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp not found (" + e.getMessage() + ")"); + } catch (IOException e) { + Logger.error(this,"Idp is not valid (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting setting idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // setDefault. + + @GET + @Path("/default") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response getDefault(@Context final HttpServletRequest req){ + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + final String defaultIdpConfigId = idpConfigHelper.getDefaultIdpConfigId(); + + response = + Response.ok(new ResponseEntityView( + CollectionsUtils.map(IdpConfigWriterReader.DEFAULT_SAML_CONFIG, defaultIdpConfigId))).build(); + + } catch (IOException e) { + Logger.error(this,"Error reading file with Idps (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Idp is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json with Idps (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting default idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // getDefault. + + @GET + @Path("/disabledsites") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response getDisabledSites(@Context final HttpServletRequest req){ + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + final Map disabledSiteIds = idpConfigHelper.getDisabledSiteIds(); + + response = Response.ok(new ResponseEntityView( + CollectionsUtils.map(IdpConfigWriterReader.DISABLE_SAML_SITES, disabledSiteIds))) + .build(); + + } catch (IOException e) { + Logger.error(this,"Error reading file with disabled sites (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "disable site is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json with Idps (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling disabled site json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting default idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } // getDisabledSites. + + @POST + @Path("/disabledsites") + @JSONP + @NoCache + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final Response saveDisabledSited(@Context final HttpServletRequest req, + @FormDataParam("disabledsites") String disabledSites) { + this.webResource.init(null, true, req, true, null); + + Response response; + + try { + HashMap disabledSitesMap = new ObjectMapper().readValue(disabledSites, HashMap.class); + idpConfigHelper.saveDisabledSiteIds(disabledSitesMap); + + response = Response.ok().build(); + + } catch (IOException e) { + Logger.error(this,"Error reading file with disabled sites (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "disable site is not valid (" + e.getMessage() + ")"); + } catch (JSONException e) { + Logger.error(this,"Error handling json with Idps (" + e.getMessage() + ")", e); + response = ExceptionMapperUtil.createResponse(null, "Error handling disabled site json (" + e.getMessage() + ")"); + } catch (Exception e) { // this is an unknown error, so we report as a 500. + Logger.error(this,"Error getting default idp", e); + response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return response; + } + +} + diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfig.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfig.java new file mode 100644 index 0000000..408b5da --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfig.java @@ -0,0 +1,203 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import java.io.File; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; + +public class IdpConfig { + + private String id; + private String idpName; + private boolean enabled; + private String sPIssuerURL; + private String sPEndponintHostname; + private File privateKey; + private File publicCert; + private File idPMetadataFile; + private String signatureValidationType; + private Properties optionalProperties; + private Map sites; + + private IdpConfig() { + } + + public static class Builder { + private IdpConfig idpConfigToBuild; + + Builder() { + idpConfigToBuild = new IdpConfig(); + } + + IdpConfig build() { + IdpConfig builtIdpConfig = idpConfigToBuild; + idpConfigToBuild = new IdpConfig(); + + return builtIdpConfig; + } + + public Builder id(String id) { + this.idpConfigToBuild.id = id; + return this; + } + + public Builder idpName(String idpName) { + this.idpConfigToBuild.idpName = idpName; + return this; + } + + public Builder enabled(boolean enabled) { + this.idpConfigToBuild.enabled = enabled; + return this; + } + + public Builder sPIssuerURL(String sPIssuerURL) { + this.idpConfigToBuild.sPIssuerURL = sPIssuerURL; + return this; + } + + public Builder sPEndponintHostname(String sPEndponintHostname) { + this.idpConfigToBuild.sPEndponintHostname = sPEndponintHostname; + return this; + } + + public Builder privateKey(File privateKey) { + this.idpConfigToBuild.privateKey = privateKey; + return this; + } + + public Builder publicCert(File publicCert) { + this.idpConfigToBuild.publicCert = publicCert; + return this; + } + + public Builder idPMetadataFile(File idPMetadataFile) { + this.idpConfigToBuild.idPMetadataFile = idPMetadataFile; + return this; + } + + public Builder signatureValidationType(String signatureValidationType) { + this.idpConfigToBuild.signatureValidationType = signatureValidationType; + return this; + } + + public Builder optionalProperties(Properties optionalProperties) { + this.idpConfigToBuild.optionalProperties = optionalProperties; + return this; + } + + public Builder sites(Map sites) { + this.idpConfigToBuild.sites = sites; + return this; + } + } + + public static IdpConfig.Builder convertIdpConfigToBuilder(IdpConfig idpConfig){ + IdpConfig.Builder builder = new IdpConfig.Builder(); + + builder.id(idpConfig.getId()) + .idpName(idpConfig.getIdpName()) + .enabled(idpConfig.isEnabled()) + .sPIssuerURL(idpConfig.getsPIssuerURL()) + .sPEndponintHostname(idpConfig.getsPEndponintHostname()) + .privateKey(idpConfig.getPrivateKey()) + .publicCert(idpConfig.getPublicCert()) + .idPMetadataFile(idpConfig.getIdPMetadataFile()) + .signatureValidationType(idpConfig.getSignatureValidationType()) + .optionalProperties(idpConfig.getOptionalProperties()) + .sites(idpConfig.getSites()); + + return builder; + } + + public String getId() { + return id; + } + + public String getIdpName() { + return idpName; + } + + public boolean isEnabled() { + return enabled; + } + + public String getsPIssuerURL() { + return sPIssuerURL; + } + + public String getsPEndponintHostname() { + return sPEndponintHostname; + } + + public File getPrivateKey() { + return privateKey; + } + + public File getPublicCert() { + return publicCert; + } + + public File getIdPMetadataFile() { + return idPMetadataFile; + } + + public String getSignatureValidationType() { + return signatureValidationType; + } + + public Properties getOptionalProperties() { + return optionalProperties; + } + + public Map getSites() { + return sites; + } + + private String getSearchable() { + StringBuilder sb = new StringBuilder(); + + //config name. + sb.append(this.idpName); + sb.append(" "); + //SP Issuer URL. + sb.append(this.sPIssuerURL); + sb.append(" "); + //SP Endpoint Hostname. + sb.append(this.sPEndponintHostname); + sb.append(" "); + //sites related to the IdP. + for (Map.Entry entry : this.sites.entrySet()) { + sb.append(entry.getKey()); + sb.append(" "); + sb.append(entry.getValue()); + sb.append(" "); + } + //any override parameter. + sb.append(this.optionalProperties); + + return sb.toString(); + } + + public boolean contains(String string) { + return getSearchable().toLowerCase().contains(string.trim().toLowerCase()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + IdpConfig idpConfig = (IdpConfig) o; + return Objects.equals(id, idpConfig.id); + } + + @Override + public int hashCode() { + + return Objects.hash(id); + } +} diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigComparator.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigComparator.java new file mode 100644 index 0000000..3bafa19 --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigComparator.java @@ -0,0 +1,11 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import java.util.Comparator; + +public class IdpConfigComparator implements Comparator{ + + @Override + public int compare(IdpConfig idpConfig1, IdpConfig idpConfig2) { + return idpConfig1.getIdpName().compareToIgnoreCase(idpConfig2.getIdpName()); + } +} diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigHelper.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigHelper.java new file mode 100644 index 0000000..77c14f2 --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigHelper.java @@ -0,0 +1,185 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.util.Config; +import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UUIDGenerator; +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.json.JSONException; +import com.liferay.util.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; +import java.util.Map; + +public class IdpConfigHelper implements Serializable { + + private final String assetsPath; + private final String idpfilePath; + private final String certsParentPath; + private final String metadataParentPath; + + final static String SAML = "saml"; + + public IdpConfigHelper() { + this.assetsPath = Config.getStringProperty("ASSET_REAL_PATH", + FileUtil.getRealPath(Config.getStringProperty("ASSET_PATH", "/assets"))); + + this.idpfilePath = assetsPath + File.separator + SAML + File.separator + "config.json"; + this.certsParentPath = assetsPath + File.separator + SAML + File.separator + "certs" + File.separator; + this.metadataParentPath = assetsPath + File.separator + SAML + File.separator + "metadata" + File.separator; + } // IdpConfigHelper. + + private static class SingletonHolder { + private static final IdpConfigHelper INSTANCE = new IdpConfigHelper(); + } // SingletonHolder + + public static IdpConfigHelper getInstance() { + return IdpConfigHelper.SingletonHolder.INSTANCE; + } // getInstance. + + public List getIdpConfigs() throws IOException, JSONException { + final List idpConfigs = IdpConfigWriterReader.readIdpConfigs(new File(idpfilePath)); + return idpConfigs; + } // getIdpConfigs. + + public IdpConfig findIdpConfig(String id) throws IOException, JSONException, DotDataException { + if (UtilMethods.isSet(id)){ + List idpConfigList = getIdpConfigs(); + IdpConfig idpConfig = new IdpConfig.Builder().id(id).build(); + return idpConfigList.get(idpConfigList.indexOf(idpConfig)); + } else { + throw new DotDataException("Idp with id:" + id + " not found in file."); + } + } // findIdpConfig. + + public IdpConfig saveIdpConfig(IdpConfig idpConfig) throws IOException, JSONException { + List idpConfigList = getIdpConfigs(); + + if (UtilMethods.isSet(idpConfig.getId())){ + //Update. + + //Renaming files + idpConfig = renameIdpConfigFiles(idpConfig); + + idpConfigList.remove(idpConfig); + idpConfigList.add(idpConfig); + IdpConfigWriterReader.writeIdpConfigs(idpConfigList, idpfilePath); + } else { + //Create. + IdpConfig.Builder builder = IdpConfig.convertIdpConfigToBuilder(idpConfig); + //Creating new UUID. + builder.id(UUIDGenerator.generateUuid()); + idpConfig = builder.build(); + //Renaming files + idpConfig = renameIdpConfigFiles(idpConfig); + + idpConfigList.add(idpConfig); + IdpConfigWriterReader.writeIdpConfigs(idpConfigList, idpfilePath); + } + + return idpConfig; + } // saveIdpConfig. + + public void deleteIdpConfig(IdpConfig idpConfig) throws IOException, JSONException { + List idpConfigList = getIdpConfigs(); + String defaultIdpConfigId = IdpConfigWriterReader.readDefaultIdpConfigId(new File(idpfilePath)); + + //We need to clean the defaultIdpConfigId if we are deleting the same IDP. + if (idpConfig.getId().equals(defaultIdpConfigId)){ + defaultIdpConfigId = ""; + } + + if (idpConfigList.contains(idpConfig)){ + //Delete from list. + idpConfig = idpConfigList.get(idpConfigList.indexOf(idpConfig)); + idpConfigList.remove(idpConfig); + IdpConfigWriterReader.writeDefaultIdpConfigId(idpConfigList, defaultIdpConfigId, idpfilePath); + //Delete files from FS. + deleteFile(idpConfig.getPrivateKey()); + deleteFile(idpConfig.getPublicCert()); + deleteFile(idpConfig.getIdPMetadataFile()); + + } else { + Logger.warn(this, "IdpConfig with Id: " + idpConfig.getId() + "no longer exists in file."); + } + } // deleteIdpConfig. + + public void setDefaultIdpConfig(String idpConfigId) throws IOException, JSONException, DotDataException { + List idpConfigList = getIdpConfigs(); + + final IdpConfig idpConfig = new IdpConfig.Builder().id(idpConfigId).build(); + + if (idpConfigList.contains(idpConfig)){ + IdpConfigWriterReader.writeDefaultIdpConfigId(idpConfigId, idpfilePath); + } + else { + Logger.error(this, "IdpConfig with Id: " + idpConfig.getId() + "no longer exists in file."); + throw new DotDataException("IdpConfig with Id: " + idpConfig.getId() + "no longer exists in file."); + } + } // setDefaultIdpConfig. + + public String getDefaultIdpConfigId() throws IOException, JSONException { + return IdpConfigWriterReader.readDefaultIdpConfigId(new File(idpfilePath)); + } // setDefaultIdpConfig. + + public void saveDisabledSiteIds(Map disablebSitesMap) throws IOException, JSONException { + IdpConfigWriterReader.writeDisabledSIteIds(disablebSitesMap, idpfilePath); + } // saveDisabledSiteIds. + + public Map getDisabledSiteIds() throws IOException, JSONException { + return IdpConfigWriterReader.readDisabledSiteIds(new File(idpfilePath)); + } // getDisabledSiteIds. + + private IdpConfig renameIdpConfigFiles(IdpConfig idpConfig) throws IOException { + IdpConfig.Builder builder = IdpConfig.convertIdpConfigToBuilder(idpConfig); + + if (UtilMethods.isSet(idpConfig.getPrivateKey())){ + builder.privateKey(writeCertFile(idpConfig.getPrivateKey(), idpConfig.getId() + ".key")); + } + if (UtilMethods.isSet(idpConfig.getPublicCert())){ + builder.publicCert(writeCertFile(idpConfig.getPublicCert(), idpConfig.getId() + ".crt")); + } + if (UtilMethods.isSet(idpConfig.getIdPMetadataFile())){ + builder.idPMetadataFile(writeMetadataFile(idpConfig.getIdPMetadataFile(), idpConfig.getId() + ".xml")); + } + + return builder.build(); + } // renameIdpConfigFiles. + + private File writeCertFile(File sourceFile, String fileName) throws IOException{ + return this.writeFile(sourceFile, this.certsParentPath, fileName); + } // writeCertFile. + + private File writeMetadataFile(File sourceFile, String fileName) throws IOException{ + return this.writeFile(sourceFile, this.metadataParentPath, fileName); + } // writeMetadataFile. + + private File writeFile(File sourceFile, String parentPath, String fileName) throws IOException{ + File targetFile = new File(parentPath + fileName); + + if (!targetFile.exists()) { + targetFile.getParentFile().mkdirs(); + targetFile.createNewFile(); + } + + final Path movedPath = Files.move(sourceFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + + return movedPath.toFile(); + } // writeFile. + + private void deleteFile(File fileToDelete){ + if (fileToDelete != null){ + if (fileToDelete.exists() && fileToDelete.canWrite()){ + fileToDelete.delete(); + } else { + Logger.warn(this, "File doesn't exist or can't write: " + fileToDelete.getName()); + } + } + } // deleteFile. +} diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigWriterReader.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigWriterReader.java new file mode 100644 index 0000000..0f82d11 --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpConfigWriterReader.java @@ -0,0 +1,129 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import com.dotmarketing.util.json.JSONArray; +import com.dotmarketing.util.json.JSONException; +import com.dotmarketing.util.json.JSONObject; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.util.*; + +public class IdpConfigWriterReader { + + public static final String IDP_CONFIGS = "samlConfigs"; + public static final String DEFAULT_SAML_CONFIG = "defaultSamlConfig"; + public static final String DISABLE_SAML_SITES = "disabledSamlSites"; + + public static File write(List idpConfigList, String defaultIdpConfigId, Map disabledSitesMap, String idpConfigPath) throws IOException, JSONException { + JSONArray jsonArray = new JSONArray(); + for (IdpConfig idpConfig : idpConfigList) { + final JSONObject joIdp = IdpJsonTransformer.idpToJson(idpConfig); + final JSONObject joOnlyId = new JSONObject().put(idpConfig.getId(), joIdp); + jsonArray.add(joOnlyId); + } + + JSONObject jo = new JSONObject(); + jo.put(DEFAULT_SAML_CONFIG, defaultIdpConfigId); + jo.put(IDP_CONFIGS, jsonArray); + jo.put(DISABLE_SAML_SITES, SiteJsonTransformer.getJsonObjecFromtMap(disabledSitesMap)); + + File idpConfigFile = new File(idpConfigPath); + if (!idpConfigFile.exists()) { + idpConfigFile.getParentFile().mkdirs(); + idpConfigFile.createNewFile(); + } + + try (final FileWriter file = new FileWriter(idpConfigFile)) { + file.write(jo.toString()); + + } + + return new File(idpConfigPath); + } + + public static String readDefaultIdpConfigId(final File idpConfigFile) throws IOException, JSONException { + String defaultIdpConfigId = ""; + + if (idpConfigFile.exists() && idpConfigFile.canRead()) { + String content = new String(Files.readAllBytes(idpConfigFile.toPath())); + JSONObject jsonObject = new JSONObject(content); + if (jsonObject.has(DEFAULT_SAML_CONFIG)){ + defaultIdpConfigId = jsonObject.getString(DEFAULT_SAML_CONFIG); + } + } + + return defaultIdpConfigId; + } + + public static File writeDefaultIdpConfigId(String defaultIdpConfigId, String idpConfigPath) throws IOException, JSONException { + return write(readIdpConfigs(new File(idpConfigPath)), + defaultIdpConfigId, + readDisabledSiteIds(new File(idpConfigPath)), + idpConfigPath); + } + + public static File writeDefaultIdpConfigId(List idpConfigList, String defaultIdpConfigId, String idpConfigPath) throws IOException, JSONException { + return write(idpConfigList, + defaultIdpConfigId, + readDisabledSiteIds(new File(idpConfigPath)), + idpConfigPath); + } + + public static List readIdpConfigs(final File idpConfigFile) throws IOException, JSONException { + List idpConfigList = new ArrayList<>(); + + if (idpConfigFile.exists() && idpConfigFile.canRead()) { + String content = new String(Files.readAllBytes(idpConfigFile.toPath())); + JSONObject jsonObject = new JSONObject(content); + final JSONArray jsonArray = jsonObject.getJSONArray(IDP_CONFIGS); + + for (int i = 0; i < jsonArray.size(); i++) { + //joId = UUID:{idpConfigs} + final JSONObject joId = jsonArray.getJSONObject(i); + + //I don't like this hack but we need to get the id. + Iterator keys = joId.keys(); + String idpId = keys.next(); + + //Now we can get the real JSONObject. + final JSONObject jo = joId.getJSONObject(idpId); + final IdpConfig idpConfig = IdpJsonTransformer.jsonToIdp(jo); + idpConfigList.add(idpConfig); + } + } + + return idpConfigList; + } + + public static File writeIdpConfigs(List idpConfigList, String idpConfigPath) throws IOException, JSONException { + return write(idpConfigList, readDefaultIdpConfigId(new File(idpConfigPath)), readDisabledSiteIds(new File(idpConfigPath)), idpConfigPath); + } + + public static Map readDisabledSiteIds(final File idpConfigFile) + throws IOException, JSONException { + + Map disabledSites = new HashMap<>(); + + if (idpConfigFile.exists()) { + String content = new String(Files.readAllBytes(idpConfigFile.toPath())); + JSONObject jo = new JSONObject(content); + + if (jo.has(DEFAULT_SAML_CONFIG)) { + final JSONObject joDisabledSites = jo.getJSONObject(DISABLE_SAML_SITES); + disabledSites = SiteJsonTransformer.getMapFromJsonObject(joDisabledSites); + } + } + + return disabledSites; + } + + public static File writeDisabledSIteIds(Map disabledSitesMap, String idpConfigPath) throws IOException, JSONException { + + return write(readIdpConfigs(new File(idpConfigPath)), + readDefaultIdpConfigId(new File(idpConfigPath)), + disabledSitesMap, + idpConfigPath); + } +} diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpJsonTransformer.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpJsonTransformer.java new file mode 100644 index 0000000..445e63f --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/IdpJsonTransformer.java @@ -0,0 +1,100 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.json.JSONException; +import com.dotmarketing.util.json.JSONObject; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.Properties; + +public class IdpJsonTransformer { + + public static JSONObject idpToJson(IdpConfig idpConfig) throws JSONException, IOException { + JSONObject jo = new JSONObject(); + + jo.put("id", idpConfig.getId()); + jo.put("idpName", idpConfig.getIdpName()); + jo.put("enabled", idpConfig.isEnabled()); + jo.put("sPIssuerURL", idpConfig.getsPIssuerURL()); + jo.put("sPEndponintHostname", idpConfig.getsPEndponintHostname()); + jo.put("privateKey", getCanonicalPathIfExists(idpConfig.getPrivateKey())); + jo.put("publicCert", getCanonicalPathIfExists(idpConfig.getPublicCert())); + jo.put("idPMetadataFile", getCanonicalPathIfExists(idpConfig.getIdPMetadataFile())); + jo.put("signatureValidationType", idpConfig.getSignatureValidationType()); + jo.put("optionalProperties", getJsonObjectFromProperties(idpConfig.getOptionalProperties())); + jo.put("sites", SiteJsonTransformer.getJsonObjecFromtMap(idpConfig.getSites())); + + return jo; + } + + public static IdpConfig jsonToIdp(JSONObject jsonObject) throws JSONException { + IdpConfig.Builder builder = new IdpConfig.Builder(); + + builder.id(jsonObject.getString("id")); + builder.idpName(jsonObject.getString("idpName")); + builder.enabled(jsonObject.getBoolean("enabled")); + builder.sPIssuerURL(jsonObject.getString("sPIssuerURL")); + builder.sPEndponintHostname(jsonObject.getString("sPEndponintHostname")); + builder.privateKey(getFileFromCanonicalPath(jsonObject.getString("privateKey"))); + builder.publicCert(getFileFromCanonicalPath(jsonObject.getString("publicCert"))); + builder.idPMetadataFile(getFileFromCanonicalPath(jsonObject.getString("idPMetadataFile"))); + builder.signatureValidationType(jsonObject.getString("signatureValidationType")); + builder.optionalProperties(getPropertiesFromJsonObject(jsonObject.getJSONObject("optionalProperties"))); + builder.sites(SiteJsonTransformer. getMapFromJsonObject(jsonObject.getJSONObject("sites"))); + + return builder.build(); + } + + private static String getCanonicalPathIfExists(File file) throws IOException{ + String canonicalPath = ""; + if (file != null){ + canonicalPath = file.getCanonicalPath(); + } + return canonicalPath; + } + + private static File getFileFromCanonicalPath(String canonicalPath){ + File file = null; + + if (UtilMethods.isSet(canonicalPath)){ + File fileFromPath = new File(canonicalPath); + if (fileFromPath.exists()){ + file = fileFromPath; + } else { + Logger.error(IdpJsonTransformer.class, "File doesn't exists: " + canonicalPath); + } + } + + return file; + } + + private static JSONObject getJsonObjectFromProperties(Properties properties) throws JSONException { + JSONObject jo = new JSONObject(); + + if (UtilMethods.isSet(properties)){ + for (String key : properties.stringPropertyNames()) { + jo.put(key, properties.getProperty(key)); + } + } + + return jo; + } + + private static Properties getPropertiesFromJsonObject(JSONObject jo) throws JSONException { + Properties properties = new Properties(); + Iterator keys = jo.keys(); + + while( keys.hasNext() ) { + String key = (String)keys.next(); + String value = jo.getString(key); + + properties.setProperty(key, value); + } + + return properties; + } + +} diff --git a/src/com/dotcms/plugin/saml/v3/rest/api/v1/SiteJsonTransformer.java b/src/com/dotcms/plugin/saml/v3/rest/api/v1/SiteJsonTransformer.java new file mode 100644 index 0000000..2fd8570 --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/rest/api/v1/SiteJsonTransformer.java @@ -0,0 +1,38 @@ +package com.dotcms.plugin.saml.v3.rest.api.v1; + +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.json.JSONException; +import com.dotmarketing.util.json.JSONObject; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class SiteJsonTransformer { + + public static JSONObject getJsonObjecFromtMap(Map map) throws JSONException { + JSONObject jsonObject = new JSONObject(); + + if (UtilMethods.isSet(map)) { + for (Map.Entry entry : map.entrySet()) { + jsonObject.put(entry.getKey(), entry.getValue()); + } + } + + return jsonObject; + } + + public static Map getMapFromJsonObject(JSONObject jsonObject) throws JSONException { + Map map = new HashMap<>(); + Iterator keys = jsonObject.keys(); + + while (keys.hasNext()) { + String key = (String) keys.next(); + String value = jsonObject.getString(key); + + map.put(key, value); + } + + return map; + } +} diff --git a/src/com/dotcms/plugin/saml/v3/util/pagination/IdpConfigPaginator.java b/src/com/dotcms/plugin/saml/v3/util/pagination/IdpConfigPaginator.java new file mode 100644 index 0000000..7ddffa4 --- /dev/null +++ b/src/com/dotcms/plugin/saml/v3/util/pagination/IdpConfigPaginator.java @@ -0,0 +1,69 @@ +package com.dotcms.plugin.saml.v3.util.pagination; + +import com.dotcms.plugin.saml.v3.rest.api.v1.IdpConfig; +import com.dotcms.plugin.saml.v3.rest.api.v1.IdpConfigWriterReader; +import com.dotcms.util.pagination.OrderDirection; +import com.dotcms.util.pagination.Paginator; +import com.dotmarketing.exception.DotRuntimeException; +import com.dotmarketing.util.Config; +import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.json.JSONException; +import com.liferay.portal.model.User; +import com.liferay.util.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +public class IdpConfigPaginator implements Paginator { + + private final AtomicInteger lastTotalRecords = new AtomicInteger(0); + + private final String assetsPath; + private final String idpfilePath; + + public IdpConfigPaginator() { + this.assetsPath = Config.getStringProperty("ASSET_REAL_PATH", + FileUtil.getRealPath(Config.getStringProperty("ASSET_PATH", "/assets"))); + this.idpfilePath = assetsPath + File.separator + "saml" + File.separator + "config.json"; + } + + @Override + public long getTotalRecords(String s) { + return lastTotalRecords.get(); + } + + @Override + public Collection getItems(final User user, final String filter, final int limit, final int offset, + final String orderby, final OrderDirection direction, + final Map extraParams) { + + try { + List idpConfigs = IdpConfigWriterReader.readIdpConfigs(new File(idpfilePath)); + + if (UtilMethods.isSet(filter)){ + idpConfigs = idpConfigs.stream() + .filter(x -> x.contains(filter)) + .collect(Collectors.toList()); + } + + List paginatedAndFiltered = idpConfigs.stream() + .skip(offset) + .limit(limit) + .collect(Collectors.toList()); + + lastTotalRecords.set(idpConfigs.size()); + + return paginatedAndFiltered; + + } catch (IOException | JSONException e) { + Logger.error(IdpConfigPaginator.class, "Error getting paginated IdpConfigs", e); + throw new DotRuntimeException(e.getMessage(), e); + } + } +} diff --git a/src/com/dotcms/rest/ErrorEntity.java b/src/com/dotcms/rest/ErrorEntity.java new file mode 100644 index 0000000..3248b98 --- /dev/null +++ b/src/com/dotcms/rest/ErrorEntity.java @@ -0,0 +1,45 @@ +package com.dotcms.rest; + +import java.io.Serializable; + +/** + * Encapsulates an error. + * Usually the errors are returned to the client transformed on JSON. + * @author jsanca + */ +public class ErrorEntity implements Serializable { + + /** In case an error code */ + private final String errorCode; + + /** Final message (no an i18n key */ + private final String message; + + /** + * Constructor + * @param errorCode + * @param message + */ + public ErrorEntity(final String errorCode, + final String message) { + + this.errorCode = errorCode; + this.message = message; + } + + public String getErrorCode() { + return errorCode; + } + + public String getMessage() { + return message; + } + + @Override + public String toString() { + return "ErrorEntity{" + + "errorCode='" + errorCode + '\'' + + ", message='" + message + '\'' + + '}'; + } +} // E:O:F:ErrorEntity. diff --git a/src/com/dotcms/rest/MessageEntity.java b/src/com/dotcms/rest/MessageEntity.java new file mode 100644 index 0000000..8cdbb0d --- /dev/null +++ b/src/com/dotcms/rest/MessageEntity.java @@ -0,0 +1,30 @@ +package com.dotcms.rest; + +import java.io.Serializable; + +/** + * Encapsulates a message. + * Usually the errors are returned to the client transformed on JSON. + * @author jsanca + */ +public class MessageEntity implements Serializable { + + private final String message; + + public MessageEntity(final String message) { + this.message = message; + } + + public String getMessage() { + + return message; + } + + @Override + public String toString() { + return "MessageEntity{" + + "message='" + message + '\'' + + '}'; + } +} // E:O:F:MessageEntity. + diff --git a/src/com/dotcms/rest/ResponseEntityView.java b/src/com/dotcms/rest/ResponseEntityView.java new file mode 100644 index 0000000..d34c3dd --- /dev/null +++ b/src/com/dotcms/rest/ResponseEntityView.java @@ -0,0 +1,132 @@ +package com.dotcms.rest; + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * Response Entity View encapsulates the response to include errors and the entity to be returned as part of the Jersey response + * @author jsanca + */ +public class ResponseEntityView implements Serializable { + + private static final String EMPTY_ENTITY = ""; + + private final List errors; + private final Object entity; + private final List messages; + private final Map i18nMessagesMap; + + + public ResponseEntityView(final List errors) { + + this.errors = errors; + this.messages = Collections.EMPTY_LIST; + this.entity = EMPTY_ENTITY; + this.i18nMessagesMap = Collections.EMPTY_MAP; + } + + public ResponseEntityView(final List errors, final Map i18nMessagesMap) { + + this.errors = errors; + this.messages = Collections.EMPTY_LIST; + this.entity = EMPTY_ENTITY; + this.i18nMessagesMap = i18nMessagesMap; + } + + public ResponseEntityView(final List errors, final Object entity) { + + this.errors = errors; + this.messages = Collections.EMPTY_LIST; + this.entity = entity; + this.i18nMessagesMap = Collections.EMPTY_MAP; + } + + public ResponseEntityView(final List errors, final Object entity, final Map i18nMessagesMap) { + + this.errors = errors; + this.messages = Collections.EMPTY_LIST; + this.entity = entity; + this.i18nMessagesMap = i18nMessagesMap; + } + + public ResponseEntityView(final Object entity) { + + this.errors = Collections.EMPTY_LIST; + this.messages = Collections.EMPTY_LIST; + this.entity = entity; + this.i18nMessagesMap = Collections.EMPTY_MAP; + } + + public ResponseEntityView(final Object entity, final Map i18nMessagesMap) { + + this.errors = Collections.EMPTY_LIST; + this.messages = Collections.EMPTY_LIST; + this.entity = entity; + this.i18nMessagesMap = i18nMessagesMap; + } + + public ResponseEntityView(final Object entity, + final List messages) { + + this.errors = Collections.EMPTY_LIST; + this.messages = messages; + this.entity = entity; + this.i18nMessagesMap = Collections.EMPTY_MAP; + } + + public ResponseEntityView(final Object entity, + final List messages, + final Map i18nMessagesMap) { + + this.errors = Collections.EMPTY_LIST; + this.messages = messages; + this.entity = entity; + this.i18nMessagesMap = i18nMessagesMap; + } + + public ResponseEntityView(final Object entity, final List errors, + final List messages) { + + this.errors = errors; + this.messages = messages; + this.entity = entity; + this.i18nMessagesMap = Collections.EMPTY_MAP; + } + + public ResponseEntityView(final Object entity, final List errors, + final List messages, final Map i18nMessagesMap) { + + this.errors = errors; + this.messages = messages; + this.entity = entity; + this.i18nMessagesMap = i18nMessagesMap; + } + + public List getErrors() { + return errors; + } + + public Object getEntity() { + return entity; + } + + public List getMessages() { + return messages; + } + + public Map getI18nMessagesMap() { + return i18nMessagesMap; + } + + @Override + public String toString() { + return "ResponseEntityView{" + + "errors=" + errors + + ", entity=" + entity + + ", messages=" + messages + + ", i18nMessagesMap=" + i18nMessagesMap + + '}'; + } +} // E:O:F:ResponseEntityView. diff --git a/src/com/dotcms/rest/config/DotRestApplication.java b/src/com/dotcms/rest/config/DotRestApplication.java new file mode 100644 index 0000000..100cc46 --- /dev/null +++ b/src/com/dotcms/rest/config/DotRestApplication.java @@ -0,0 +1,84 @@ +package com.dotcms.rest.config; + +import com.dotcms.plugin.saml.v3.rest.api.v1.DotSamlResource; +import com.dotcms.repackage.org.glassfish.jersey.media.multipart.MultiPartFeature; +import com.dotcms.rest.RulesEnginePortlet; +import com.dotcms.rest.TagResource; +import com.dotcms.rest.api.v1.languages.LanguagesResource; +import com.dotcms.rest.api.v1.personas.PersonaResource; +import com.dotcms.rest.api.v1.sites.ruleengine.rules.actions.ActionResource; +import com.dotcms.rest.api.v1.sites.ruleengine.rules.conditions.ConditionResource; +import com.dotcms.rest.api.v1.sites.ruleengine.rules.conditions.ConditionValueResource; +import com.dotcms.rest.api.v1.sites.ruleengine.rules.conditions.ConditionGroupResource; +import com.dotcms.rest.api.v1.sites.ruleengine.rules.RuleResource; +import com.dotcms.rest.api.v1.system.ruleengine.actionlets.ActionletsResource; +import com.dotcms.rest.api.v1.system.ruleengine.conditionlets.ConditionletsResource; +import com.dotcms.rest.api.v1.system.i18n.I18NResource; +import com.dotcms.rest.api.v1.user.UserResource; +import com.dotcms.rest.personas.PersonasResourcePortlet; + +import java.util.HashSet; +import java.util.Set; + +public class DotRestApplication extends com.dotcms.repackage.javax.ws.rs.core.Application { + protected volatile static Set> REST_CLASSES = null; + + @Override + public Set> getClasses() { + if(REST_CLASSES == null){ + synchronized (this.getClass().getName().intern()) { + if(REST_CLASSES == null){ + + REST_CLASSES = new HashSet<>(); + REST_CLASSES.add(MultiPartFeature.class); + REST_CLASSES.add(com.dotcms.rest.ESIndexResource.class); + REST_CLASSES.add(com.dotcms.rest.RoleResource.class); + REST_CLASSES.add(com.dotcms.rest.BundleResource.class); + REST_CLASSES.add(com.dotcms.rest.StructureResource.class); + REST_CLASSES.add(com.dotcms.rest.ContentResource.class); + REST_CLASSES.add(com.dotcms.rest.BundlePublisherResource.class); + REST_CLASSES.add(com.dotcms.rest.JSPPortlet.class); + REST_CLASSES.add(com.dotcms.rest.AuditPublishingResource.class); + REST_CLASSES.add(com.dotcms.rest.WidgetResource.class); + REST_CLASSES.add(com.dotcms.rest.CMSConfigResource.class); + REST_CLASSES.add(com.dotcms.rest.OSGIResource.class); + REST_CLASSES.add(com.dotcms.rest.UserResource.class); + REST_CLASSES.add(com.dotcms.rest.ClusterResource.class); + REST_CLASSES.add(com.dotcms.rest.EnvironmentResource.class); + REST_CLASSES.add(com.dotcms.rest.NotificationResource.class); + REST_CLASSES.add(com.dotcms.rest.IntegrityResource.class); + REST_CLASSES.add(com.dotcms.rest.LicenseResource.class); + REST_CLASSES.add(com.dotcms.rest.WorkflowResource.class); + + REST_CLASSES.add(com.dotcms.rest.RestExamplePortlet.class); + REST_CLASSES.add(com.dotcms.rest.elasticsearch.ESContentResourcePortlet.class); + + REST_CLASSES.add(PersonaResource.class); + REST_CLASSES.add(UserResource.class); + REST_CLASSES.add(TagResource.class); + + REST_CLASSES.add(RulesEnginePortlet.class); + REST_CLASSES.add(RuleResource.class); + REST_CLASSES.add(ConditionGroupResource.class); + REST_CLASSES.add(ConditionResource.class); + REST_CLASSES.add(ConditionValueResource.class); + REST_CLASSES.add(PersonasResourcePortlet.class); + + + REST_CLASSES.add(ConditionletsResource.class); + REST_CLASSES.add(ActionResource.class); + REST_CLASSES.add(ActionletsResource.class); + REST_CLASSES.add(I18NResource.class); + REST_CLASSES.add(LanguagesResource.class); + + //SAML RESOURCES. + REST_CLASSES.add(DotSamlResource.class); + + } + } + } + return REST_CLASSES; + + } + +} \ No newline at end of file diff --git a/src/com/dotcms/rest/exception/mapper/ExceptionMapperUtil.java b/src/com/dotcms/rest/exception/mapper/ExceptionMapperUtil.java new file mode 100644 index 0000000..cb22927 --- /dev/null +++ b/src/com/dotcms/rest/exception/mapper/ExceptionMapperUtil.java @@ -0,0 +1,85 @@ +package com.dotcms.rest.exception.mapper; + +import com.dotcms.repackage.javax.ws.rs.core.MediaType; +import com.dotcms.repackage.javax.ws.rs.core.Response; +import com.dotmarketing.util.ConfigUtils; +import com.dotmarketing.util.json.JSONException; +import com.dotmarketing.util.json.JSONObject; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import static com.dotcms.util.CollectionsUtils.map; + +/** + * Created by Oscar Arrieta on 8/27/15. + * + * Class to abstract methods that will be used in Mapper Exception classes on dotCMS. + */ +public final class ExceptionMapperUtil { + + /** + * + * @param message error message to include in the JSON. + * @return string with the Json formed in this format: {error:message}. + */ + public static String getJsonErrorAsString(String message){ + + //Creating the message in JSON format. + String entity; + try { + JSONObject json = new JSONObject(); + json.put("error", message); + entity = json.toString(); + } catch (JSONException e) { + entity = "{ \"error\": \"" + message.replace("\"", "\\\"") + "\" }"; + } + return entity; + } + + /** + * + * @param entity JSON as String. + * @return Response with Status 400 and Media Type JSON. + */ + public static Response createResponse(String entity, String message){ + + //Return 4xx message to the client. + return Response + .status(Response.Status.BAD_REQUEST) + .entity(entity) + .header("error-message", message) + .type(MediaType.APPLICATION_JSON) + .build(); + } + + /*** + * Creates an response based on a status and exception + * @param exception {@link Exception} + * @param status {@link Response} + * @return Response + */ + public static Response createResponse(final Exception exception, final Response.Status status){ + //Create the message. + final String message = exception.getMessage(); + //Creating the message in JSON format. + if (ConfigUtils.isDevMode()) { + + final StringWriter errors = new StringWriter(); + exception.printStackTrace(new PrintWriter(errors)); + + return Response + .status(status) + .entity(map("message", message, + "stacktrace", errors)) + .header("error-message", message) + .build(); + } + + return Response + .status(status) + .entity(map("message", message)) + .header("error-message", message) + .build(); + } +} diff --git a/src/com/dotcms/util/PaginationUtil.java b/src/com/dotcms/util/PaginationUtil.java new file mode 100644 index 0000000..def43ae --- /dev/null +++ b/src/com/dotcms/util/PaginationUtil.java @@ -0,0 +1,272 @@ +package com.dotcms.util; + +import com.dotcms.repackage.javax.ws.rs.core.Response; +import com.dotcms.repackage.org.apache.commons.lang.StringUtils; +import com.dotcms.rest.ResponseEntityView; +import com.dotcms.util.pagination.OrderDirection; +import com.dotcms.util.pagination.Paginator; +import com.dotmarketing.common.util.SQLUtil; +import com.dotmarketing.util.Config; +import com.dotmarketing.util.UtilMethods; +import com.liferay.portal.model.User; +import com.liferay.util.StringUtil; + +import javax.servlet.http.HttpServletRequest; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; + +import static com.dotcms.util.CollectionsUtils.map; +import static com.dotmarketing.util.WebKeys.DOTCMS_PAGINATION_LINKS; +import static com.dotmarketing.util.WebKeys.DOTCMS_PAGINATION_ROWS; + +/** + * Utility class to the pagination elements and filter + * + * @author oswaldogallango + * + */ +public class PaginationUtil { + + public static final int FIRST_PAGE_INDEX = 1; + + public static final String FILTER = "filter"; + public static final String PAGE = "page"; + public static final String PER_PAGE = "per_page"; + public static final String ORDER_BY = "orderby"; + public static final String DIRECTION = "direction"; + + private static final String LINK_HEADER_NAME = "Link"; + private static final String PAGINATION_PER_PAGE_HEADER_NAME = "X-Pagination-Per-Page"; + private static final String PAGINATION_CURRENT_PAGE_HEADER_NAME = "X-Pagination-Current-Page"; + private static final String PAGINATION_MAX_LINK_PAGES_HEADER_NAME = "X-Pagination-Link-Pages"; + private static final String PAGINATION_TOTAL_ENTRIES_HEADER_NAME = "X-Pagination-Total-Entries"; + public static final String PAGE_VALUE_TEMPLATE = "pageValue"; + + private Paginator paginator; + + private static final String LINK_TEMPLATE = "<{URL}>;rel=\"{relValue}\""; + + private static final String FIRST_REL_VALUE = "first"; + private static final String LAST_REL_VALUE = "last"; + private static final String PREV_REL_VALUE = "prev"; + private static final String NEXT_REL_VALUE = "next"; + private static final String PAGE_REL_VALUE = "x-page"; + + private int perPageDefault; + private int nLinks; + + public PaginationUtil(Paginator paginator){ + this.paginator = paginator; + perPageDefault = Config.getIntProperty(DOTCMS_PAGINATION_ROWS, 10); + nLinks = Config.getIntProperty(DOTCMS_PAGINATION_LINKS, 5); + } + + /** + * Get the minimum pagination element index + * @param currentPage The current page + * @param perPage The max amount of element per page + * @return minimum pagination element index + */ + private int getMinIndex(int currentPage, int perPage){ + return (currentPage - 1) * perPage; + + } + + /** + * Get the maximum pagination element index + * @param currentPage The current page + * @param perPage The max amount of element per page + * @return maximum pagination element index + */ + private int getMaxIndex(int currentPage, int perPage){ + return perPage * currentPage; + } + + public Response getPage(final HttpServletRequest req, final User user, final String filter, final int pageParam, final int perPageParam) { + return getPage(req, user, filter, pageParam, perPageParam, StringUtils.EMPTY, (OrderDirection) null, null); + } + + public Response getPage(final HttpServletRequest req, final User user, final String filter, final int pageParam, + final int perPageParam, final String orderBy, final String direction) { + return getPage(req, user, filter, pageParam, perPageParam, orderBy, + OrderDirection.valueOf(direction), null); + } + + public Response getPage(final HttpServletRequest req, final User user, final String filter, final int pageParam, + final int perPageParam, final Map extraParams) { + return getPage(req, user, filter, pageParam, perPageParam, null, null, extraParams); + } + + /** + * Return a pagination's response + * + * @param req + * @param user Login User + * @param filter + * @param page Page to return + * @param perPage Number of items by page + * @param orderBy Field name to order by + * @param direction Order direction (ASC, DESC) + * @return + */ + public Response getPage(final HttpServletRequest req, final User user, final String filter, final int page, + final int perPage, final String orderBy, final OrderDirection direction, final Map extraParams) { + + final int pageValue = page == 0 ? FIRST_PAGE_INDEX : page; + final int perPageValue = perPage == 0 ? perPageDefault : perPage; + final int minIndex = getMinIndex(pageValue, perPageValue); + final String sanitizefilter = SQLUtil.sanitizeParameter(filter); + + Collection items = paginator.getItems(user, sanitizefilter, perPageValue, minIndex, orderBy, direction, extraParams); + items = !UtilMethods.isSet(items) ? Collections.emptyList() : items; + final long totalRecords = paginator.getTotalRecords(sanitizefilter); + final String linkHeaderValue = getHeaderValue(req.getRequestURL().toString(), sanitizefilter, pageValue, perPageValue, + totalRecords, orderBy, direction, extraParams); + + return Response. + ok(new ResponseEntityView(items)) + .header(LINK_HEADER_NAME, linkHeaderValue) + .header(PAGINATION_PER_PAGE_HEADER_NAME, perPageValue) + .header(PAGINATION_CURRENT_PAGE_HEADER_NAME, pageValue) + .header(PAGINATION_MAX_LINK_PAGES_HEADER_NAME, nLinks) + .header(PAGINATION_TOTAL_ENTRIES_HEADER_NAME, totalRecords) + .build(); + } + + + /** + * Return the valur for the Link header according tis RFC: + * + * https://tools.ietf.org/html/rfc5988#page-6 + * + * The sintax to build each URL is the follow: + * + * [urlBase]?filter=[filter]&page=[page]&perPage=[perPage]&archived=[showArchived]&direction=[direction]&orderBy=[orderBy] + * + * The real parameter could hve the follow values: next, prev, last, fisrt and x-page. + * + * For more information, you can see: + * + * https://developer.github.com/v3/#pagination + * + * @param urlBase + * @param filter + * @param page + * @param perPage + * @param totalRecords + * @param orderBy + * @param direction + * @return + */ + private static String getHeaderValue(final String urlBase, final String filter, final int page, final int perPage, + final long totalRecords, final String orderBy, final OrderDirection direction, + final Map extraParams) { + final List links = new ArrayList<>(); + + links.add(StringUtil.format(LINK_TEMPLATE, map( + "URL", getUrl(urlBase, filter, FIRST_PAGE_INDEX, perPage, orderBy, direction, extraParams), + "relValue", FIRST_REL_VALUE + ))); + + int lastPage = (int) (Math.ceil((double) totalRecords/perPage)); + links.add(StringUtil.format(LINK_TEMPLATE, map( + "URL", getUrl(urlBase, filter, lastPage, perPage, orderBy, direction, extraParams), + "relValue", LAST_REL_VALUE + ))); + + links.add(StringUtil.format(LINK_TEMPLATE, map( + "URL", getUrl(urlBase, filter, -1, perPage, orderBy, direction, extraParams), + "relValue", PAGE_REL_VALUE + ))); + + int next = page + 1; + if (next <= lastPage){ + links.add(StringUtil.format(LINK_TEMPLATE, map( + "URL", getUrl(urlBase, filter, next, perPage, orderBy, direction, extraParams), + "relValue", NEXT_REL_VALUE + ))); + } + + int prev = page - 1; + if (prev > 0){ + links.add(StringUtil.format(LINK_TEMPLATE, map( + "URL", getUrl(urlBase, filter, prev, perPage, orderBy, direction, extraParams), + "relValue", PREV_REL_VALUE + ))); + } + + return String.join(",", links); + } + + /** + * Build each URL for the Link header. + * The sintax to build each URL is the follow: + * + * [urlBase]?filter=[filter]&page=[page]&perPage=[perPage]&archived=[showArchived]&direction=[direction]&orderBy=[orderBy] + * + * @param urlBase + * @param filter + * @param page + * @param perPage + * @param orderBy + * @param direction + * @return + */ + private static String getUrl(final String urlBase, final String filter, final int page, final int perPage, + final String orderBy, final OrderDirection direction, final Map extraParams){ + + final Map params = new HashMap<>(); + + if (UtilMethods.isSet(filter)){ + params.put(FILTER, String.valueOf(filter)); + } + + params.put(PER_PAGE, String.valueOf(perPage)); + params.put (PAGE, (-1 != page) ? String.valueOf(page) : PAGE_VALUE_TEMPLATE); + + if (UtilMethods.isSet(direction)) { + params.put(DIRECTION, direction.toString()); + } + + if (UtilMethods.isSet(orderBy)) { + params.put(ORDER_BY, orderBy); + } + + if (extraParams != null) { + for (final Map.Entry extraParamsEntry : extraParams.entrySet()) { + final Object value = extraParamsEntry.getValue(); + + if (value != null) { + params.put(extraParamsEntry.getKey(), value.toString()); + } + } + } + + final StringBuilder buffer = new StringBuilder(urlBase); + + boolean firstParam = true; + + for (final Map.Entry paramsEntry : params.entrySet()) { + + if (firstParam){ + buffer.append('?'); + firstParam = false; + }else{ + buffer.append('&'); + } + + + try { + final String encode = URLEncoder.encode(paramsEntry.getValue(), "UTF-8"); + buffer.append(paramsEntry.getKey()) + .append('=') + .append(encode); + } catch (UnsupportedEncodingException e) { + continue; + } + } + + return buffer.toString(); + } +} \ No newline at end of file diff --git a/src/com/dotcms/util/pagination/OrderDirection.java b/src/com/dotcms/util/pagination/OrderDirection.java new file mode 100644 index 0000000..160bdcb --- /dev/null +++ b/src/com/dotcms/util/pagination/OrderDirection.java @@ -0,0 +1,9 @@ +package com.dotcms.util.pagination; + +/** + * It is the order for a pagination request + */ +public enum OrderDirection { + ASC, + DESC +} diff --git a/src/com/dotcms/util/pagination/Paginator.java b/src/com/dotcms/util/pagination/Paginator.java new file mode 100644 index 0000000..8884285 --- /dev/null +++ b/src/com/dotcms/util/pagination/Paginator.java @@ -0,0 +1,43 @@ +package com.dotcms.util.pagination; + +import com.liferay.portal.model.User; + +import java.util.Collection; +import java.util.Map; + +/** + * Define the methods to get handle a pagination request + */ +public interface Paginator { + + /** + * Return the number of items + * + * @param condition + * @return + */ + public abstract long getTotalRecords(String condition); + + /** + * Return a set of items for a page + * + * @param user user to filter + * @param filter extra filter parameter + * @param limit Number of items to return + * @param offset offset + * @param orderby field to order + * @param direction If the order is Asc or Desc + * @return + */ + public abstract Collection getItems(User user, String filter, int limit, int offset, + String orderby, OrderDirection direction, Map extraParams); + + default Collection getItems(User user, String filter, int limit, int offset){ + return getItems(user, filter, limit, offset, null, null); + } + + default Collection getItems(User user, String filter, int limit, int offset, String orderby, + OrderDirection direction){ + return getItems(user, filter, limit, offset, orderby, direction, null); + } +} diff --git a/src/com/dotmarketing/util/ConfigUtils.java b/src/com/dotmarketing/util/ConfigUtils.java new file mode 100644 index 0000000..d4f3e89 --- /dev/null +++ b/src/com/dotmarketing/util/ConfigUtils.java @@ -0,0 +1,170 @@ +package com.dotmarketing.util; + +import com.dotcms.enterprise.ClusterThreadProxy; +import com.dotmarketing.business.APILocator; + +import java.io.File; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.UUID; + +/** + * Generic class to get return configuration parameters, and any logic required + * for those paramenters. This is different from the Config class, which only + * reads from the config file. + * + * @author andres + * + */ +public class ConfigUtils { + + public static String getDynamicContentPath() { + String realPath = Config.getStringProperty("DYNAMIC_CONTENT_PATH"); + if (UtilMethods.isSet(realPath)) { + if (!realPath.endsWith(java.io.File.separator)) { + realPath = realPath + java.io.File.separator; + } + } else { + realPath = com.liferay.util.FileUtil.getRealPath("/dotsecure"); + } + return realPath; + + } + + public static String getDynamicVelocityPath() { + return getDynamicContentPath() + File.separator + "velocity" + + File.separator + "dynamic"; + } + + public static String getACheckerPath() { + return com.liferay.util.FileUtil.getRealPath("/WEB-INF/achecker_sql"); + } + + public static String getLucenePath() { + return getDynamicContentPath() + File.separator + "dotlucene"; + } + + public static String getBackupPath() { + return getDynamicContentPath() + File.separator + "backup"; + } + + public static String getBundlePath() { + String path=APILocator.getFileAPI().getRealAssetsRootPath() + File.separator + "bundles"; + File pathDir=new File(path); + if(!pathDir.exists()) + pathDir.mkdirs(); + return path; + } + + public static String getIntegrityPath() { + String path=APILocator.getFileAPI().getRealAssetsRootPath() + File.separator + "integrity"; + File pathDir=new File(path); + if(!pathDir.exists()) + pathDir.mkdirs(); + return path; + } + + public static String getTimeMachinePath(){ + + String path = Config.getStringProperty("TIMEMACHINE_PATH", null); + + if(path == null || (path != null && path.equals("null")) ){ + path=APILocator.getFileAPI().getRealAssetsRootPath() + File.separator + "timemachine"; + File pathDir=new File(path); + if(!pathDir.exists()) + pathDir.mkdirs(); + } + + return path; + } + + public static String getServerId(){ + String serverId; + if (Config.getStringProperty("DIST_INDEXATION_SERVER_ID")==null || Config.getStringProperty("DIST_INDEXATION_SERVER_ID").equalsIgnoreCase("")) { + serverId = APILocator.getServerAPI().readServerId(); + + if(!UtilMethods.isSet(serverId)) { + serverId = UUID.randomUUID().toString(); + + } + + Config.setProperty("DIST_INDEXATION_SERVER_ID", serverId); +// serverId=deduceHostName(); + } else { + serverId= Config.getStringProperty("DIST_INDEXATION_SERVER_ID"); + } + return serverId; + } + + private static String deduceHostName() { + String hostName=null; + try { + if (findServerId(java.net.InetAddress.getLocalHost().getHostName())) { + hostName=java.net.InetAddress.getLocalHost().getHostName() ; + } + } catch (UnknownHostException e) { + Logger.error(ConfigUtils.class, "Couldn't determine hostname: " + e.getMessage()); + } + if (hostName==null) { + Logger.info(ConfigUtils.class, "Trying to find hostname by examining network interfaces"); + Enumeration en=null; + try { + en=NetworkInterface.getNetworkInterfaces(); + + } catch (SocketException e) { + Logger.error(ConfigUtils.class, "Error getting interfaces: " + e.getMessage()); + } + if (en!=null) { + while (en.hasMoreElements() && hostName==null ) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress address= enumIpAddr.nextElement(); + Logger.info(ConfigUtils.class, "Getting hostname for: " +address ); + String interfaceName=address.getHostName(); + if (findServerId(interfaceName)) { + hostName=interfaceName; + } + + } + } + } + } + if (hostName==null) { + Logger.fatal(ConfigUtils.class, "No valid hostname found. Make sure your correct host name is defined in DIST_INDEXATION_SERVERS_IDS in dotmarketing-config.properties."); + } else { + Logger.info(ConfigUtils.class, "Deduced hostname: " + hostName); + } + return hostName; + } + + private static boolean findServerId(String id) { + if (id!=null) { + for (String s: ClusterThreadProxy.getClusteredServerIds()) { + if (s.equalsIgnoreCase(id)) { + return true; + } + } + } + return false; + } + + /* + * This property determine if the app is running on dev mode. + */ + public static final String DEV_MODE_KEY = "dotcms.dev.mode"; + + /** + * Returns true if app is running on dev mode. + * @return boolean + */ + public static boolean isDevMode () { + + // by default if the vars does not exists, we assume is not + // running on dev mode, so it is false. + return Config.getBooleanProperty(DEV_MODE_KEY, false); + } + +} diff --git a/src/com/dotmarketing/util/WebKeys.java b/src/com/dotmarketing/util/WebKeys.java new file mode 100644 index 0000000..33f7c86 --- /dev/null +++ b/src/com/dotmarketing/util/WebKeys.java @@ -0,0 +1,710 @@ +package com.dotmarketing.util; + +import com.dotmarketing.business.PermissionCache; + +/** + * This class provides a centralized access point to the keys of several system + * parameters that are set via the configuration files in dotCMS. The + * configuration properties for many system features can be located in this + * class. + * + * @author Will Ezel + * @version 1.0 + * @since Mar 22, 2012 + */ +public final class WebKeys { + + //Generated File Indicator + public static final String GENERATED_FILE ="dotGenerated_"; + public static final String RENDITION_FILE ="dotRendition_"; + public static final String EDITED_IMAGE_FILE_ASSET ="_dotfileAsset"; + public static final String IMAGE_TOOL_CLIPBOARD = "_imageToolClipboard"; + public static final String IMAGE_TOOL_SAVE_FILES = "_imageToolSaveFile"; + public static final String LONG_LIVED_DOTCMS_ID_COOKIE = "dmid"; + public static final String ONCE_PER_VISIT_COOKIE = "opvc"; + public static final String SITE_VISITS_COOKIE = "sitevisitscookie"; + + public static final String DIRECTOR_URL = "com.dotmarketing.preview.DirectorURL"; + public static final String VIEW_FOLDERS_URL = "com.dotmarketing.preview.ViewFolderURL"; + public static final String VIEW_BROWSER_URL = "com.dotmarketing.preview.ViewBrowserURL"; + public static final String PREVIEW_PAGE_URL = "com.dotmarketing.preview.PreviewPageURL"; + public static final String VIEW_CONTENTS_URL = "com.dotmarketing.preview.ViewContentsURL"; + + public static final String CART = "com.dotmarketing.cms.cart.cart"; + public static final String INODES_VIEW_PORTLET = "com.dotmarketing.inodes.view.portlet"; + public static final String INODES_VIEW = "com.dotmarketing.inodes.view"; + public static final String INODES_EDIT = "com.dotmarketing.inodes.edit"; + public static final String INODE_EDIT = "com.dotmarketing.inodes.edit"; + + public static final String JOBS_LIST = "com.dotmarketing.jobs.view.portlet"; + public static final String JOB_EDIT = "com.dotmarketing.jobs.edit_job"; + public static final String RESUMES_LIST = "com.dotmarketing.jobs.resumes.view"; + public static final String RESUME_EDIT = "com.dotmarketing.jobs.resume.edit"; + public static final String SEARCHFIRMS_LIST = "com.dotmarketing.jobs.searchfirms.view"; + public static final String SEARCHFIRM_EDIT = "com.dotmarketing.jobs.searchfirm.edit"; + + public static final String BANNER_VIEW_PORTLET = "com.dotmarketing.banner.view.portlet"; + public static final String BANNERS_VIEW = "com.dotmarketing.banners.view"; + public static final String BANNER_EDIT = "com.dotmarketing.banners.edit"; + public static final String BANNER_FORM_EDIT = "com.dotmarketing.banners.formedit"; + + public static final String FILE_EDIT = "com.dotmarketing.files.edit"; + public static final String FILE_VIEW = "com.dotmarketing.files.view"; + public static final String FILE_FORM_EDIT = "com.dotmarketing.files.form"; + public static final String FILE_VERSIONS = "com.dotmarketing.files.versions"; + public static final String FILES_VIEW = "com.dotmarketing.files.view"; + public static final String FILES_VIEW_COUNT = "com.dotmarketing.files.view.count"; + public static final String FILE_RELATED_ASSETS = "com.dotmarketing.file.related.assets"; + public static final String FILE_TITLE = "com.dotmarketing.file.title"; + public static final String FILE_MIME = "com.dotmarketing.file.mime"; + public static final String FILE_NAME = "com.dotmarketing.file.name"; + public static final String FILE_DESCRIPTION = "com.dotmarketing.file.description"; + public static final String FILE_QUERY = "com.dotmarketing.file.query"; + public static final String FILE_SHOW_DELETED = "com.dotmarketing.file.show_deleted"; + public static final String FILE_HOST_CHANGED = "com.dotmarketing.file.host_changed"; + public static final String TEMP_FILE_PREFIX = "_temp_"; + + public static final String REPORTS_VIEW = "com.dotmarketing.files.view"; + public static final String REPORTS_VIEW_COUNT = "com.dotmarketing.files.view.count"; + public static final String REPORTS_QUERY = "com.dotmarketing.file.query"; + public static final String REPORTS_SHOW_DELETED = "com.dotmarketing.file.show_deleted"; + + public static final String CATEGORY_VIEW_PORTLET = "com.dotmarketing.categories.view.portlet"; + public static final String CATEGORY_VIEW = "com.dotmarketing.categories.view"; + public static final String CATEGORY_EDIT = "com.dotmarketing.categories.edit"; + public static final String CATEGORY_LIST_TOP = "com.dotmarketing.categories.top_list"; + public static final String CATEGORY_LIST_ORPHAN = "com.dotmarketing.categories.orphan_list"; + + public static final String ENTITY_VIEW_PORTLET = "com.dotmarketing.entity.view.portlet"; + public static final String ENTITY_VIEW = "com.dotmarketing.entity.view"; + public static final String ENTITY_EDIT = "com.dotmarketing.entity.edit"; + public static final String ENTITY_FORM_EDIT = "com.dotmarketing.entity.formedit"; + + public static final String NEWSLETTER_VIEW_PORTLET = "com.dotmarketing.newsletter.view.portlet"; + public static final String NEWSLETTER_VIEW = "com.dotmarketing.newsletter.view"; + public static final String NEWSLETTER_EDIT = "com.dotmarketing.newsletter.edit"; + public static final String NEWSLETTER_FORM_EDIT = "com.dotmarketing.newsletter.formedit"; + + public static final String STORY_LIST = "com.dotmarketing.story.list"; + + public static final String CONTENTLET_LIST = "com.dotmarketing.contentlet.list"; + public static final String CONTENTLETS_VIEW = "com.dotmarketing.contentlet.view"; + public static final String CONTENTLETS_VIEW_COUNT = "com.dotmarketing.contentlet.view.count"; + public static final String CONTENTLET_VIEW_PORTLET = "com.dotmarketing.contentlet.view.portlet"; + public static final String CONTENTLET_EDIT = "com.dotmarketing.contentlet.edit"; + public static final String CONTENTLET_RELATIONSHIPS_EDIT = "com.dotmarketing.contentlet.relationships.edit"; + public static final String CONTENTLET_SIBBLING_EDIT = "com.dotmarketing.contentlet.edit.sibbling"; + public static final String CONTENTLET_FORM_EDIT = "com.dotmarketing.contentlet.formedit"; + public static final String CONTENTLET_PARENT = "com.dotmarketing.contentlet.parent"; + public static final String CONTENTLET_VERSIONS = "com.dotmarketing.contentlet.versions"; + public static final String CONTENTLET_MAIN_IMAGE = "com.dotmarketing.contentlet.main_image"; + public static final String CONTENTLET_MAIN_LINK = "com.dotmarketing.contentlet.main_link"; + public static final String CONTENTLET_TITLE = "com.dotmarketing.contentlet.title"; + public static final String CONTENTLET_START_DATE = "com.dotmarketing.contentlet.startDate"; + public static final String CONTENTLET_END_DATE = "com.dotmarketing.contentlet.endDate"; + public static final String CONTENTLET_SUBTITLE = "com.dotmarketing.contentlet.subTitle"; + public static final String CONTENTLET_BODY = "com.dotmarketing.contentlet.body"; + public static final String CONTENTLET_AUTHOR = "com.dotmarketing.contentlet.author"; + public static final String CONTENTLET_SUMMARY = "com.dotmarketing.contentlet.summary"; + public static final String CONTENTLET_SUBSUBTITLE = "com.dotmarketing.contentlet.subsubtitle"; + public static final String CONTENTLET_RELATED_ASSETS = "com.dotmarketing.contentlet.related.assets"; + public static final String CONTENTLET_QUERY = "com.dotmarketing.contentlet.query"; + public static final String CONTENTLET_SHOW_DELETED = "com.dotmarketing.contentlet.show_deleted"; + public static final String CONTENTLET_LAST_SEARCH = "com.dotmarketing.contentlet.last_search"; + //http://jira.dotmarketing.net/browse/DOTCMS-2273 + public static final String CONTENTLET_FORM_NAME_VALUE_SEPARATOR = "com.dotmarketing.contentlet.form_name_value_separator"; + + public static final String SECTIONS_LIST = "com.dotmarketing.section.list"; + public static final String COURSES_LIST = "com.dotmarketing.courses.list"; + public static final String COURSE = "com.dotmarketing.course"; + public static final String PACKAGES_LIST = "com.dotmarketing.packages.list"; + public static final String PACKAGE = "com.dotmarketing.package"; + public static final String COURSE_SECTIONS = "com.dotmarketing.course_sections"; + public static final String COURSE_DEPARTMENTS= "com.dotmarketing.course_departments"; + public static final String DEPARTMENT= "com.dotmarketing.department"; + public static final String DEPARTMENTS= "com.dotmarketing.departments"; + public static final String FOLDER_VIEW_PORTLET = "com.dotmarketing.folder.view.portlet"; + public static final String FOLDERS_VIEW = "com.dotmarketing.folder.view"; + public static final String FOLDER_EDIT = "com.dotmarketing.folder.edit"; + public static final String FOLDER_FORM_EDIT = "com.dotmarketing.folder.formedit"; + public static final String ROOTFOLDER_VIEW_PORTLET = "com.dotmarketing.folder.rootfolder.portlet"; + public static final String FOLDER_PARENT = "com.dotmarketing.folder.parent.folder"; + public static final String HOST_PARENT = "com.dotmarketing.folder.parent.host"; + + public static final String FOLDER_ENTRY_LIST = "com.dotmarketing.folder.entry_list"; + public static final String FOLDER_SELECTED = "com.dotmarketing.folder.selected"; + public static final String FOLDER_THUMBNAIL_LIST = "com.dotmarketing.folder.thumbnail_list"; + public static final String FOLDER_THUMBS = "com.dotmarketing.folder.thumbs"; + public static final String FOLDER_OPEN_NODES = "com.dotmarketing.folder.open_nodes"; + public static final String FOLDER_RELATED_ASSETS = "com.dotmarketing.folder.related_assets"; + public static final String FOLDER_SHOWMENU = "com.dotmarketing.folder.show_menu"; + public static final String HOST_EDIT = "com.dotmarketing.host.edit"; + + ////EXCEPTIONS + public static final String EDIT_ASSET_EXCEPTION = "com.dotmarketing.webasset.edit.exception"; + public static final String GET_LIVE_ASSET_EXCEPTION = "com.dotmarketing.webasset.get.live.exception"; + public static final String USER_PERMISSIONS_EXCEPTION = "com.dotmarketing.webasset.user.permissions.exception"; + + public static final String FILEUPLOAD_EDIT = "com.dotmarketing.fileupload.edit"; + public static final String FILEUPLOAD_VIEW = "com.dotmarketing.fileupload.view"; + + // Permissions tab keys + public static final String PERMISSIONABLE_EDIT = "com.dotmarketing.permissions.permissionable_edit"; + public static final String PERMISSIONABLE_EDIT_BASE = "com.dotmarketing.permissions.permissionable_edit_base"; + + //Version tab keys + public static final String VERSIONS_INODE_EDIT = "com.dotmarketing.webassets.asset_versions"; + + public static final String PARENT_FOLDER = "com.dotmarketing.webasset.parent_folder"; + + public static final String CONTAINER_EDIT = "com.dotmarketing.containers.edit"; + public static final String CONTAINERS_VIEW = "com.dotmarketing.containers.view"; + public static final String CONTAINERS_VIEW_COUNT = "com.dotmarketing.containers.view.count"; + public static final String CONTAINER_VIEW_PORTLET = "com.dotmarketing.containers.view.portlet"; + public static final String CONTAINER_FORM_EDIT = "com.dotmarketing.containers.form"; + public static final String CONTAINER_VERSIONS = "com.dotmarketing.containers.versions"; + public static final String CONTAINER_PARENT = "com.dotmarketing.container.parent"; + public static final String CONTAINER_RELATED_ASSETS = "com.dotmarketing.containers.related.assets"; + public static final String CONTAINER_QUERY = "com.dotmarketing.container.query"; + public static final String CONTAINER_SHOW_DELETED = "com.dotmarketing.container.show_deleted"; + public static final String CONTAINER_HOST_CHANGED = "com.dotmarketing.container.host_changed"; + public static final String CONTAINER_INODE = "com.dotmarketing.containers.inode"; + public static final String CONTAINER_CAN_ADD = "com.dotmarketing.container.can.add.container"; + public static final String CONTAINER_HOSTS = "com.dotmarketing.container.hosts"; + + public static final String TEMPLATE_EDIT = "com.dotmarketing.templates.edit"; + public static final String TEMPLATES_VIEW = "com.dotmarketing.templates.view"; + public static final String TEMPLATES_VIEW_COUNT = "com.dotmarketing.templates.view.count"; + public static final String TEMPLATE_VIEW_PORTLET = "com.dotmarketing.templates.view.portlet"; + public static final String TEMPLATE_FORM_EDIT = "com.dotmarketing.templates.form"; + public static final String TEMPLATE_VERSIONS = "com.dotmarketing.templates.versions"; + public static final String TEMPLATE_PARENT = "com.dotmarketing.templates.parent"; + public static final String TEMPLATE_PREVIEW_PAGE = "com.dotmarketing.templates.preview.page"; + public static final String TEMPLATE_RELATED_ASSETS = "com.dotmarketing.templates.related.assets"; + public static final String TEMPLATE_QUERY = "com.dotmarketing.template.query"; + public static final String TEMPLATE_SHOW_DELETED = "com.dotmarketing.template.show_deleted"; + public static final String TEMPLATE_HOST_CHANGED = "com.dotmarketing.template.host_changed"; + public static final String TEMPLATE_CAN_ADD = "com.dotmarketing.template.can.add.template"; + + // *********************** BEGIN GRAZIANO issue-12-dnd-template + public static final String TEMPLATE_CAN_DESIGN = "com.dotmarketing.template.can.design.template"; + public static final String TEMPLATE_IS_DRAWED = "com.dotmarketing.template.can.design.template._drawed"; + public static final String OVERRIDE_DRAWED_TEMPLATE_BODY = "com.dotmarketing.template.can.design.template._drawedOverride"; + public static final String TEMPLATE_JAVASCRIPT_PARAMETERS = "com.dotmarketing.template.can.design.template._jsParameters"; + public static final String FILE_PATH_SQL_TEMPLATE_DESIGN = "path.sql.file.design.template"; + public static final String PREVIEW_TEMPLATE_DESIGN_ENABLE = "PREVIEW_ENABLE"; + // *********************** END GRAZIANO issue-12-dnd-template + + public static final String TEMPLATE_HOSTS = "com.dotmarketing.template.hosts"; + + public static final String HTMLPAGE_EDIT = "com.dotmarketing.htmlpages.edit"; + public static final String HTMLPAGE_REFERER = "com.dotmarketing.htmlpages.referer"; + public static final String HTMLPAGES_VIEW = "com.dotmarketing.htmlpages.view"; + public static final String HTMLPAGES_VIEW_COUNT = "com.dotmarketing.htmlpages.view.count"; + public static final String HTMLPAGE_VIEW_PORTLET = "com.dotmarketing.htmlpages.view.portlet"; + public static final String HTMLPAGE_FORM_EDIT = "com.dotmarketing.htmlpages.form"; + public static final String HTMLPAGE_VERSIONS = "com.dotmarketing.htmlpages.versions"; + public static final String HTMLPAGE_PREVIEW_PAGE = "com.dotmarketing.htmlpages.preview.page"; + public static final String HTML_CONTENTCONTAINERS = "com.dotmarketing.htmlpages.contentcontainers"; + public static final String HTMLPAGE_PARENT = "com.dotmarketing.htmlpages.parent"; + public static final String HTMLPAGE_RELATED_ASSETS = "com.dotmarketing.htmlpages.related.assets"; + public static final String HTMLPAGE_RELATED_WORKFLOWS = "com.dotmarketing.htmlpages.related.workflows"; + public static final String HTMLPAGE_QUERY = "com.dotmarketing.htmlpage.query"; + public static final String HTMLPAGE_SHOW_DELETED = "com.dotmarketing.htmlpage.show_deleted"; + public static final String HTMLPAGE_HOST_CHANGED = "com.dotmarketing.htmlpage.host_changed"; + public static final String HTMLPAGE_INODE = "com.dotmarketing.htmlpage.inode"; + public static final String REDIRECT_PREVIEW_PAGE = "com.dotmarketing.htmlpage.redirect.preview"; + public static final String HTMLPAGE_LANGUAGE = "com.dotmarketing.htmlpage.language"; + public static final String CONTENT_SELECTED_LANGUAGE = "com.dotmarketing.content.selected.language"; + public static final String Globals_FRONTEND_LOCALE_KEY = "com.dotmarketing.frontend.locale"; + + public static final String HTMLPAGE_ID = "pageId"; + public static final String HTMLPAGE_TITLE = "pageTitle"; + public static final String HTMLPAGE_META = "pageMeta"; + public static final String HTMLPAGE_SERVER_NAME = "serverName"; + + public static final String HTMLPAGE_SECURE = "com.dotmarketing.htmlpage.secure"; + public static final String HTMLPAGE_REDIRECT = "com.dotmarketing.htmlpage.redirect"; + + public static final String MAILING_LIST_VIEW_PORTLET = "com.dotmarketing.mailinglist.view.portlet"; + public static final String MAILING_LIST_VIEW = "com.dotmarketing.mailinglist.view"; + public static final String MAILING_LIST_EDIT = "com.dotmarketing.mailinglist.edit"; + public static final String MAILING_LIST_SUBSCRIBERS = "com.dotmarketing.mailinglist.subscribers"; + public static final String COMMUNICATION_LIST_VIEW = "com.dotmarketing.communicationlist.view"; + + public static final String MAILING_LIST_SYSTEM = "System Account"; + + public static final String FILE_EDIT_TEXT = "com.dotmarketing.portlets.file.edit.text"; + public static final String FILE_EDIT_TEXT_FILE_EXT = "com.dotmarketing.portlets.file.edit.text.file.ext"; + + public static final String COPY_CONTENTLET_UNIQUE_HAS_VALIDATION = "Unique Has Validation"; + public static final String COPY_CONTENTLET_UNIQUE_NOT_TEXT = "Unique Not Text"; + + //Links + public static final String LINK_EDIT = "com.dotmarketing.links.edit"; + public static final String LINK_FORM_EDIT = "com.dotmarketing.links.form"; + public static final String LINK_VERSIONS = "com.dotmarketing.links.versions"; + public static final String LINKS_VIEW = "com.dotmarketing.links.linksview"; + public static final String LINKS_VIEW_COUNT = "com.dotmarketing.links.linksview.count"; + public static final String LINK_VIEW_PORTLET = "com.dotmarketing.links.portlet"; + public static final String LINK_RELATED_ASSETS = "com.dotmarketing.links.related.assets"; + public static final String LINK_QUERY = "com.dotmarketing.link.query"; + public static final String LINK_SHOW_DELETED = "com.dotmarketing.link.show_deleted"; + public static final String LINK_HOST_CHANGED = "com.dotmarketing.link.host_changed"; + + // COOKIES + public static final String PREVIEW_MODE_COOKIE = "PREVIEW_MODE_COOKIE"; + public static final String PREPRECESS_RUN = "PREPRECESS_RUN_NUMBER"; + public static final String ADMIN_MODE_COOKIE = "ADMIN_MODE_COOKIE"; + + // SESSION ATTRIBUTES + public static final String EDIT_MODE_SESSION = "com.dotmarketing.EDIT_MODE_SESSION"; + public static final String PREVIEW_MODE_SESSION = "com.dotmarketing.PREVIEW_MODE_SESSION"; + public static final String ADMIN_MODE_SESSION = "com.dotmarketing.ADMIN_MODE_SESSION"; + public static final String SESSION_RATING_CACHE = "com.dotmarketing.beans.Rating"; + public static final String LAST_RATED_CONTENTLET = "last.rated.contentlet"; + public static final String CMSFILTER_REDIRECTING = "com.dotmarketing.filters.CMSFilter"; + public static final String CMSFILTER_URI = "com.dotmarketing.filters.CMSFilter.URI"; + public static final String PENDING_ALERT_SEEN = "PENDING_ALERT_SEEN"; + public static final String LOCALE = "com.dotmarketing.LOCALE"; + + // NON_LOGGED_IN_USER_CATS + public static final String NON_LOGGED_IN_USER_CATS = "com.dotmarketing.NON_LOGGED_IN_USER_CATS"; + public static final String LOGGED_IN_USER_CATS = "com.dotmarketing.LOGGED_IN_USER_CATS"; + + // NON_LOGGED_IN_USER_TAGS + public static final String NON_LOGGED_IN_USER_TAGS = "com.dotmarketing.NON_LOGGED_IN_USER_TAGS"; + public static final String LOGGED_IN_USER_TAGS = "com.dotmarketing.LOGGED_IN_USER_TAGS"; + + //MENU + public static final String MENU_OPEN = "com.dotmarketing.filters.MenuBuilder.open"; + public static final String MENU_PATH = "com.dotmarketing.filters.MenuBuilder.path"; + public static final String MENU_ITEMS = "com.dotmarketing.filters.MenuBuilder.items"; + public static final String MENU_MAIN_FOLDER = "com.dotmarketing.filters.MenuBuilder.main_folder"; + + public static final String DIRECTORIES_LIST = "com.dotmarketing.servicesdirectory.list"; + public static final String DIRECTORY_EDIT = "com.dotmarketing.servicesdirectory.edit"; + + //SHOPPING + public static final String SHOPPING_C_A_ADDORDERNOTEACTION = "com.dotmarketing.portlets.shopping.c.a.AddOrderNoteAction"; + public static final String SHOPPING_C_A_BROWSECATEGORIESACTION = "com.dotmarketing.portlets.shopping.c.a.BrowseCategoriesAction"; + public static final String SHOPPING_C_A_CHANGEORDERACTION = "com.dotmarketing.portlets.shopping.c.a.ChangeOrderAction"; + public static final String SHOPPING_C_A_DELETECATEGORYACTION = "com.dotmarketing.portlets.shopping.c.a.DeleteCategoryAction"; + public static final String SHOPPING_C_A_DELETEITEMACTION = "com.dotmarketing.portlets.shopping.c.a.DeleteItemAction"; + public static final String SHOPPING_C_A_DELETEORDERACTION = "com.dotmarketing.portlets.shopping.c.a.DeleteOrderAction"; + public static final String SHOPPING_C_A_DELETEORDERNOTEACTION = "com.dotmarketing.portlets.shopping.c.a.DeleteOrderNoteAction"; + public static final String SHOPPING_C_A_EDITCATEGORYACTION = "com.dotmarketing.portlets.shopping.c.a.EditCategoryAction"; + public static final String SHOPPING_C_A_EDITITEMACTION = "com.dotmarketing.portlets.shopping.c.a.EditItemAction"; + public static final String SHOPPING_C_A_EDITLATESTORDERACTION = "com.dotmarketing.portlets.shopping.c.a.EditLatestOrderAction"; + public static final String SHOPPING_C_A_EDITORDERACTION = "com.dotmarketing.portlets.shopping.c.a.EditOrderAction"; + public static final String SHOPPING_C_A_FORWARDCHECKOUTACTION = "com.dotmarketing.portlets.shopping.c.a.ForwardCheckoutAction"; + public static final String SHOPPING_C_A_PAYPALNOTIFICATIONACTION = "com.dotmarketing.portlets.shopping.c.a.PayPalNotificationAction"; + public static final String SHOPPING_C_A_QUICKADDITEMSACTION = "com.dotmarketing.portlets.shopping.c.a.QuickAddItemsAction"; + public static final String SHOPPING_C_A_SAVELATESTORDERACTION ="com.dotmarketing.portlets.shopping.c.a.SaveLatestOrderAction"; + public static final String SHOPPING_C_A_SEARCHACTION = "com.dotmarketing.portlets.shopping.c.a.SearchAction"; + public static final String SHOPPING_C_A_SENDORDEREMAILACTION ="com.dotmarketing.portlets.shopping.c.a.SendOrderEmailAction"; + public static final String SHOPPING_C_A_SENDSHIPPINGEMAILACTION = "com.dotmarketing.portlets.shopping.c.a.SendShippingEmailAction"; + public static final String SHOPPING_C_A_UPDATECARTACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateCartAction"; + public static final String SHOPPING_C_A_UPDATECATEGORYACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateCategoryAction"; + public static final String SHOPPING_C_A_UPDATEITEMACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateItemAction"; + public static final String SHOPPING_C_A_UPDATELATESTORDERACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateLatestOrderAction"; + public static final String SHOPPING_C_A_UPDATEORDERACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateOrderAction"; + public static final String SHOPPING_C_A_UPDATEPREFERENCEACTION = "com.dotmarketing.portlets.shopping.c.a.UpdatePreferenceAction"; + public static final String SHOPPING_C_A_UPDATESHOPPINGCONFIGACTION = "com.dotmarketing.portlets.shopping.c.a.UpdateShoppingConfigAction"; + public static final String SHOPPING_C_H_CARTHANDLER = "com.dotmarketing.portlets.shopping.c.h.CartHandler"; + public static final String SHOPPING_URL = "com.dotmarketing.portlets.shopping.URL"; + public static final String SHOPPING_C_A_HOMEACTION = "com.dotmarketing.portlets.shopping.c.a.ExtranetAction"; + + //Polls + public static final String POLLS_C_A_ADDVOTEACTION = "com.dotmarketing.portlets.polls.c.a.AddVoteAction"; + public static final String POLLS_C_A_DELETEQUESTIONACTION = "com.dotmarketing.portlets.polls.c.a.DeleteQuestionAction"; + public static final String POLLS_C_A_EDITQUESTIONACTION = "com.dotmarketing.portlets.polls.c.a.EditQuestionAction"; + public static final String POLLS_C_A_UPDATEQUESTIONACTION = "com.dotmarketing.portlets.polls.c.a.UpdateQuestionAction"; + public static final String POLLS_C_A_VIEWCHARTACTION = "com.dotmarketing.portlets.polls.c.a.ViewChartAction"; + public static final String POLLS_C_A_VIEWQUESTIONSACTION = "com.dotmarketing.portlets.polls.c.a.ViewQuestionsAction"; + public static final String POLLS_C_A_VIEWCURRENTQUESTIONSACTION = "com.dotmarketing.portlets.polls.c.a.ViewCurrentQuestionsAction"; + public static final String POLLS_CATID = "com.dotmarketing.portlets.polls.catid"; + public static final String POLLS_C_A_DELETECHOICEACTION = "com.dotmarketing.portlets.polls.c.a.DeleteChoiceAction"; + public static final String POLLS_C_A_EDITCHOICEACTION = "com.dotmarketing.portlets.polls.c.a.EditChoiceAction"; + public static final String POLLS_C_A_UPDATECHOICEACTION = "com.dotmarketing.portlets.polls.c.a.UpdateChoiceAction"; + public static final String POLLS_CHOICE = "com.dotmarketing.portlets.polls.choice"; + public static final String POLLS_C_A_REORDERCHOICESACTION = "com.dotmarketing.portlets.polls.c.a.ReorderChoicesAction"; + + //Newsletter + public static final String CAMPAIGN_LIST = "com.dotmarketing.campaign.list"; + public static final String CAMPAIGN_RECURRENT_OCURRENCES = "com.dotmarketing.campaign.recurrent.ocurrences"; + public static final String CAMPAIGN_EDIT = "com.dotmarketing.campaign.edit"; + public static final String CLICK_EDIT = "com.dotmarketing.click.edit"; + public static final String RECIPIENT_LIST = "com.dotmarketing.recipient.list"; + public static final String RECIPIENT_LIST_TITLE = "com.dotmarketing.recipient.list.title"; + public static final String RECIPIENT_EDIT = "com.dotmarketing.recipient.edit"; + + // WORKFLOWS + public static final String WORKFLOW_TASK_EDIT = "com.dotmarketing.workflowtask.edit"; + public static final String WORKFLOW_TASK_FORM_EDIT = "com.dotmarketing.workflowtask.edit_form"; + public static final String WORKFLOW_TASKS_LIST = "com.dotmarketing.workflowtasks.list"; + public static final String WORKFLOW_USER_TASKS_LIST = "com.dotmarketing.workflowtasks.user.list"; + public static final String WORKFLOW_FILTER_TASKS_LIST = "com.dotmarketing.workflowtasks.filter.list"; + public static final String WORKFLOW_FILTER_TASKS_COUNT = "com.dotmarketing.workflowtasks.filter.count"; + public static final String WORKFLOW_ACTIONLET_CLASSES = "WORKFLOW_ACTIONLET_CLASSES"; + public static final String WORKFLOW_SEARCHER = "com.dotmarketing.workflowtasks.WORKFLOW_SEARCHER"; + public static enum WorkflowStatuses { OPEN, RESOLVED, CANCELLED }; + + // RULES ENGIGE + public static final String RULES_CONDITIONLET_CLASSES = "RULES_CONDITIONLET_CLASSES"; + public static final String RULES_ACTIONLET_CLASSES = "RULES_ACTIONLET_CLASSES"; + public static final String RULES_CONDITIONLET_VISITEDURLS = "RULES_CONDITIONLET_VISITEDURLS"; + public static final String RULES_ENGINE_PARAM = "dotRules"; + public static final String RULES_ENGINE_FIRE_LIST = "dotRulesFired"; + + //ADMIN CONTROL + public static final String ADMIN_CONTROL_TOP = "com.dotmarketing.admin.control.top"; + public static final String ADMIN_CONTROL_LEFT = "com.dotmarketing.admin.control.left"; + public static final String ADMIN_CONTROL_CLOSED = "com.dotmarketing.admin.control.closed"; + + //TASK CONTROL + public static final String TASK_CONTROL_TOP = "com.dotmarketing.task.control.top"; + public static final String TASK_CONTROL_LEFT = "com.dotmarketing.task.control.left"; + public static final String TASK_CONTROL_CLOSED = "com.dotmarketing.task.control.closed"; + + //USER PREFERENCES + public static final String USER_PREFERENCE_EDIT = "com.dotmarketing.portlets.user.edit_userpreference"; + public static final String USER_PREFERENCE_HOME_PAGE = "com.dotmarketing.user.home_page"; + + //USER COMMENTS + public static final String USER_COMMENTS_VIEW = "com.dotmarketing.portlets.usercomments.view_user_comments"; + + //USER CLICKS + public static final String USER_CLICKS_VIEW = "com.dotmarketing.portlets.userclicks.view_user_clicks"; + + //USER FILTERS + public static final String USER_FILTER_LIST_VIEW_PORTLET = "com.dotmarketing.userfilter.view.portlet"; + public static final String USER_FILTER_LIST_VIEW = "com.dotmarketing.userfilter.view"; + public static final String USER_FILTER_LIST_TITLE = "com.dotmarketing.userfilter.title"; + public static final String USER_FILTER_LIST_INODE = "com.dotmarketing.userfilter.inode"; + + //DIRECTOR VARIABLES FOR PORTLET URL + public static final String JAVAX_PORTLET_REQUEST = "com.dotmarketing.javax.portlet.request"; + public static final String JAVAX_PORTLET_CONFIG = "com.dotmarketing.javax.portlet.config"; + public static final String LAYOUT = "com.dotmarketing.LAYOUT"; + public static final String SESSION_MESSAGES = "com.dotmarketing.session.messages"; + + //LANGUAGE MANAGER + public static final String LANGUAGE_MANAGER_LIST = "com.dotmarketing.languagemanager.view.portlet"; + public static final String LANGUAGE_MANAGER_PROPERTIES = "com.dotmarketing.languagemanager.properties"; + public static final String LANGUAGE_MANAGER_SEARCH= "com.dotmarketing.languagemanager.properties.search"; + public static final String LANGUAGE_MANAGER_PAGE_NUMBERS= "com.dotmarketing.languagemanager.properties.page_numbers"; + public static final String LANGUAGE_MANAGER_ADDEDKEY= "com.dotmarketing.languagemanager.properties.addedkey"; + public static final String LANGUAGE_MANAGER_LANGUAGE= "com.dotmarketing.languagemanager.language"; + public static final String LANGUAGE_MANAGER_LANGUAGE_FORM= "com.dotmarketing.languagemanager.language_form"; + public static final String LANGUAGES = "com.dotmarketing.languages.languages_list"; + public static final String LANGUAGE = "com.dotmarketing.languages.language_selected"; + public static final String LANGUAGE_SEARCHED = "com.dotmarketing.languages.language_searched"; + + public static final String CRUMB_TRAIL = "com.dotmarketing.viewtool.crumbtrail"; + public static final String REDIRECT_AFTER_LOGIN = "REDIRECT_AFTER_LOGIN"; + + // CMS USER LOGIN + public static final String CMS_USER = "cms.user"; + public static final String CMS_PERSONALIZATION_BEAN = "cms.user.personalization"; + public static final String CMS_USER_REGISTRATIONS = "cms.user.registrations"; + public static final String CMS_CURRENT_PAGE = "cms.current.page"; + + public static final String CLICKSTREAM_URI_OVERRIDE = "com.dotmarketing.clickstream.uri.override"; + public static final String CLICKSTREAM_IDENTIFIER_OVERRIDE = "com.dotmarketing.clickstream.identifier.override"; + + //REGISTRATIONS MANAGER + public static final String REGISTRATION_VIEW_PORTLET = "com.dotmarketing.registration.view.portlet"; + public static final String REGISTRATION_VIEW = "com.dotmarketing.registration.view"; + public static final String REGISTRATION_USERS = "com.dotmarketing.registration.users"; + public static final String REGISTRATION_VIEW_COUNT = "com.dotmarketing.registration.view.count"; + public static final String REGISTRATION_EDIT = "com.dotmarketing.registration.edit"; + public static final String REGISTRATION_FORM_EDIT = "com.dotmarketing.registration.formedit"; + + //Marketing list builder + public static final String MAILINGLIST = "com.dotmarketing.mailinglistbuilder.mailing_list"; + public static final String MAILINGLISTFORM = "com.dotmarketing.mailinglistbuilder.mailing_list_form"; + + //EVENTS + public static final String EVENTS_LIST = "com.dotmarketing.event.list"; + public static final String EVENT_EDIT = "com.dotmarketing.event.edit"; + public static final String EVENT_RECURRENCE_EDIT = "com.dotmarketing.event_recurrence.edit"; + public static final String EVENT_FORM = "com.dotmarketing.event.form"; + public static final String EVENT_CATEGORIES = "com.dotmarketing.event.categories"; + public static final String RECURANCE_EDIT = "com.dotmarketing.recurance.edit"; + public static final String EVENT_REGISTRATIONS = "com.dotmarketing.event.registrations"; + + //Hosts + public static final String CURRENT_HOST = "com.dotmarketing.session_host"; + public static final String SEARCH_HOST_ID = "com.dotmarketing.search_host_id"; + public static final String HOST_SHOW_DELETED = "com.dotmarketing.host.show_deleted"; + + //Structure + public static final String SEARCH_STRUCTURE_ID = "com.dotmarketing.search_structure_id"; + public static final String STRUCTURES_VIEW = "com.dotmarketing.structures.view"; + public static final String STRUCTURE_QUERY = "com.dotmarketing.structures.query"; + public static final String STRUCTURES_VIEW_COUNT = "com.dotmarketing.structures.view.count"; + + //Structure + public static final String SEARCH_TEMPLATE_ID = "com.dotmarketing.search_template_id"; + + //FACILITIES + public static final String FACILITIES_LIST = "com.dotmarketing.facilities.list"; + public static final String FACILITY_EDIT = "com.dotmarketing.facility.edit"; + + //Organizations + public static final String ORGANIZATION_VIEW = "com.dotmarketing.portlets.organization.model.Organization.view"; + public static final String ORGANIZATION_EDIT = "com.dotmarketing.portlets.organization.model.Organization.edit"; + + //User Manage + public static final String USERMANAGER_EDIT_FORM = "com.dotmarketing.portlets.usermanager.edit"; + public static final String USERMANAGERLISTFORM= "com.dotmarketing.portlets.usermanager.listForm"; + public static final String USERMANAGERLIST= "com.dotmarketing.portlets.usermanager.list"; + public static final String USERMANAGERLISTCOUNT = "com.dotmarketing.portlets.usermanager.listcount"; + public static final String USERMANAGERLISTPARAMETERS = "com.dotmarketing.portlets.usermanager.lastSearchParameters"; + public static final String USERMANAGER_PROPERTIES = "com.dotmarketing.portlets.usermanager.properties"; + + // WORKFLOW MESSAGES + public static final String WORKFLOW_MESSAGE_EDIT = "com.dotmarketing.workflowmessages.edit"; + public static final String WORKFLOW_MESSAGE_FORM_EDIT = "com.dotmarketing.workflowmessages.edit_form"; + public static final String WORKFLOW_MESSAGE_LIST = "com.dotmarketing.workflowmessages.list"; + public static final String WORKFLOW_MESSAGE_VIEW_PORTLET = "com.dotmarketing.workflowmessages.view.portlet"; + public static final String WORKFLOW_MESSAGE_VERSIONS = "com.dotmarketing.workflowmessages.versions"; + public static final String WORKFLOW_MESSAGE_SHOW_DELETED = "com.dotmarketing.workflowmessages.show.deleted"; + public static final String WORKFLOW_MESSAGE_ORDER_BY = "com.dotmarketing.workflowmessages.order.by"; + public static final String WORKFLOW_MESSAGE_ORDER_BY_DIRECTION = "com.dotmarketing.workflowmessages.order.by.direction"; + public static final String WORKFLOW_MESSAGE_STATUS_ID = "com.dotmarketing.workflowmessages.status_id"; + public static final String WORKFLOW_MESSAGE_QUERY = "com.dotmarketing.workflowmessages.query"; + public static final String WORKFLOW_MESSAGES_VIEW = "com.dotmarketing.workflowmessages.view"; + + // USER FAVORITES + public static final String USER_FAVORITES = "com.dotmarketing.user_favorites"; + + //PRODUCT MANAGER + //BACK END + public static final String PRODUCT_PRODUCTS_TYPE = "ProductTypes"; + public static final String PRODUCT_CATEGORIES = "Ecommerce"; + public static final String PRODUCT_PRODUCT = "product"; + public static final String PRODUCT_PRODUCT_FORMAT = "productFormat"; + public static final String PRODUCT_PRODUCT_PRICE = "productPrice"; + public static final String PRODUCT_SMALL_IMAGE = "smallImage"; + public static final String PRODUCT_MEDIUM_IMAGE = "mediumImage"; + public static final String PRODUCT_LARGE_IMAGE = "largeImage"; + public static final String PRODUCT_FILES = "files"; + public static final String PRODUCT_RELATED = "relatedProduct"; + + //FRONT END + public static final String SHOPPING_CART = "shoppingCart"; + public static final String SHOPPING_CART_ORDER_FORM = "shoppingCartOrderForm"; + public static final String SHOPPING_CART_FORMAT_INODE = "shoppingCartFormatInode"; + public static final String SHOPPING_CART_FORMAT_QUANTITY = "shoppingCartFormatQuantity"; + public static final String SHOPPING_CART_ERRORS = "shoppingCartErrors"; + + //Event Registration Manager + public static final String WEBEVENTS_REG_VIEW = "com.dotmarketing.webevents.registration.view"; + public static final String WEBEVENTS_REG_EDIT = "com.dotmarketing.webevents.registration.edit"; + public static final String WEBEVENTS_REG_FORM = "com.dotmarketing.webevents.registration.form"; + public static final String WEBEVENT_REG_ATTENDEES = "com.dotmarketing.webevents..registration.attendees"; + public static final String WEBEVENTS_REG_USER = "com.dotmarketing.webevents.registration.user"; + public static final String WEBEVENTS_REG_USERID = "com.dotmarketing.webevents.registration.userid"; + public static final String WEBEVENTS_REG_ATTENDEE_EDIT = "com.dotmarketing.webevents.registration.attendee.edit"; + public static final String WEBEVENTS_REG_ATTENDEE_FORM = "com.dotmarketing.webevents.registration.attendee.form"; + public static final String WEBEVENTS_REG_STATUSES = "com.dotmarketing.webevents.registration.statuses"; + public static final String WEBEVENTS_REG_BEAN = "com.dotmarketing.webevents.registration.bean"; + public static final String WEBEVENTS_REG_ERRORS = "com.dotmarketing.webevents.registration.errors"; + + //Order Manager + public static final String ORDER_MGR_VIEW = "com.dotmarketing.order_manager.view"; + public static final String ORDER_MGR_EDIT = "com.dotmarketing.order_manager.edit"; + public static final String ORDER_MGR_FORM = "com.dotmarketing.order_manager.form"; + public static final String ORDER_MGR_ITEMS = "com.dotmarketing.order_manager.items"; + public static final String ORDER_MGR_ITEM_EDIT = "com.dotmarketing.order_manager.item.edit"; + public static final String ORDER_MGR_ITEM_FORM = "com.dotmarketing.order_manager.item.form"; + public static final String ORDER_MGR_STATUSES = "com.dotmarketing.order_manager.statuses"; + public static final String ORDER_MGR_PAY_STATUSES = "com.dotmarketing.order_manager.pay.statuses"; + + //DISCOUNT CODE + public static final String DISCOUNTCODE_DISCOUNTS = "discounts"; + public static final String DISCOUNTCODE_ORDER_BY = "orderby"; + public static final String DISCOUNTCODE_DIRECTION = "direction"; + public static final String DISCOUNTCODE_PERCENTAGE = "1"; + public static final String DISCOUNTCODE_DISCOUNT = "2"; + public static final String DISCOUNTCODE_PRODUCT_FORMAT = "productFormat"; + //END DISCOUNT CODE + + public static final String WEBEVENTS_VIEW = "com.dotmarketing.webevents.view"; + public static final String WEBEVENTS_EDIT = "com.dotmarketing.webevents.edit"; + public static final String WEBEVENTS_FORM = "com.dotmarketing.webevents.form"; + public static final String WEBEVENT_CATEGORIES = "com.dotmarketing.webevents.categories"; + public static final String WEBEVENT_LOCATIONS = "com.dotmarketing.webevents.locations"; + public static final String WEBEVENTS_LOCATION_EDIT = "com.dotmarketing.webevents.location.edit"; + public static final String WEBEVENTS_LOCATION_FORM = "com.dotmarketing.webevents.location.form"; + + //ORGANIZATION + public static final String ORGANIZATION_OBJECT = "com.dotmarketing.organization.object"; + public static final String REDIRECT_AFTER_UPDATE_ACCOUNT_INFO = "REDIRECT_AFTER_UPDATE_ACCOUNT_INFO"; + + //SCHEDULER + public static final String SCHEDULER_VIEW_PORTLET = "com.dotmarketing.scheduler.view.portlet"; + public static final String SCHEDULER_LIST_VIEW = "com.dotmarketing.scheduler.view"; + public static final String UNIQUE_SCHEDULER_EXCEPTION = "com.dotmarketing.scheduler.unique.exception"; + + //REPORTS + public static final String REPORT_EDIT = "com.dotmarketing.report.edit"; + + //WIki + public static final String WIKI_CONTENTLET = "com.dotmarketing.wiki.contentlet"; + public static final String WIKI_CONTENTLET_INODE = "com.dotmarketing.wiki.contentlet.inode"; + public static final String WIKI_IN_WIKI = "com.dotmarketing.wiki.in.wiki"; + public static final String WIKI_CONTENTLET_URL = "com.dotmarketing.wiki.contentlet.url"; + + //VISITOR + public static final String VISITOR = "com.dotcms.visitor"; + + public static class Cache + { + public static final String CACHE_BANNER_CACHE = "com.dotmarketing.cache.BannerCache"; + public static final String CACHE_HOST_CACHE = "com.dotmarketing.cache.HostCache"; + public static final String CACHE_IDENTIFIER_CACHE = "com.dotmarketing.cache.IdentifierCache"; + public static final String CACHE_LIVE_CACHE = "com.dotmarketing.cache.LiveCache"; + public static final String CACHE_PAGE_NOT_FOUND_CACHE = "com.dotmarketing.cache.PageNotFoundCache"; + public static final String CACHE_PERMISSION_CACHE = PermissionCache.class.getName(); + + public static final String CACHE_ALL_CACHES = "CACHE_ALL_CACHES"; + public static final String CACHE_WORKING_FILES = "CACHE_WORKING_FILES"; + public static final String CACHE_LIVE_FILES = "CACHE_LIVE_FILES"; + public static final String CACHE_NUMBER_LIVE_FILES = "CACHE_NUMBER_LIVE_FILES"; + public static final String CACHE_NUMBER_WORKING_FILES = "CACHE_WORKING_LIVE_FILES"; + public static final String CACHE_CONTENTS_INDEX = "CACHE_CONTENTS_INDEX"; + public static final String CACHE_OPTIMIZE_INDEX = "CACHE_OPTIMIZE_INDEX"; + public static final String CACHE_MENU_FILES = "CACHE_MENUS_CACHE"; + public static final String CACHE_NOT_FOUND = "_NOT_FOUND_"; + } + + public static class Structure + { + public static final String STRUCTURES = "STRUCTURES"; + public static final String STRUCTURE = "STRUCTURE"; + public static final String REORDER = "REORDER"; + public static final String SET_DEFAULT = "SET_DEFAULT"; + public static final String STRUCTURE_ENTITY = "structure_entity"; + public static final String STRUCTURE_TYPE = "Structure Type"; + public static final String STRUCTURE_EDIT_TYPE = "structure_edit_type"; + public static final String ENTRIES_NUMBER = "entries_number"; + } + + public static class Relationship + { + public static final String RELATIONSHIP_EDIT = "com.dotmarketing.relationships.edit_relationship"; + public static final String RELATIONSHIP_REQUIRED = "com.dotmarketing.relationships.required"; + public static enum RELATIONSHIP_CARDINALITY { ONE_TO_MANY , MANY_TO_MANY }; + public static final String RELATIONSHIPS = "RELATIONSHIPS"; + public static final String STRUCTURES_LIST = "STRUCTURES_LIST"; + } + + public static class Field + { + public static final String FIELDS = "FIELDS"; + public static final String FIELD = "FIELD"; + } + + public static class FatContentlet + { + public static final String CONTENTLET = "contentlet"; + } + + public static class DateFormats + { + public static final String SHORTDATE = "dd/MM/yyyy"; + public static final String DBDATE = "yyyy-MM-dd"; + public static final String LONGDBDATE = "yyyy-MM-dd hh:mm:ss"; + + public static final String EXP_IMP_DATE = "MM/dd/yyyy"; + public static final String EXP_IMP_DATETIME = "MM/dd/yyyy hh:mm aa"; + public static final String EXP_IMP_TIME = "hh:mm aa"; + + public static final String DOTSCHEDULER_DATE = "yyyy-MM-dd hh:mm:ss a"; + public static final String DOTSCHEDULER_DATE2 = "yyyy-MM-dd HH:mm:ss"; + } + + public static class Report + { + public static final String ReportList = "reportList"; + } + + //COMMUNICATION + public static final String COMMUNICATIONS_LIST = "com.dotmarketing.communications.list"; + public static final String COMMUNICATION_EDIT = "com.dotmarketing.communications.edit"; + public static final String COMMUNICATION_EDIT_FORM = "com.dotmarketing.communications.editForm"; + public static final String COMMUNICATION_EDIT_FORM_PERMISSION = "com.dotmarketing.communications.editForm.permission"; + + //WebFormsMailExcel + public static final String WEBFORMS_MAIL_EXCEL_FROM_ADDRESS = "WEBFORMS_MAIL_EXCEL_FROM_ADDRESS"; + public static final String WEBFORMS_MAIL_EXCEL_FROM_NAME = "WEBFORMS_MAIL_EXCEL_FROM_NAME"; + public static final String WEBFORMS_MAIL_EXCEL_FROM_SUBJECT = "WEBFORMS_MAIL_EXCEL_FROM_SUBJECT"; + public static final String WEBFORMS_MAIL_EXCEL_GROUP_NAME = "WEBFORMS_MAIL_EXCEL_GROUP_NAME"; + public static final String WEBFORMS_MAIL_EXCEL_WEBFORM_TYPE = "WEBFORMS_MAIL_EXCEL_WEBFORM_TYPE"; + + //JCaptcha + public static final String SESSION_JCAPTCHA_SOUND_SERVICE = "DOTCMS_SESSION_JCAPTCHA_SOUND_SERVICE"; + + //CMS SUB NAV VARIABLES + public static final String CMS_SELECTED_HOST_ID = "CMS_SELECTED_HOST_ID"; + public static final String CMS_CRUMBTRAIL_OPTIONS = "CMS_CRUMBTRAIL_OPTIONS"; + public static final String DONT_DISPLAY_SUBNAV_ALL_HOSTS = "DONT_DISPLAY_SUBNAV_ALL_HOSTS"; + public static final String LOCK_SUBNAV_TO_ALL_HOST = "LOCK_SUBNAV_TO_ALL_HOST"; + + public static final String SELECTED_ENVIRONMENTS = "SELECTED_ENVIRONMENTS"; + public static final String SELECTED_BUNDLE = "SELECTED_BUNDLE"; + + public static final String CONTENT_EDITABLE = "CONTENT_EDITABLE"; + + // SYS Monitor + public static final String USER_SESSIONS = "USER_SESSIONS"; + + // ACE Text Editor + public static final String TEXT_EDITOR = "textEditor"; + public static final String VELOCITY = "velocity"; + + // Personas + public static final String CMS_PERSONA_PARAMETER= "com.dotmarketing.persona.id"; + + public static final String OSGI_ENABLED="felix.osgi.enabled"; + + public static final String DOTCMS_STARTED_UP="dotcms.started.up"; + public static final String DOTCMS_STARTUP_TIME="dotcms.startup.ms"; + public static final String DOTCMS_STARTUP_TIME_CACHE="dotcms.startup.cache.ms"; + public static final String DOTCMS_STARTUP_TIME_DB="dotcms.startup.db.ms"; + public static final String DOTCMS_STARTUP_TIME_ES="dotcms.startup.es.ms"; + public static final String DOTCMS_STARTUP_TIME_HAZEL="dotcms.startup.hazel.ms"; + public static final String DOTCMS_STARTUP_TIME_QUARTZ="dotcms.startup.quartz.ms"; + public static final String DOTCMS_STARTUP_TIME_OSGI="dotcms.startup.osgi.ms"; + + // Websocket configuration parameters + public static final String DOTCMS_WEBSOCKET_PROTOCOL = "dotcms.websocket.protocol"; + public static final String DOTCMS_WEBSOCKET_BASEURL = "dotcms.websocket.baseurl"; + public static final String DOTCMS_WEBSOCKET_ENDPOINTS = "dotcms.websocket.endpoints"; + public static final String DOTCMS_WEBSOCKET_TIME_TO_WAIT_TO_RECONNECT = "dotcms.websocket.reconnect.time"; + public static final String DOTCMS_DISABLE_WEBSOCKET_PROTOCOL = "dotcms.websocket.disable"; + + // System Events + public static final String WEBSOCKET_SYSTEMEVENTS_ENDPOINT = "websocket.systemevents.endpoint"; + + // System Security + public static final String AUTH_FAILED_ATTEMPTS_DELAY_STRATEGY_ENABLED = "auth.failedattempts.delay.enabled"; + public static final String AUTH_FAILED_ATTEMPTS_DELAY_STRATEGY = "auth.failedattempts.delay.strategy"; + + // Cache Transport + public static final String DOTCMS_CACHE_TRANSPORT_BIND_ADDRESS = "dotcms.cache.transport.bind.address"; + public static final String DOTCMS_CACHE_TRANSPORT_BIND_PORT = "dotcms.cache.transport.bind.port"; + public static final String DOTCMS_CACHE_TRANSPORT_TCP_INITIAL_HOSTS = "dotcms.cache.transport.tcp.initial.hosts"; + public static final String DOTCMS_CACHE_TRANSPORT_UDP_MCAST_ADDRESS = "dotcms.cache.transport.udp.mcast.address"; + public static final String DOTCMS_CACHE_TRANSPORT_UDP_MCAST_PORT = "dotcms.cache.transport.udp.mcast.port"; + + //Pagination Parameters + public static final String DOTCMS_PAGINATION_ROWS = "dotcms.paginator.rows"; + public static final String DOTCMS_PAGINATION_LINKS = "dotcms.paginator.links"; + + //User validations + public static final String DOTCMS_USE_REGEX_TO_VALIDATE_EMAILS = "dotcms.use.regex.to.validate.emails"; +} diff --git a/src/com/liferay/util/StringUtil.java b/src/com/liferay/util/StringUtil.java new file mode 100644 index 0000000..3fe2fc2 --- /dev/null +++ b/src/com/liferay/util/StringUtil.java @@ -0,0 +1,672 @@ +/** + * Copyright (c) 2000-2005 Liferay, LLC. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.liferay.util; + +import com.dotmarketing.util.Logger; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * View Source + * + * @author Brian Wing Shun Chan + * @version $Revision: 1.21 $ + * + */ +public class StringUtil { + + public static String add(String s, String add) { + return add(s, add, StringPool.COMMA); + } + + public static String add(String s, String add, String delimiter) { + return add(s, add, delimiter, false); + } + + public static String add( + String s, String add, String delimiter, boolean allowDuplicates) { + + if ((add == null) || (delimiter == null)) { + return null; + } + + if (s == null) { + s = StringPool.BLANK; + } + + if (allowDuplicates || !contains(s, add, delimiter)) { + if (Validator.isNull(s) || s.endsWith(delimiter)) { + s += add + delimiter; + } + else { + s += delimiter + add + delimiter; + } + } + + return s; + } + + public static boolean contains(String s, String text) { + return contains(s, text, StringPool.COMMA); + } + + public static boolean contains(String s, String text, String delimiter) { + if ((s == null) || (text == null) || (delimiter == null)) { + return false; + } + + if (!s.endsWith(delimiter)) { + s += delimiter; + } + + int pos = s.indexOf(delimiter + text + delimiter); + + if (pos == -1) { + if (s.startsWith(text + delimiter)) { + return true; + } + + return false; + } + + return true; + } + + public static int count(String s, String text) { + if ((s == null) || (text == null)) { + return 0; + } + + int count = 0; + + int pos = s.indexOf(text); + + while (pos != -1) { + pos = s.indexOf(text, pos + text.length()); + count++; + } + + return count; + } + + public static boolean endsWith(String s, char end) { + return startsWith(s, (new Character(end)).toString()); + } + + public static boolean endsWith(String s, String end) { + if ((s == null) || (end == null)) { + return false; + } + + if (end.length() > s.length()) { + return false; + } + + String temp = s.substring(s.length() - end.length(), s.length()); + + if (temp.equalsIgnoreCase(end)) { + return true; + } + else { + return false; + } + } + + public static String extractChars(String s) { + if (s == null) { + return ""; + } + + char[] c = s.toCharArray(); + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < c.length; i++) { + if (Validator.isChar(c[i])) { + sb.append(c[i]); + } + } + + return sb.toString(); + } + + public static String extractDigits(String s) { + if (s == null) { + return ""; + } + + char[] c = s.toCharArray(); + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < c.length; i++) { + if (Validator.isDigit(c[i])) { + sb.append(c[i]); + } + } + + return sb.toString(); + } + + public static String merge(String array[]) { + return merge(array, StringPool.COMMA); + } + + public static String merge(String array[], String delimiter) { + if (array == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < array.length; i++) { + sb.append(array[i].trim()); + + if ((i + 1) != array.length) { + sb.append(delimiter); + } + } + + return sb.toString(); + } + + public static String randomize(String s) { + Randomizer r = new Randomizer(); + + return r.randomize(s); + } + + public static String read(ClassLoader classLoader, String name) + throws IOException { + InputStream is=classLoader.getResourceAsStream(name); + if (is==null) { + File f=new File(FileUtil.getRealPath("/WEB-INF/"+name)); + is=new FileInputStream(f); + } + + return read(is); + } + + public static String read(InputStream is) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + + StringBuilder sb = new StringBuilder(); + String line = null; + + while ((line = br.readLine()) != null) { + sb.append(line).append('\n'); + } + + br.close(); + + return sb.toString().trim(); + } + + public static String remove(String s, String remove) { + return remove(s, remove, StringPool.COMMA); + } + + public static String remove(String s, String remove, String delimiter) { + if ((s == null) || (remove == null) || (delimiter == null)) { + return null; + } + + if (Validator.isNotNull(s) && !s.endsWith(delimiter)) { + s += delimiter; + } + + while (contains(s, remove, delimiter)) { + int pos = s.indexOf(delimiter + remove + delimiter); + + if (pos == -1) { + if (s.startsWith(remove + delimiter)) { + s = s.substring( + remove.length() + delimiter.length(), s.length()); + } + } + else { + s = s.substring(0, pos) + s.substring(pos + remove.length() + + delimiter.length(), s.length()); + } + } + + return s; + } + + public static String replace(String s, char oldSub, char newSub) { + return replace(s, oldSub, new Character(newSub).toString()); + } + + public static String replace(String s, char oldSub, String newSub) { + if ((s == null) || (newSub == null)) { + return null; + } + + char[] c = s.toCharArray(); + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < c.length; i++) { + if (c[i] == oldSub) { + sb.append(newSub); + } + else { + sb.append(c[i]); + } + } + + return sb.toString(); + } + + public static String replace(String s, String oldSub, String newSub) { + if ((s == null) || (oldSub == null) || (newSub == null)) { + return null; + } + + int y = s.indexOf(oldSub); + + if (y >= 0) { + StringBuilder sb = new StringBuilder(); + int length = oldSub.length(); + int x = 0; + + while (x <= y) { + sb.append(s.substring(x, y)); + sb.append(newSub); + x = y + length; + y = s.indexOf(oldSub, x); + } + + sb.append(s.substring(x)); + + return sb.toString(); + } + else { + return s; + } + } + + public static String replace(String s, String[] oldSubs, String[] newSubs) { + if ((s == null) || (oldSubs == null) || (newSubs == null)) { + return null; + } + + if (oldSubs.length != newSubs.length) { + return s; + } + + for (int i = 0; i < oldSubs.length; i++) { + s = replace(s, oldSubs[i], newSubs[i]); + } + + return s; + } + + public static String reverse(String s) { + if (s == null) { + return null; + } + + char[] c = s.toCharArray(); + char[] reverse = new char[c.length]; + + for (int i = 0; i < c.length; i++) { + reverse[i] = c[c.length - i - 1]; + } + + return new String(reverse); + } + + public static String shorten(String s) { + return shorten(s, 20); + } + + public static String shorten(String s, int length) { + return shorten(s, length, ".."); + } + + public static String shorten(String s, String suffix) { + return shorten(s, 20, suffix); + } + + public static String shorten(String s, int length, String suffix) { + if (s == null || suffix == null) { + return null; + } + + if (s.length() > length) { + s = s.substring(0, length) + suffix; + } + + return s; + } + + public static String[] split(String s) { + return split(s, StringPool.COMMA); + } + + public static String[] split(String s, String delimiter) { + if (s == null || delimiter == null) { + return new String[0]; + } + + s = s.trim(); + + if (!s.endsWith(delimiter)) { + s += delimiter; + } + + if (s.equals(delimiter)) { + return new String[0]; + } + + List nodeValues = new ArrayList(); + + if (delimiter.equals("\n") || delimiter.equals("\r")) { + try { + BufferedReader br = new BufferedReader(new StringReader(s)); + + String line = null; + + while ((line = br.readLine()) != null) { + nodeValues.add(line); + } + + br.close(); + } + catch (IOException ioe) { + Logger.error(StringUtil.class,ioe.getMessage(),ioe); + } + } + else { + int offset = 0; + int pos = s.indexOf(delimiter, offset); + + while (pos != -1) { + nodeValues.add(s.substring(offset, pos)); + + offset = pos + delimiter.length(); + pos = s.indexOf(delimiter, offset); + } + } + + return (String[])nodeValues.toArray(new String[0]); + } + + public static boolean[] split(String s, String delimiter, boolean x) { + String[] array = split(s, delimiter); + boolean[] newArray = new boolean[array.length]; + + for (int i = 0; i < array.length; i++) { + boolean value = x; + + try { + value = Boolean.valueOf(array[i]).booleanValue(); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static double[] split(String s, String delimiter, double x) { + String[] array = split(s, delimiter); + double[] newArray = new double[array.length]; + + for (int i = 0; i < array.length; i++) { + double value = x; + + try { + value = Double.parseDouble(array[i]); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static float[] split(String s, String delimiter, float x) { + String[] array = split(s, delimiter); + float[] newArray = new float[array.length]; + + for (int i = 0; i < array.length; i++) { + float value = x; + + try { + value = Float.parseFloat(array[i]); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static int[] split(String s, String delimiter, int x) { + String[] array = split(s, delimiter); + int[] newArray = new int[array.length]; + + for (int i = 0; i < array.length; i++) { + int value = x; + + try { + value = Integer.parseInt(array[i]); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static long[] split(String s, String delimiter, long x) { + String[] array = split(s, delimiter); + long[] newArray = new long[array.length]; + + for (int i = 0; i < array.length; i++) { + long value = x; + + try { + value = Long.parseLong(array[i]); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static short[] split(String s, String delimiter, short x) { + String[] array = split(s, delimiter); + short[] newArray = new short[array.length]; + + for (int i = 0; i < array.length; i++) { + short value = x; + + try { + value = Short.parseShort(array[i]); + } + catch (Exception e) { + } + + newArray[i] = value; + } + + return newArray; + } + + public static final String stackTrace(Throwable t) { + String s = null; + + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + t.printStackTrace(new PrintWriter(baos, true)); + s = baos.toString(); + } + catch (Exception e) { + } + + return s; + } + + public static boolean startsWith(String s, char begin) { + return startsWith(s, (new Character(begin)).toString()); + } + + public static boolean startsWith(String s, String start) { + if ((s == null) || (start == null)) { + return false; + } + + if (start.length() > s.length()) { + return false; + } + + String temp = s.substring(0, start.length()); + + if (temp.equalsIgnoreCase(start)) { + return true; + } + else { + return false; + } + } + + public static String trimLeading(String s) { + for (int i = 0; i < s.length(); i++) { + if (!Character.isWhitespace(s.charAt(i))) { + return s.substring(i, s.length()); + } + } + + return StringPool.BLANK; + } + + public static String trimTrailing(String s) { + for (int i = s.length() - 1; i >= 0; i--) { + if (!Character.isWhitespace(s.charAt(i))) { + return s.substring(0, i + 1); + } + } + + return StringPool.BLANK; + } + + public static String wrap(String text) { + return wrap(text, 80, "\n"); + } + + public static String wrap(String text, int width, String lineSeparator) { + if (text == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + + try { + BufferedReader br = new BufferedReader(new StringReader(text)); + + String s = StringPool.BLANK; + + while ((s = br.readLine()) != null) { + if (s.length() == 0) { + sb.append(lineSeparator); + } + else { + String[] tokens = s.split(StringPool.SPACE); + boolean firstWord = true; + int curLineLength = 0; + + for (int i = 0; i < tokens.length; i++) { + if (!firstWord) { + sb.append(StringPool.SPACE); + curLineLength++; + } + + if (firstWord) { + sb.append(lineSeparator); + } + + sb.append(tokens[i]); + + curLineLength += tokens[i].length(); + + if (curLineLength >= width) { + firstWord = true; + curLineLength = 0; + } + else { + firstWord = false; + } + } + } + } + } + catch (IOException ioe) { + Logger.error(StringUtil.class,ioe.getMessage(),ioe); + } + + return sb.toString(); + } + + /** + * Format a String template with name, for example: + * + * String template = "Hello word {name}"; + * String format = StringUtil.format(teamplat, map("name", "Freddy")); + * System.out.println(format); + * + * + * The output is: Hello Wordl Freddy + * + * @param template + * @param params + * @return + */ + public static String format (String template, final Map params){ + String result = template; + + for (Map.Entry entry : params.entrySet()) { + String key = String.format("\\{%s\\}", entry.getKey()); + result = result.replaceAll(key, entry.getValue()); + } + + return result; + } + +} \ No newline at end of file diff --git a/static_files/saml/view_saml_configuration.jsp b/static_files/saml/view_saml_configuration.jsp new file mode 100644 index 0000000..7185a7d --- /dev/null +++ b/static_files/saml/view_saml_configuration.jsp @@ -0,0 +1,219 @@ +<%@page import="com.dotmarketing.beans.Host"%> +<%@ page import="com.dotmarketing.business.APILocator" %> +<%@page import="com.liferay.portal.language.LanguageUtil"%> +<%@page import="java.util.List"%> + + + +
+ +
+
+ + +
+
+ +
+
+ + + + + + + + + + + + + + +
<%=LanguageUtil.get(pageContext, "status")%><%=LanguageUtil.get(pageContext, "idp-name")%><%=LanguageUtil.get(pageContext, "Actions")%><%=LanguageUtil.get(pageContext, "sp-metadata-file")%>
+ + +
+
+ +
+
+ <%=LanguageUtil.get(pageContext, "Viewing-Results-From")%> +
+
+ +
+
+ +
+ +
" style="display: none; width:600px"> +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ + +
+ +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ <% + List allHosts = APILocator.getHostAPI().findAll(APILocator.getUserAPI().getSystemUser(),true); + %> + + + + +
+
+
+ + + + + + + + + + + + + + +
<%=LanguageUtil.get(pageContext, "site")%><%=LanguageUtil.get(pageContext, "id")%><%=LanguageUtil.get(pageContext, "Actions")%>
+
+
+
+ +
+
+
+
+ +
" style="display: none; width:600px"> +
+
+
+
+
+
+
+ <% + allHosts = APILocator.getHostAPI().findAll(APILocator.getUserAPI().getSystemUser(),true); + %> + + + + +
+
+
+ + + + + + + + + + + +
<%=LanguageUtil.get(pageContext, "site")%><%=LanguageUtil.get(pageContext, "id")%><%=LanguageUtil.get(pageContext, "Actions")%>
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/static_files/saml/view_saml_configuration_js_inc.jsp b/static_files/saml/view_saml_configuration_js_inc.jsp new file mode 100644 index 0000000..505149d --- /dev/null +++ b/static_files/saml/view_saml_configuration_js_inc.jsp @@ -0,0 +1,474 @@ +<%@page import="com.liferay.portal.language.LanguageUtil"%> +<%@page import="com.dotmarketing.util.UtilMethods"%> +<%response.setContentType("text/JavaScript");%> + + require(["dojo/ready"], function(ready){ + ready(function(){ + idpAdmin.renderIdpConfigs(); + }); + }); + + function saveIdp() { + + if (document.getElementById ("addEditIdPForm").checkValidity()) { + + var addEditIdPForm = dojo.byId("addEditIdPForm"); + var formData = new FormData(addEditIdPForm); + + formData.append("signatureValidationType", dijit.byId("signatureValidationType").value); + + var jsonData = {}; + + for (var key of mySitesMap.keys()) { + var siteId = key; + var siteName = mySitesMap.get(key); + + jsonData[siteId] = siteName; + } + + formData.append("sites", JSON.stringify(jsonData)); + + var xhrArgs = { + url: "/api/v1/dotsaml/idp", + headers: { "Content-Type": false }, + postData: formData, + handleAs: "json", + load: function (data) { + dijit.byId('addEditIdPDialog').hide(); + idpAdmin.renderIdpConfigs(); + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrPost(xhrArgs); + } else { + document.getElementById ("addEditIdPForm").reportValidity(); + } + + } + + function saveDisabledSites() { + var formData = new FormData(); + var jsonData = {}; + + for (var key of myDisabledSitesMap.keys()) { + var siteId = key; + var siteName = myDisabledSitesMap.get(key); + + jsonData[siteId] = siteName; + } + + formData.append("disabledsites", JSON.stringify(jsonData)); + + var xhrArgs = { + url: "/api/v1/dotsaml/disabledsites", + headers: { "Content-Type": false }, + postData: formData, + handleAs: "json", + load: function (data) { + dijit.byId('disableSamlSiteDialog').hide(); + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrPost(xhrArgs); + } + + function setDefaultIdpConfig(id) { + xhrArgs = { + url: "/api/v1/dotsaml/default/" + id, + handleAs: "json", + load: function () { + idpAdmin.renderIdpConfigs(); + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrPut(xhrArgs); + } + + function getDefaultIdpConfig(){ + var defaultIdp = ""; + + xhrArgs = { + url: "/api/v1/dotsaml/default", + sync: true, + handleAs: "json", + load: function (data) { + idp = data.entity; + if(idp && idp.defaultSamlConfig){ + defaultIdp = idp.defaultSamlConfig; + } + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + } + deferred = dojo.xhrGet(xhrArgs); + + return defaultIdp; + } + + function deleteIdpConfig(id) { + xhrArgs = { + url: "/api/v1/dotsaml/idp/" + id, + handleAs: "json", + load: function () { + idpAdmin.renderIdpConfigs(); + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrDelete(xhrArgs); + } + + function getDisabledSites() { + xhrArgs = { + url: "/api/v1/dotsaml/disabledsites/", + handleAs: "json", + load: function (data ) { + var entity = data.entity; + + Object.keys(entity.disabledSamlSites).forEach(function(key,index) { + myDisabledSitesMap.set(key, entity.disabledSamlSites[key]); + }); + drawTable(myDisabledSitesMap, "myDisabledSitesMap", "disabledSiteListingTable"); + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrGet(xhrArgs); + } + + function getDefaultIdpConfig(){ + var defaultIdp = ""; + + xhrArgs = { + url: "/api/v1/dotsaml/default", + sync: true, + handleAs: "json", + load: function (data) { + idp = data.entity; + if(idp && idp.defaultSamlConfig){ + defaultIdp = idp.defaultSamlConfig; + } + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + } + deferred = dojo.xhrGet(xhrArgs); + + return defaultIdp; + } + + function findIdpConfig(id) { + xhrArgs = { + url: "/api/v1/dotsaml/idp/" + id, + handleAs: "json", + load: function (data) { + var idp = data.entity; + + dijit.byId('addEditIdPDialog').show(); + + resetIdpConfig(mySitesMap, "siteListingTable"); + + addEditIdPForm.elements["id"].value = idp.id; + addEditIdPForm.elements["idpName"].value = idp.idpName; + if (idp.enabled){ + document.getElementById("enabledTrue").checked = true; + } else { + document.getElementById("enabledFalse").checked = true; + } + + addEditIdPForm.elements["sPIssuerURL"].value = idp.sPIssuerURL; + addEditIdPForm.elements["sPEndponintHostname"].value = idp.sPEndponintHostname; + + dijit.byId("signatureValidationType").set("value", idp.signatureValidationType); + + if(idp.privateKey){ + document.getElementById("privateKeySavedFile").innerText = idp.privateKey.replace(/^.*[\\\/]/, ''); + } + if(idp.publicCert){ + document.getElementById("publicCertSavedFile").innerText = idp.publicCert.replace(/^.*[\\\/]/, ''); + } + if(idp.idPMetadataFile){ + document.getElementById("idPMetadataSavedFile").innerText = idp.idPMetadataFile.replace(/^.*[\\\/]/, ''); + } + + var optionalPropertiesText = ""; + + Object.keys(idp.optionalProperties).forEach(function(key,index) { + optionalPropertiesText += key + "=" + idp.optionalProperties[key]+ "\n" + }); + + Object.keys(idp.sites).forEach(function(key,index) { + mySitesMap.set(key, idp.sites[key]); + }); + + addEditIdPForm.elements["optionalProperties"].value = optionalPropertiesText; + + drawTable(mySitesMap, "mySitesMap", "siteListingTable"); + + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + deferred = dojo.xhrGet(xhrArgs); + } + + var mySitesMap = new Map(); + var myDisabledSitesMap = new Map(); + + function addSite(sitesMap, sitesMapName, selectId, tableId){ + var siteId = dijit.byId(selectId).value; + var siteName = dijit.byId(selectId).attr('displayedValue'); + + sitesMap.set(siteId, siteName); + drawTable(sitesMap, sitesMapName, tableId); + } + + function deleteSite(id, sitesMap, sitesMapName, tableId) { + sitesMap.delete(id); + drawTable(sitesMap, sitesMapName, tableId); + } + + function resetTable(tableId) { + var tableRows = document.getElementById(tableId).rows.length; + if (tableRows > 1) { + for (i = 1; i < tableRows; i++) { + document.getElementById(tableId).deleteRow(i); + } + } + } + + function drawTable(sitesMap, sitesMapName, tableId){ + resetTable(tableId); + + for (var key of sitesMap.keys()) { + + var table = document.getElementById(tableId); + var row = table.insertRow(1); // -1 at the end. + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + var cell3 = row.insertCell(2); + + var siteId = key; + var siteName = sitesMap.get(key); + + cell1.innerHTML = siteName; + cell2.innerHTML = siteId; + cell3.innerHTML = ''; + } + } + + function resetIdpConfig(sitesMap, tableId) { + dojo.byId("addEditIdPForm").reset(); + + document.getElementById("privateKeySavedFile").innerText = ""; + document.getElementById("publicCertSavedFile").innerText = ""; + document.getElementById("idPMetadataSavedFile").innerText = ""; + + document.getElementById("privateKey").value = ""; + document.getElementById("publicCert").value = ""; + document.getElementById("idPMetadataFile").value = ""; + + document.getElementById("optionalProperties").value = ""; + + sitesMap.clear(); + resetTable(tableId); + } + + require(['dojo/_base/declare'], function(declare){ + declare("dotcms.dijit.saml.IdPAdmin", null, { + constructor: function(){ + this.currentPage = 1; + this.RESULTS_PER_PAGE = 10; + this.total = 0; + this.filter = ""; + }, + + tableResultSummaryTemplate: '<%= LanguageUtil.get(pageContext, "Viewing-Results") %> {startRecord} <%= LanguageUtil.get(pageContext, "to") %> \ + {endRecord} <%= LanguageUtil.get(pageContext, "of") %> {total}', + + renderPagination: function (total) { + //Rendering the results summary bottom section of the table + var startRecord = (this.currentPage - 1) * this.RESULTS_PER_PAGE + 1; + if (startRecord > total) + startRecord = total; + var endRecord = startRecord + this.RESULTS_PER_PAGE - 1; + if (endRecord > total) + endRecord = total; + + var summaryHTML = dojo.replace(this.tableResultSummaryTemplate, { + startRecord: startRecord, + endRecord: endRecord, + total: total + }); + dojo.byId('resultsSummary').innerHTML = summaryHTML; + //Rendering the next and previous buttons + dojo.style('buttonNextResultsWrapper', { + visibility: 'hidden' + }); + dojo.style('buttonPreviousResultsWrapper', { + visibility: 'hidden' + }); + if (endRecord < total) + dojo.style('buttonNextResultsWrapper', { + visibility: 'visible' + }); + if (startRecord > 1) + dojo.style('buttonPreviousResultsWrapper', { + visibility: 'visible' + }); + + if (total == 0) + dojo.style('resultsSummary', { + visibility: 'hidden' + }) + else + dojo.style('resultsSummary', { + visibility: 'visible' + }) + }, + + addIdp : function() { + dijit.byId('addEditIdPDialog').show(); + resetIdpConfig(mySitesMap, "siteListingTable"); + }, + editIdp : function(id) { + findIdpConfig(id); + }, + deleteIdp : function(id) { + if(confirm('<%= UtilMethods.escapeSingleQuotes(LanguageUtil.get(pageContext, "delete-dialog-text"))%>')) { + deleteIdpConfig(id); + } + }, + setDefaultIdp : function(id) { + setDefaultIdpConfig(id); + }, + disableSAMLPerSite : function() { + dijit.byId('disableSamlSiteDialog').show(); + getDisabledSites(); + }, + downloadSPMedatadata : function() { + window.alert("This functionality will be available in the next sprint"); + }, + gotoNextPage: function(){ + this.currentPage++; + this.renderIdpConfigs(); + }, + gotoPreviousPage: function(){ + this.currentPage--; + this.renderIdpConfigs(); + }, + searchIdpByName: function(){ + this.filter = document.getElementById("filter").value; + this.renderIdpConfigs(); + }, + resetSearch: function(){ + document.getElementById("filter").value = ""; + this.filter = ""; + this.renderIdpConfigs(); + }, + renderIdpConfigs : function() { + //Node List + var idpList; + var defaultIdp = getDefaultIdpConfig(); + + xhrArgs = { + url: "/api/v1/dotsaml/idps", + content: { + page: this.currentPage, + filter: this.filter, + }, + handleAs: "json", + load: function (data) { + idpList = data.entity; + var idpsTableHTML = ""; + var idpStatusColor = ""; + + dojo.forEach(idpList, function (item, index) { + + if (item.enabled) { + idpStatusColor = "liveIcon"; + } else { + idpStatusColor = "archivedIcon"; + } + + var defaultButtonHTML = ""; + + if(defaultIdp && defaultIdp == item.id){ + defaultButtonHTML = ""; + } + + var defaultTranslation = "" + + if(defaultIdp && defaultIdp == item.id){ + defaultTranslation = "(Default)"; + } + + idpsTableHTML += + " " + + " " + + " " + + " " + + " " + item.idpName + defaultTranslation + "" + + " " + + " " + + " " + + defaultButtonHTML + + " " + + " " + + " " + + " " + + " "; + }); + + idpsTableHTML += "" + + " " + + " " + + " <%=LanguageUtil.get(pageContext, "disabled-sites")%>" + + " " + + " " + + " " + + " " + + " " + + " " + + dojo.empty(dojo.byId("idpTableBody")); + dojo.place(idpsTableHTML, dojo.byId("idpTableBody")); + dojo.parser.parse(dojo.byId("idpTableBody")) + }, + error: function (error) { + alert("An unexpected error occurred: " + error); + } + }; + + deferred = dojo.xhrGet(xhrArgs); + deferred.then(function (response) { + var total = deferred.ioArgs.xhr.getResponseHeader("X-Pagination-Total-Entries"); + idpAdmin.renderPagination(total); + }); + + } + }); + }); + + var idpAdmin = new dotcms.dijit.saml.IdPAdmin({});