Skip to content

Commit

Permalink
new signUi + userList + fix ldap user search
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemaignent committed Jan 15, 2021
1 parent 7e219c1 commit 745b225
Show file tree
Hide file tree
Showing 26 changed files with 504 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

@ConfigurationProperties(prefix="extdb")
public class ExtDbProperties {

DataSourceProperties[] dataSources;
Map<String, DataSourceProperties> dataSources = new HashMap<>();

public DataSourceProperties[] getDataSources() {
public Map<String, DataSourceProperties> getDataSources() {
return dataSources;
}

public void setDataSources(DataSourceProperties[] dataSources) {
this.dataSources = dataSources;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.esupportail.esupsignature.repository.ldap;

import org.esupportail.esupsignature.service.ldap.AliasLdap;
import org.springframework.data.ldap.repository.LdapRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AliasLdapRepository extends LdapRepository<AliasLdap> {

List<AliasLdap> findByMailAliasStartingWithOrCnStartingWithAndMailAliasNotNull(String mailAlias, String cn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
public interface PersonLdapRepository extends LdapRepository<PersonLdap> {
List<PersonLdap> findByEduPersonPrincipalName(String eppn);
List<PersonLdap> findByMail(String mail);
List<PersonLdap> findByUid(String uid);
List<PersonLdap> findByUidOrEduPersonPrincipalNameOrSupannAliasLogin(String uid);
List<PersonLdap> findByCnIgnoreCaseOrDisplayNameIgnoreCaseOrUidOrMail(String cn, String displayName, String uid, String mail);
List<PersonLdap> findByDisplayNameStartingWithIgnoreCaseOrCnStartingWithIgnoreCaseOrUidStartingWithOrMailStartingWith(String displayName, String cn, String uid, String mail);
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.esupportail.esupsignature.service;

import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.config.ldap.LdapProperties;
import org.esupportail.esupsignature.config.security.WebSecurityProperties;
import org.esupportail.esupsignature.entity.*;
import org.esupportail.esupsignature.entity.enums.EmailAlertFrequency;
Expand Down Expand Up @@ -50,6 +51,9 @@ public class UserService {
@Resource
private GlobalProperties globalProperties;

@Resource
private LdapProperties ldapProperties;

@Resource
private UserRepository userRepository;

Expand Down Expand Up @@ -193,7 +197,7 @@ public User createUserWithAuthentication(Authentication authentication) {
throw new EsupSignatureRuntimeException("Creation of user not implemented without ldap configuration");
}
logger.info("controle de l'utilisateur " + uid);
List<PersonLdap> personLdaps = ldapPersonService.getIfAvailable().getPersonLdapRepository().findByUidOrEduPersonPrincipalNameOrSupannAliasLogin(uid);
List<PersonLdap> personLdaps = ldapPersonService.getIfAvailable().getPersonLdap(uid);
String eppn = personLdaps.get(0).getEduPersonPrincipalName();
if (eppn == null) {
eppn = buildEppn(personLdaps.get(0).getUid());
Expand All @@ -204,7 +208,6 @@ public User createUserWithAuthentication(Authentication authentication) {
return createUser(eppn, name, firstName, mail, UserType.ldap);
}

@Transactional
public User createUser(String eppn, String name, String firstName, String email, UserType userType) {
User user;
if (userRepository.countByEppn(eppn) > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.esupportail.esupsignature.service.extdb;

import org.esupportail.esupsignature.config.extdb.ExtDbConfig;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

Expand All @@ -15,12 +14,7 @@ public class ExtDbService {
private ExtDbConfig extDbConfigs;

public DataSource getDataSourceByName(String name) {
for(DataSourceProperties dataSourceProperties : extDbConfigs.getExtDbProperties().getDataSources()) {
if(dataSourceProperties.getName().equals(name)) {
return dataSourceProperties.initializeDataSourceBuilder().build();
}
}
return null;
return extDbConfigs.getExtDbProperties().getDataSources().get(name).initializeDataSourceBuilder().build();
}

public JdbcTemplate getJdbcTemplateByName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import org.esupportail.esupsignature.service.interfaces.fs.FsAccessService;
import org.esupportail.esupsignature.service.interfaces.fs.FsFile;
import org.esupportail.esupsignature.service.interfaces.fs.UploadActionType;
import org.esupportail.esupsignature.service.utils.file.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.util.FileCopyUtils;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -41,9 +39,6 @@ public class VfsAccessImpl extends FsAccessService implements DisposableBean {

private static final Logger logger = LoggerFactory.getLogger(VfsAccessImpl.class);

@Resource
private FileService fileService;

protected FileSystemManager fsManager;

protected FileObject root;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.esupportail.esupsignature.service.ldap;

import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;

import javax.naming.Name;
import java.util.List;

@Entry(objectClasses = {"nisMailAlias"}, base = "ou=aliases-list")
public class AliasLdap {

@Id
private Name dn;
private @Attribute(name = "mail") String mailAlias;
private @Attribute(name = "rfc822MailMember")
List<String> memberMails;
private @Attribute(name = "cn") String cn;

public String getMailAlias() {
return mailAlias;
}

public void setMailAlias(String mailAlias) {
this.mailAlias = mailAlias;
}

public List<String> getMemberMails() {
return memberMails;
}

public void setMemberMails(List<String> memberMails) {
this.memberMails = memberMails;
}

public String getCn() {
return cn;
}

public void setCn(String cn) {
this.cn = cn;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.esupportail.esupsignature.service.ldap;

import org.esupportail.esupsignature.repository.ldap.AliasLdapRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LdapAliasService {

@Autowired(required = false)
private AliasLdapRepository aliasLdapRepository;


public List<AliasLdap> searchAlias(String searchString) {
return aliasLdapRepository.findByMailAliasStartingWithOrCnStartingWithAndMailAliasNotNull(searchString, searchString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

import org.esupportail.esupsignature.config.ldap.LdapProperties;
import org.esupportail.esupsignature.repository.ldap.PersonLdapRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.List;

@Service
@ConditionalOnProperty(prefix = "spring.ldap", name = "base")
@EnableConfigurationProperties(LdapProperties.class)
public class LdapPersonService {

@Autowired
private LdapTemplate ldapTemplate;

@Resource
private LdapProperties ldapProperties;

@Resource
private PersonLdapRepository personLdapRepository;

Expand All @@ -26,4 +35,9 @@ public PersonLdapRepository getPersonLdapRepository() {
return personLdapRepository;
}

public List<PersonLdap> getPersonLdap(String uid) {
String formattedFilter = MessageFormat.format(ldapProperties.getUserIdSearchFilter(), new String[] { uid });
return ldapTemplate.search(ldapProperties.getSearchBase(), formattedFilter, new PersonLdapAttributesMapper());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.esupportail.esupsignature.service.ldap;

import org.springframework.ldap.core.AttributesMapper;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;


public class PersonLdapAttributesMapper implements AttributesMapper<PersonLdap> {

public PersonLdap mapFromAttributes(Attributes attrs) throws NamingException {
PersonLdap person = new PersonLdap();
person.setCn((String)attrs.get("cn").get());
Attribute sn = attrs.get("sn");
if (sn != null){
person.setSn((String) sn.get());
}
Attribute givenName = attrs.get("givenName");
if (givenName != null){
person.setGivenName((String) givenName.get());
}
Attribute mail = attrs.get("mail");
if (mail != null){
person.setMail((String) mail.get());
}
Attribute eduPersonPrincipalName = attrs.get("eduPersonPrincipalName");
if (eduPersonPrincipalName != null){
person.setEduPersonPrincipalName((String) eduPersonPrincipalName.get());
}
return person;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.esupportail.esupsignature.service.list;

import java.util.List;

public interface UserList {
public String getName();
public List<String> getUsersEmailFromList(String listName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.esupportail.esupsignature.service.list;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserListService {

@Autowired(required = false)
UserList userList;

public List<String> getUsersEmailFromList(String listName) {
if(userList != null) {
return userList.getUsersEmailFromList(listName);
} else {
return new ArrayList<>();
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.esupportail.esupsignature.service.list.impl;

import org.esupportail.esupsignature.service.extdb.ExtDbService;
import org.esupportail.esupsignature.service.list.UserList;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

@Component
@ConditionalOnProperty(name = "extdb.datasources.userListDataSource.name", havingValue = "sympa")
public class SympaUserList implements UserList {

JdbcTemplate jdbcTemplate;

@Resource
ExtDbService extDbService;

@PostConstruct
public void initJdbcTemplate() {
this.jdbcTemplate = extDbService.getJdbcTemplateByName("userListDataSource");
}

@Override
public String getName() {
return "sympa";
}

@Override
public List<String> getUsersEmailFromList(String listName) {
List<String> userEmails = new ArrayList<>();
jdbcTemplate.query("select user_subscriber from subscriber_table where list_subscriber=" + "'" + listName.split("@")[0] + "'", (ResultSet rs) -> {
userEmails.add(rs.getString("user_subscriber"));
while (rs.next()) {
userEmails.add(rs.getString("user_subscriber"));
}
});
return userEmails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public class ScheduledTaskService {
@Transactional
public void scanAllSignbooksSources() {
Iterable<Workflow> workflows = workflowService.getAllWorkflows();
User userScheduler = userService.getSchedulerUser();
for(Workflow workflow : workflows) {
workflowService.importFilesFromSource(workflow, userService.getSchedulerUser(), userService.getSchedulerUser());
workflowService.importFilesFromSource(workflow, userScheduler, userScheduler);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.esupportail.esupsignature.service.security.cas;

import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.config.ldap.LdapProperties;
import org.esupportail.esupsignature.config.security.WebSecurityProperties;
import org.esupportail.esupsignature.config.security.cas.CasProperties;
Expand Down Expand Up @@ -48,9 +47,6 @@ public class CasSecurityServiceImpl implements SecurityService {
@Resource
private CasProperties casProperties;

@Resource
private GlobalProperties globalProperties;

@Resource
private LdapProperties ldapProperties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public InputStream stampImage(InputStream inputStream, SignRequest signRequest,
float ty = 0;
float xAdjusted = signRequestParams.getxPos();
float yAdjusted;
int widthAdjusted = Math.round((float) (bufferedSignImage.getWidth() / 3 * 0.75));
int heightAdjusted = Math.round((float) (bufferedSignImage.getHeight() / 3 * 0.75));
int widthAdjusted = Math.round((float) signRequestParams.getSignWidth());
int heightAdjusted = Math.round((float) signRequestParams.getSignHeight());

if(pdfParameters.getRotation() == 0 || pdfParameters.getRotation() == 180) {
yAdjusted = pdfParameters.getHeight() - signRequestParams.getyPos() - signRequestParams.getSignHeight() + pdPage.getCropBox().getLowerLeftY();
Expand Down
Loading

0 comments on commit 745b225

Please sign in to comment.