Commit 256832a0 authored by benjamin.ertl's avatar benjamin.ertl
Browse files

add comments

parent a583d6cc
...@@ -26,8 +26,15 @@ import javax.net.ssl.TrustManager; ...@@ -26,8 +26,15 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
/**
* Custom SSL context generation class.
*
* @author benjamin
*
*/
public final class CustomSSLContext { public final class CustomSSLContext {
// example cert
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final String cert = "-----BEGIN CERTIFICATE-----\n" private static final String cert = "-----BEGIN CERTIFICATE-----\n"
+ "MIICNTCCAZ6gAwIBAgIES343gjANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJV" + "MIICNTCCAZ6gAwIBAgIES343gjANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJV"
...@@ -46,6 +53,13 @@ public final class CustomSSLContext { ...@@ -46,6 +53,13 @@ public final class CustomSSLContext {
private CustomSSLContext() { private CustomSSLContext() {
} }
/**
* Initializes a SSL context with the given certificate.
*
* @param cert
* the X.509 certificate for the context
* @return a {@link SSLContext}
*/
public static SSLContext initSslContextWithCertificate(String cert) { public static SSLContext initSslContextWithCertificate(String cert) {
SSLContext sslContext = null; SSLContext sslContext = null;
...@@ -92,6 +106,11 @@ public final class CustomSSLContext { ...@@ -92,6 +106,11 @@ public final class CustomSSLContext {
return sslContext; return sslContext;
} }
/**
* Initializes an empty SSL context.
*
* @return a {@link SSLContext}
*/
public static SSLContext initEmptySslContext() { public static SSLContext initEmptySslContext() {
SSLContext sslContext = null; SSLContext sslContext = null;
try { try {
......
...@@ -19,6 +19,12 @@ import javax.net.ssl.SSLContext; ...@@ -19,6 +19,12 @@ import javax.net.ssl.SSLContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* Custom URL connection generation class.
*
* @author benjamin
*
*/
public final class CustomUrlConnection { public final class CustomUrlConnection {
private static final Logger log = LoggerFactory.getLogger(CustomUrlConnection.class); private static final Logger log = LoggerFactory.getLogger(CustomUrlConnection.class);
...@@ -26,6 +32,15 @@ public final class CustomUrlConnection { ...@@ -26,6 +32,15 @@ public final class CustomUrlConnection {
private CustomUrlConnection() { private CustomUrlConnection() {
} }
/**
* Initializes a HTTPS URL connection.
*
* @param checkCertificate
* enables certificate check
* @param url
* the URL to connect to
* @return a {@link HttpsURLConnection}
*/
public static HttpsURLConnection getSecureHttpConnection(boolean checkCertificate, String url) { public static HttpsURLConnection getSecureHttpConnection(boolean checkCertificate, String url) {
HttpsURLConnection urlConnection = null; HttpsURLConnection urlConnection = null;
try { try {
...@@ -56,6 +71,13 @@ public final class CustomUrlConnection { ...@@ -56,6 +71,13 @@ public final class CustomUrlConnection {
return urlConnection; return urlConnection;
} }
/**
* Initializes a HTTP URL connection.
*
* @param url
* the URL to connect to
* @return a {@link HttpURLConnection}
*/
public static HttpURLConnection getHttpConnection(String url) { public static HttpURLConnection getHttpConnection(String url) {
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
try { try {
......
...@@ -22,6 +22,12 @@ import org.springframework.stereotype.Component; ...@@ -22,6 +22,12 @@ import org.springframework.stereotype.Component;
import edu.kit.scc.dto.GroupDTO; import edu.kit.scc.dto.GroupDTO;
import edu.kit.scc.dto.UserDTO; import edu.kit.scc.dto.UserDTO;
/**
* LDAP client implementation.
*
* @author benjamin
*
*/
@Component @Component
public class LdapClient { public class LdapClient {
...@@ -82,21 +88,29 @@ public class LdapClient { ...@@ -82,21 +88,29 @@ public class LdapClient {
@Autowired @Autowired
private LdapGroupDAO ldapGroup; private LdapGroupDAO ldapGroup;
public void getLdapUsers() { /**
* Gets all users from the LDAP server.
*
* @return a {@link List<UserDTO>} with the LDAP user information
*/
public List<UserDTO> getLdapUsers() {
List<UserDTO> userList = ldapUser.getAllUsers(); List<UserDTO> userList = ldapUser.getAllUsers();
for (int i = 0; i < userList.size(); i++) for (int i = 0; i < userList.size(); i++)
log.info("User name {}", ((UserDTO) userList.get(i)).getCommonName()); log.info("User name {}", ((UserDTO) userList.get(i)).getCommonName());
List<UserDTO> userDetails = ldapUser.getUserDetails("jsmith1");
for (int i = 0; i < userDetails.size(); i++) return userList;
log.info("Description {}", ((UserDTO) userDetails.get(i)).getDescription());
} }
public void getLdapGroups() { /**
* Gets all groups from the LDAP server.
*
* @return a {@link List<GroupDTO>} with the LDAP group information
*/
public List<GroupDTO> getLdapGroups() {
List<GroupDTO> groupList = ldapGroup.getAllGroups(); List<GroupDTO> groupList = ldapGroup.getAllGroups();
for (int i = 0; i < groupList.size(); i++) for (int i = 0; i < groupList.size(); i++)
log.info("Gropu name {}", ((GroupDTO) groupList.get(i)).getCommonName()); log.info("Gropu name {}", ((GroupDTO) groupList.get(i)).getCommonName());
List<GroupDTO> groupDetails = ldapGroup.getGroupDetails("user");
for (int i = 0; i < groupDetails.size(); i++) return groupList;
log.info("GidNumber {}", ((GroupDTO) groupDetails.get(i)).getGidNumber());
} }
} }
...@@ -83,6 +83,12 @@ import org.slf4j.Logger; ...@@ -83,6 +83,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/**
* SAML client implementation.
*
* @author benjamin
*
*/
public class SamlClient { public class SamlClient {
private static final Logger log = LoggerFactory.getLogger(SamlClient.class); private static final Logger log = LoggerFactory.getLogger(SamlClient.class);
......
...@@ -25,8 +25,12 @@ public class LdapClientTests { ...@@ -25,8 +25,12 @@ public class LdapClientTests {
private LdapClient ldapClient; private LdapClient ldapClient;
@Test @Test
public void ldapClientTest() { public void getLdapGroupsTest() {
ldapClient.getLdapGroups(); ldapClient.getLdapGroups();
}
@Test
public void getLdapUsersTest() {
ldapClient.getLdapUsers(); ldapClient.getLdapUsers();
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment