Package se.inera.ifv.casebox.core.entity

Examples of se.inera.ifv.casebox.core.entity.User


    @PersistenceContext
    EntityManager entityManager;

    @Test
    public void createUser() throws Exception {
        User user = userService.createUser("test", "test1", "Kalle", "Anka");

        Assert.assertNotNull(user);
        Assert.assertEquals(user.getFirstname(), "Kalle");

        try {
            user = userService.createUser("test", "test1", "Kalle", "Anka");
            Assert.fail("Should not be able to create user with same name");
        } catch (CaseboxException e) {
            Assert.assertEquals("error.user.alreadyexist", e.getMessageCode());
        }

        user = userService.createUser("test1", "test1", "Kalle", "Anka");

        Assert.assertNotNull(user);
        Assert.assertEquals(user.getUsername(), "test1");
        ITable result = getConnection().createQueryTable("AUTHORITIES", "SELECT * FROM AUTHORITIES WHERE USERNAME = 'test1'");
        Assert.assertEquals("ROLE_USER", result.getValue(0, "AUTHORITY"));
    }
View Full Code Here


   
    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);

    public User createUser(String username, String password, String firstName, String lastName) throws CaseboxException {

        User user = userRepository.findByUsername(username);
        if (user != null) {
            log.error("Username {} already exist, can not create user.", new Object[] {username});
            throw new CaseboxException("error.user.alreadyexist");
        }
       
        user = new User(username, password, true, firstName, lastName);
        Authority authority = new Authority(user, AuthorityRole.ROLE_USER);
        user.getAuthorities().add(authority);
       
        log.debug("Create user {}.", new Object[]{user});
        user = userRepository.store(user);

        return user;
View Full Code Here

    public User getAuthenticatedUser() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            String username =  ((UserDetails) principal).getUsername();
            User user = userRepository.findByUsername(username);
            return user;
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of se.inera.ifv.casebox.core.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.