// Path: src/main/java/com/github/segator/proxylive/config/LDAPAutentication.java
// public class LDAPAutentication {
// 
//     private String server, searchBase, user, password;
// 
//     public String getServer() {
//         return server;
//     }
// 
//     public void setServer(String server) {
//         this.server = server;
//     }
// 
//     public String getSearchBase() {
//         return searchBase;
//     }
// 
//     public void setSearchBase(String searchBase) {
//         this.searchBase = searchBase;
//     }
// 
//     public String getUser() {
//         return user;
//     }
// 
//     public void setUser(String user) {
//         this.user = user;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
// }
// 
// Path: src/main/java/com/github/segator/proxylive/config/ProxyLiveConfiguration.java
// @Configuration
// @ConfigurationProperties
// public class ProxyLiveConfiguration {
//     private final Logger logger = LoggerFactory.getLogger(DirectTranscodeTask.class);
//     private final JwtHelper jwtHelper;
//     private BufferingConfiguration buffers;
//     private FFMpegConfiguration ffmpeg;
//     private HttpLiveSource source;
//     private GEOIPDatasource geoIP;
//     private AuthenticationConfiguration authentication;
//     private String userAgent;
//     private int streamTimeout;
// 
//     public ProxyLiveConfiguration(JwtHelper jwtHelper) {
//         this.jwtHelper = jwtHelper;
//     }
// 
//     @PostConstruct
//     public void initializeBean() {
// 
//         //If tvheadend input is set complete configuration
//         if(source.getTvheadendURL()!=null){
//             if( source.getEpg().getUrl()==null) {
//                 source.getEpg().setUrl(source.getTvheadendURL() + "/xmltv/channels");
//             }
//             if(source.getChannels().getUrl()==null) {
//                 source.getChannels().setUrl(source.getTvheadendURL());
//             }
//         }
// 
// 
//     }
// 
//     public FFMpegConfiguration getFfmpeg() {
//         return ffmpeg;
//     }
// 
//     public void setFfmpeg(FFMpegConfiguration ffmpeg) {
//         this.ffmpeg = ffmpeg;
//     }
// 
//     public HttpLiveSource getSource() {
//         return source;
//     }
// 
//     public GEOIPDatasource getGeoIP() {
//         return geoIP;
//     }
// 
//     public void setGeoIP(GEOIPDatasource geoIP) {
//         this.geoIP = geoIP;
//     }
// 
//     public void setSource(HttpLiveSource source) {
//         this.source = source;
//     }
// 
//     public BufferingConfiguration getBuffers() {
//         return buffers;
//     }
// 
//     public void setBuffers(BufferingConfiguration buffers) {
//         this.buffers = buffers;
//     }
// 
//     public AuthenticationConfiguration getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(AuthenticationConfiguration authentication) {
//         this.authentication = authentication;
//     }
// 
//     public int getStreamTimeout() {
//         return streamTimeout;
//     }
//     public int getStreamTimeoutMilis() {
//         return streamTimeout*1000;
//     }
// 
//     public void setStreamTimeout(int streamTimeout) {
//         this.streamTimeout = streamTimeout;
//     }
// 
// 
//     public String getUserAgent() {
//         return userAgent;
//     }
// 
//     public void setUserAgent(String userAgent) {
//         this.userAgent = userAgent;
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/helper/AuthorityRoles.java
// public enum AuthorityRoles {
//     USER("USER"),
//     SERVICE_ACCOUNT("SERVICE_ACCOUNT"),
//     ALLOW_ENCODING("ENCODE_PULLER"),
//     ADMIN("ADMIN");
//     private String authority;
//     AuthorityRoles(String authority) {
//         this.authority = authority;
//     }
// 
//     public String getAuthority() {
//         return authority;
//     }
// }


import com.github.segator.proxylive.config.LDAPAutentication;
import com.github.segator.proxylive.config.ProxyLiveConfiguration;
import com.github.segator.proxylive.helper.AuthorityRoles;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import javax.annotation.PostConstruct;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.github.segator.proxylive.service;



/**
 *
 * @author isaac
 */
