Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fairuz Wan Ismail committed Dec 22, 2015
1 parent 3790187 commit 3163609
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
14 changes: 6 additions & 8 deletions src/main/java/sample/UserApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;

import sample.dao.GroupRepoImpl;
import org.springframework.ldap.repository.config.EnableLdapRepositories;

@SpringBootApplication
@EnableConfigurationProperties
@Configuration
@EnableLdapRepositories("sample.domain")
public class UserApplication {

public static void main(String[] args) {
Expand All @@ -33,8 +31,8 @@ public LdapTemplate ldapTemplate(ContextSource contextSource) {
return new LdapTemplate(contextSource);
}

@Bean
public GroupRepoImpl groupRepoImpl() {
return new GroupRepoImpl(ldapTemplate(contextSource()));
}
// @Bean
// public GroupRepoImpl groupRepoImpl() {
// return new GroupRepoImpl(ldapTemplate(contextSource()));
// }
}
21 changes: 15 additions & 6 deletions src/main/java/sample/controller/GroupController.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package sample.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import sample.dao.GroupRepo;
import sample.domain.GroupRepo;

@RestController
public class GroupController {

private final Logger log = LoggerFactory.getLogger(this.getClass());

@Autowired
@Qualifier("groupRepoImpl")
private GroupRepo groupRepo;

@RequestMapping(value = "/groups", method = RequestMethod.GET)
public ModelMap listGroups(ModelMap map) {
map.put("groups", groupRepo.getAllGroupNames());
return map;
public @ResponseBody String listGroups(ModelMap map) {
List<String> groups = groupRepo.getAllGroupNames();
for(String group: groups) {
log.info(">> " + group);
}
map.put("groups", groups);
return "test";
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sample.model;
package sample.domain;

import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package sample.dao;
package sample.domain;

import java.util.Collection;

import javax.naming.Name;

import org.springframework.ldap.repository.LdapRepository;
import org.springframework.ldap.repository.Query;
import org.springframework.stereotype.Repository;

import sample.model.Group;

@Repository
public interface GroupRepo extends LdapRepository<Group>, GroupRepoExtension {
public final static String USER_GROUP = "ROLE_USER";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package sample.dao;
package sample.domain;

import java.util.List;

import sample.model.Group;

public interface GroupRepoExtension {
List<String> getAllGroupNames();
void create(Group group);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sample.dao;
package sample.domain;

import static org.springframework.ldap.query.LdapQueryBuilder.query;

Expand All @@ -14,11 +14,9 @@
import org.springframework.ldap.core.support.BaseLdapNameAware;
import org.springframework.ldap.query.LdapQuery;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import sample.model.Group;

@Component
@Repository
public class GroupRepoImpl implements GroupRepoExtension, BaseLdapNameAware {
private final static LdapName ADMIN_USER = LdapUtils.newLdapName("cn=administrators,ou=System,ou=IT,ou=Departments");

Expand Down

0 comments on commit 3163609

Please sign in to comment.