Package com.vmware.bdd.entity

Examples of com.vmware.bdd.entity.User


         jaxbContext = JAXBContext.newInstance(Users.class);
         Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
         Users users =
               (Users) jaxbUnmarshaller.unmarshal(FileUtils.getConfigFile(
                     UserService.UsersFile, "Users"));
         User userDTO = null;
         boolean exsiting = false;
         boolean anonymous = false;
         if (users != null) {
            for (User user : users.getUsers()) {
               if (user.getName().equals(username)) {
                  exsiting = true;
                  userDTO = user;
                  break;
               } else if (user.getName().trim().equals("*")) {
                  anonymous = true;
                  userDTO = user;
                  userDTO.setName("Guest");
               }
            }
         }
         if (!exsiting && !anonymous) {
            throw new UsernameNotFoundException("unauthorized user");
         }

         ArrayList<GrantedAuthority> roleList = new ArrayList<GrantedAuthority>();
         roleList.add(new SimpleGrantedAuthority(ADMIN_ROLE));
         return new org.springframework.security.core.userdetails.User(
               userDTO.getName(), "", roleList);
      } catch (UsernameNotFoundException userNotFoundEx) {
         throw userNotFoundEx;
      } catch (Exception e) {
         logger.error("Authorized error :" + e.getMessage());
         throw new UsernameNotFoundException("unauthorized");
View Full Code Here


   @Test
   public void testLoadUserByUsername() throws JAXBException {
      UserDetails userDetails1 = null;
      UserDetailsService accountService = new UserService();
      Users users1 = new Users();
      User user1 = new User();
      user1.setName("serengeti");
      users1.setUsers(Arrays.asList(user1));

      String confPath = System.getProperties().get("serengeti.home.dir") + File.separator + "conf";
      new File(confPath).mkdir();
      String userXmlPath = confPath + File.separator + UsersFile;
      File usrXmlFile = new File(userXmlPath);

      TestFileUtils.createXMLFile(users1, usrXmlFile);
      try {
         userDetails1 = accountService.loadUserByUsername("root");
      } catch (UsernameNotFoundException e) {
      }
      Assert.assertNull(userDetails1);
      UserDetails userDetails2 = accountService.loadUserByUsername("serengeti");
      assertNotNull(userDetails2);
      TestFileUtils.deleteXMLFile(usrXmlFile);
      Users users2 = new Users();
      User user2 = new User();
      user2.setName("*");
      users2.setUsers(Arrays.asList(user2));
      TestFileUtils.createXMLFile(users2, usrXmlFile);
      userDetails1 = accountService.loadUserByUsername("root");
      assertNotNull(userDetails1);
      assertEquals(userDetails1.getUsername(), "Guest");
View Full Code Here

            return;
         }
      };

      Users users = new Users();
      User user = new User();
      user.setName("serengeti");
      users.setUsers(Arrays.asList(user));

      String confPath = System.getProperties().get("serengeti.home.dir") + File.separator + "conf";
      new File(confPath).mkdir();
      String userXmlPath = confPath + File.separator + UsersFile;
View Full Code Here

TOP

Related Classes of com.vmware.bdd.entity.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.