public class LDAPAuthenticationService implements AuthenticationService {
    private final Logger logger = LoggerFactory.getLogger(LDAPAuthenticationService.class);
// Path: src/main/java/com/github/segator/proxylive/config/LDAPAutentication.java
// public class LDAPAutentication {
// 
//     private String server, searchBase, user, password;
// 
//     public String getServer() {
//         return server;
//     }
// 
//     public void setServer(String server) {
//         this.server = server;
//     }
// 
//     public String getSearchBase() {
//         return searchBase;
//     }
// 
//     public void setSearchBase(String searchBase) {
//         this.searchBase = searchBase;
//     }
// 
//     public String getUser() {
//         return user;
//     }
// 
//     public void setUser(String user) {
//         this.user = user;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
// }
// 
// Path: src/main/java/com/github/segator/proxylive/config/ProxyLiveConfiguration.java
// @Configuration
// @ConfigurationProperties
// public class ProxyLiveConfiguration {
//     private final Logger logger = LoggerFactory.getLogger(DirectTranscodeTask.class);
//     private final JwtHelper jwtHelper;
//     private BufferingConfiguration buffers;
//     private FFMpegConfiguration ffmpeg;
//     private HttpLiveSource source;
//     private GEOIPDatasource geoIP;
//     private AuthenticationConfiguration authentication;
//     private String userAgent;
//     private int streamTimeout;
// 
//     public ProxyLiveConfiguration(JwtHelper jwtHelper) {
//         this.jwtHelper = jwtHelper;
//     }
// 
//     @PostConstruct
//     public void initializeBean() {
// 
//         //If tvheadend input is set complete configuration
//         if(source.getTvheadendURL()!=null){
//             if( source.getEpg().getUrl()==null) {
//                 source.getEpg().setUrl(source.getTvheadendURL() + "/xmltv/channels");
//             }
//             if(source.getChannels().getUrl()==null) {
//                 source.getChannels().setUrl(source.getTvheadendURL());
//             }
//         }
// 
// 
//     }
// 
//     public FFMpegConfiguration getFfmpeg() {
//         return ffmpeg;
//     }
// 
//     public void setFfmpeg(FFMpegConfiguration ffmpeg) {
//         this.ffmpeg = ffmpeg;
//     }
// 
//     public HttpLiveSource getSource() {
//         return source;
//     }
// 
//     public GEOIPDatasource getGeoIP() {
//         return geoIP;
//     }
// 
//     public void setGeoIP(GEOIPDatasource geoIP) {
//         this.geoIP = geoIP;
//     }
// 
//     public void setSource(HttpLiveSource source) {
//         this.source = source;
//     }
// 
//     public BufferingConfiguration getBuffers() {
//         return buffers;
//     }
// 
//     public void setBuffers(BufferingConfiguration buffers) {
//         this.buffers = buffers;
//     }
// 
//     public AuthenticationConfiguration getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(AuthenticationConfiguration authentication) {
//         this.authentication = authentication;
//     }
// 
//     public int getStreamTimeout() {
//         return streamTimeout;
//     }
//     public int getStreamTimeoutMilis() {
//         return streamTimeout*1000;
//     }
// 
//     public void setStreamTimeout(int streamTimeout) {
//         this.streamTimeout = streamTimeout;
//     }
// 
// 
//     public String getUserAgent() {
//         return userAgent;
//     }
// 
//     public void setUserAgent(String userAgent) {
//         this.userAgent = userAgent;
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/helper/AuthorityRoles.java
// public enum AuthorityRoles {
//     USER("USER"),
//     SERVICE_ACCOUNT("SERVICE_ACCOUNT"),
//     ALLOW_ENCODING("ENCODE_PULLER"),
//     ADMIN("ADMIN");
//     private String authority;
//     AuthorityRoles(String authority) {
//         this.authority = authority;
//     }
// 
//     public String getAuthority() {
//         return authority;
//     }
// }


// Path: src/main/java/com/github/segator/proxylive/service/LDAPAuthenticationService.java
import com.github.segator.proxylive.config.LDAPAutentication;
import com.github.segator.proxylive.config.ProxyLiveConfiguration;
import com.github.segator.proxylive.helper.AuthorityRoles;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import javax.annotation.PostConstruct;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.github.segator.proxylive.service;



/**
 *
 * @author isaac
 */
public class LDAPAuthenticationService implements AuthenticationService {
    private final Logger logger = LoggerFactory.getLogger(LDAPAuthenticationService.class);
    private LDAPAutentication ldapAuthConfig;