当前位置: 首页>>代码示例>>Java>>正文


Java Authority类代码示例

本文整理汇总了Java中com.mycompany.myapp.domain.Authority的典型用法代码示例。如果您正苦于以下问题:Java Authority类的具体用法?Java Authority怎么用?Java Authority使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Authority类属于com.mycompany.myapp.domain包,在下文中一共展示了Authority类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUser

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
public User createUser(String login, String password, String firstName, String lastName, String email,
    String langKey) {

    User newUser = new User();
    Authority authority = authorityRepository.findOne(AuthoritiesConstants.USER);
    Set<Authority> authorities = new HashSet<>();
    String encryptedPassword = passwordEncoder.encode(password);
    newUser.setLogin(login);
    // new user gets initially a generated password
    newUser.setPassword(encryptedPassword);
    newUser.setFirstName(firstName);
    newUser.setLastName(lastName);
    newUser.setEmail(email);
    newUser.setLangKey(langKey);
    // new user is not active
    newUser.setActivated(false);
    // new user gets registration key
    newUser.setActivationKey(RandomUtil.generateActivationKey());
    authorities.add(authority);
    newUser.setAuthorities(authorities);
    userRepository.save(newUser);
    log.debug("Created Information for User: {}", newUser);
    return newUser;
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:25,代码来源:UserService.java

示例2: updateUser

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
public void updateUser(String id, String login, String firstName, String lastName, String email,
    boolean activated, String langKey, Set<String> authorities) {

    userRepository
        .findOneById(id)
        .ifPresent(u -> {
            u.setLogin(login);
            u.setFirstName(firstName);
            u.setLastName(lastName);
            u.setEmail(email);
            u.setActivated(activated);
            u.setLangKey(langKey);
            Set<Authority> managedAuthorities = u.getAuthorities();
            managedAuthorities.clear();
            authorities.stream().forEach(
                authority -> managedAuthorities.add(authorityRepository.findOne(authority))
            );
            userRepository.save(u);
            log.debug("Changed Information for User: {}", u);
        });
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:22,代码来源:UserService.java

示例3: testGetExistingAccount

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
@Test
public void testGetExistingAccount() throws Exception {
    Set<Authority> authorities = new HashSet<>();
    Authority authority = new Authority();
    authority.setName(AuthoritiesConstants.ADMIN);
    authorities.add(authority);

    User user = new User();
    user.setLogin("test");
    user.setFirstName("john");
    user.setLastName("doe");
    user.setEmail("[email protected]");
    user.setAuthorities(authorities);
    when(mockUserService.getUserWithAuthorities()).thenReturn(user);

    restUserMockMvc.perform(get("/api/account")
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("$.login").value("test"))
            .andExpect(jsonPath("$.firstName").value("john"))
            .andExpect(jsonPath("$.lastName").value("doe"))
            .andExpect(jsonPath("$.email").value("[email protected]"))
            .andExpect(jsonPath("$.authorities").value(AuthoritiesConstants.ADMIN));
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:26,代码来源:AccountResourceIntTest.java

示例4: getAccount

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
/**
 * GET  /account -> get the current user.
 */
@RequestMapping(value = "/account",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<UserDTO> getAccount() {
    return Optional.ofNullable(userService.getUserWithAuthorities())
        .map(user -> {
            return new ResponseEntity<>(
                new UserDTO(
                    user.getLogin(),
                    null,
                    user.getFirstName(),
                    user.getLastName(),
                    user.getEmail(),
                    user.getLangKey(),
                    user.getAuthorities().stream().map(Authority::getName)
                        .collect(Collectors.toList())),
            HttpStatus.OK);
        })
        .orElse(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));
}
 
开发者ID:gmarziou,项目名称:jhipster-ionic,代码行数:25,代码来源:AccountResource.java

示例5: createUserInformation

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
public User createUserInformation(String login, String password, String firstName, String lastName, String email,
                                  String langKey) {

    User newUser = new User();
    Authority authority = authorityRepository.findOne("ROLE_USER");
    Set<Authority> authorities = new HashSet<>();
    String encryptedPassword = passwordEncoder.encode(password);
    newUser.setLogin(login);
    // new user gets initially a generated password
    newUser.setPassword(encryptedPassword);
    newUser.setFirstName(firstName);
    newUser.setLastName(lastName);
    newUser.setEmail(email);
    newUser.setLangKey(langKey);
    // new user is not active
    newUser.setActivated(false);
    // new user gets registration key
    newUser.setActivationKey(RandomUtil.generateActivationKey());
    authorities.add(authority);
    newUser.setAuthorities(authorities);
    userRepository.save(newUser);
    log.debug("Created Information for User: {}", newUser);
    return newUser;
}
 
开发者ID:gmarziou,项目名称:jhipster-ionic,代码行数:25,代码来源:UserService.java

示例6: testGetExistingAccount

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
@Test
public void testGetExistingAccount() throws Exception {
    Set<Authority> authorities = new HashSet<>();
    Authority authority = new Authority();
    authority.setName(AuthoritiesConstants.ADMIN);
    authorities.add(authority);

    User user = new User();
    user.setLogin("test");
    user.setFirstName("john");
    user.setLastName("doe");
    user.setEmail("[email protected]");
    user.setAuthorities(authorities);
    when(mockUserService.getUserWithAuthorities()).thenReturn(user);

    restUserMockMvc.perform(get("/api/account")
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.login").value("test"))
            .andExpect(jsonPath("$.firstName").value("john"))
            .andExpect(jsonPath("$.lastName").value("doe"))
            .andExpect(jsonPath("$.email").value("[email protected]"))
            .andExpect(jsonPath("$.roles").value(AuthoritiesConstants.ADMIN));
}
 
开发者ID:gmarziou,项目名称:jhipster-ionic,代码行数:26,代码来源:AccountResourceTest.java

示例7: authoritiesFromStrings

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
default Set<Authority> authoritiesFromStrings(Set<String> strings) {
    return strings.stream().map(string -> {
        Authority auth = new Authority();
        auth.setName(string);
        return auth;
    }).collect(Collectors.toSet());
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:8,代码来源:UserMapper.java

示例8: UserDTO

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
public UserDTO(User user) {
    this(user.getLogin(), user.getFirstName(), user.getLastName(),
        user.getEmail(), user.getActivated(), user.getLangKey(),
        user.getAuthorities().stream().map(Authority::getName)
            .collect(Collectors.toSet()));
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:7,代码来源:UserDTO.java

示例9: stringsFromAuthorities

import com.mycompany.myapp.domain.Authority; //导入依赖的package包/类
default Set<String> stringsFromAuthorities (Set<Authority> authorities) {
    return authorities.stream().map(Authority::getName)
        .collect(Collectors.toSet());
}
 
开发者ID:pierre-filliolaud,项目名称:jhipster-rethinkdb-app,代码行数:5,代码来源:UserMapper.java


注:本文中的com.mycompany.myapp.domain.Authority类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。