diff --git a/server/src/main/java/org/gluu/oxtrust/action/AttributeImportAction.java b/server/src/main/java/org/gluu/oxtrust/action/AttributeImportAction.java index 637aa7570..d0741f57a 100644 --- a/server/src/main/java/org/gluu/oxtrust/action/AttributeImportAction.java +++ b/server/src/main/java/org/gluu/oxtrust/action/AttributeImportAction.java @@ -11,99 +11,60 @@ import java.io.InputStream; import java.io.Serializable; -import org.gluu.oxtrust.ldap.load.conf.ImportPersonConfiguration; import org.gluu.oxtrust.ldap.service.AttributeService; -import org.gluu.oxtrust.ldap.service.ExcelService; -import org.gluu.oxtrust.ldap.service.IPersonService; import org.gluu.oxtrust.ldap.service.LdifService; -import org.gluu.oxtrust.service.external.ExternalUpdateUserService; import org.gluu.oxtrust.util.OxTrustConstants; -import org.gluu.site.ldap.persistence.LdapEntryManager; -import org.gluu.site.ldap.persistence.LdifDataUtility; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; -import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.security.Restrict; import org.jboss.seam.faces.FacesMessages; import org.jboss.seam.international.StatusMessage.Severity; -import org.jboss.seam.international.StatusMessages; import org.jboss.seam.log.Log; import org.richfaces.event.FileUploadEvent; import org.richfaces.model.UploadedFile; -import org.xdi.config.oxtrust.ApplicationConfiguration; -import org.xdi.model.GluuAttribute; - import com.unboundid.ldap.sdk.ResultCode; -import com.unboundid.ldif.LDIFReader; /** - * Action class for load data from LDIF file + * Action class to load data from LDIF file * - * @author Shekhar Laad Date: 02.14.2011 + * @author Shekhar L Date: 02.28.2017 */ @Name("attributeImportAction") @Scope(ScopeType.CONVERSATION) @Restrict("#{identity.loggedIn}") public class AttributeImportAction implements Serializable { - private static final long serialVersionUID = -1270460481895022468L; - - public static final String PERSON_PASSWORD_ATTRIBUTE = "userPassword"; + /** + * + */ + private static final long serialVersionUID = 8755036208872218664L; @Logger private Log log; - - @In - StatusMessages statusMessages; - - @In - private IPersonService personService; @In private LdifService ldifService; @In private AttributeService attributeService; - - @In(value = "#{oxTrustConfiguration.applicationConfiguration}") - private ApplicationConfiguration applicationConfiguration; - - @In - private ExternalUpdateUserService externalUpdateUserService; - - @In - private transient ExcelService excelService; @In private FacesMessages facesMessages; - @In - private transient ImportPersonConfiguration importPersonConfiguration; - - @In - protected LdapEntryManager ldapEntryManager; - - @In(create = true) - @Out(scope = ScopeType.CONVERSATION) - private CustomAttributeAction customAttributeAction; - private UploadedFile uploadedFile; private FileDataToImport fileDataToImport; private byte[] fileData; private boolean isInitialized; - LdifDataUtility ldifDataUtility; public String init() { if (this.isInitialized) { return OxTrustConstants.RESULT_SUCCESS; } - - ldifDataUtility = LdifDataUtility.instance(); this.fileDataToImport = new FileDataToImport(); this.isInitialized = true; @@ -141,6 +102,7 @@ public String importAttributes() throws Exception { public void validateFileToImport() throws Exception { removeFileDataToImport(); + String dn=attributeService.getDnForAttribute(null); if (uploadedFile == null) { return; @@ -149,7 +111,7 @@ public void validateFileToImport() throws Exception { if (uploadedFile != null) { //Table table; InputStream is = new ByteArrayInputStream(this.fileData); - ResultCode result = ldifService.importLdifFileInLdap( is); + ResultCode result = ldifService.validateLdifFile(is , dn); if(!result.equals(ResultCode.SUCCESS)){ log.info("LDIFReader --- : "); removeFileDataToImport(); @@ -163,7 +125,6 @@ public void validateFileToImport() throws Exception { } } - @Restrict("#{s:hasPermission('import', 'person')}") public void cancel() { destroy(); } @@ -186,7 +147,6 @@ public void removeFileDataToImport() { this.fileDataToImport.reset(); } - @Restrict("#{s:hasPermission('import', 'person')}") public void uploadFile(FileUploadEvent event) { removeFileToImport(); @@ -194,7 +154,6 @@ public void uploadFile(FileUploadEvent event) { this.fileData = this.uploadedFile.getData(); } - @Restrict("#{s:hasPermission('import', 'person')}") public void removeFileToImport() { if (uploadedFile != null) { try { @@ -254,34 +213,4 @@ public void setIs(InputStream is) { this.is = is; } } - - public static class ImportAttribute implements Serializable { - - private static final long serialVersionUID = -5640983196565086530L; - - private GluuAttribute attribute; - private int col; - - public ImportAttribute(int col, GluuAttribute attribute) { - this.col = col; - this.attribute = attribute; - } - - public int getCol() { - return col; - } - - public void setCol(int col) { - this.col = col; - } - - public GluuAttribute getAttribute() { - return attribute; - } - - public void setAttribute(GluuAttribute attribute) { - this.attribute = attribute; - } - } - } diff --git a/server/src/main/java/org/gluu/oxtrust/ldap/service/LdifService.java b/server/src/main/java/org/gluu/oxtrust/ldap/service/LdifService.java index 0cd21a95f..16fe6f52f 100644 --- a/server/src/main/java/org/gluu/oxtrust/ldap/service/LdifService.java +++ b/server/src/main/java/org/gluu/oxtrust/ldap/service/LdifService.java @@ -9,8 +9,6 @@ import java.io.InputStream; import java.io.Serializable; -import org.gluu.oxtrust.util.OxTrustConstants; -import org.gluu.site.ldap.OperationsFacade; import org.gluu.site.ldap.persistence.LdapEntryManager; import org.gluu.site.ldap.persistence.LdifDataUtility; import org.jboss.seam.ScopeType; @@ -19,7 +17,6 @@ import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; -import org.jboss.seam.international.StatusMessage.Severity; import org.jboss.seam.log.Log; import com.unboundid.ldap.sdk.LDAPConnection; @@ -29,15 +26,20 @@ import com.unboundid.ldif.LDIFReader; /** - * Provides operations with persons + * Provides operations with LDIF files * - * @author Yuriy Movchan Date: 10.13.2010 + * @author Shekhar L Date: 02.28.2017 */ @Scope(ScopeType.STATELESS) @Name("ldifService") @AutoCreate public class LdifService implements Serializable{ - + + /** + * + */ + private static final long serialVersionUID = 6690460114767359078L; + @Logger private Log log; @@ -46,24 +48,14 @@ public class LdifService implements Serializable{ LdifDataUtility ldifDataUtility = LdifDataUtility.instance(); - @In - private IGroupService groupService; - - private transient OperationsFacade ldapOperationService; - - public boolean destroy() { - boolean destroyResult = this.ldapOperationService.destroy(); - - return destroyResult; - } public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException{ ResultCode result = ResultCode.UNAVAILABLE; + LDAPConnectionPool ldapConnectionPool = ldapEntryManager.getLdapOperationService().getConnectionPool(); LDAPConnection connection = null; - try { - connection = ldapOperationService.getConnection(); - //ResultCode result = LdifDataUtility.instance().importLdifFileContent(connection, ldifFileContent); + try { + connection = ldapConnectionPool.getConnection(); LDIFReader importLdifReader = new LDIFReader(is); @@ -72,26 +64,28 @@ public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException{ } catch(Exception e ) { log.info("LDIFReader --- : " + e.getMessage()); + e.printStackTrace(); }finally { if (connection != null) { - ldapOperationService.releaseConnection(connection); + ldapConnectionPool.releaseConnection(connection); } } return result; } - public ResultCode validateLdifFile(InputStream is) throws LDAPException{ + public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException{ ResultCode result = ResultCode.UNAVAILABLE; try { LDIFReader validateLdifReader = new LDIFReader(is); - result = ldifDataUtility.validateLDIF(validateLdifReader); + result = ldifDataUtility.validateLDIF(validateLdifReader,dn); log.info("LDIFReader successfully"); validateLdifReader.close(); } catch(Exception e ) { log.info("LDIFReader --- : "+e.getMessage()); + e.printStackTrace(); } return result;