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


Java UserPrincipal类代码示例

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


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

示例1: shouldRetrieveTopStories

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldRetrieveTopStories() throws Exception {
    Story story = generateStory();
    Geolocation geolocation = new Geolocation();
    geolocation.setLatitude(0);
    geolocation.setLongitude(0);
    MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
    params.add("latitude",String.valueOf(geolocation.getLatitude()));
    params.add("longitude",String.valueOf(geolocation.getLongitude()));

    when(homepageService.retrieveTopStories(anyString(),any(Geolocation.class))).thenReturn(ImmutableList.of(story));

    mockMvc.perform(get("/homepage/retrieveTopStories").params(params).principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$[0].id").value(story.getId()));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:17,代码来源:HomepageControllerTest.java

示例2: shouldRetrieveHotStories

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldRetrieveHotStories() throws Exception{
    Story story = generateStory();
    Geolocation geolocation = new Geolocation();
    geolocation.setLatitude(0);
    geolocation.setLongitude(0);
    MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
    params.add("latitude",String.valueOf(geolocation.getLatitude()));
    params.add("longitude",String.valueOf(geolocation.getLongitude()));

    when(homepageService.retrieveHotStories(anyString(),any(Geolocation.class))).thenReturn(ImmutableList.of(story));

    mockMvc.perform(get("/homepage/retrieveHotStories").params(params).principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$[0].id").value(story.getId()));

}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:18,代码来源:HomepageControllerTest.java

示例3: shouldRetrieveNewStories

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldRetrieveNewStories() throws Exception{
    Story story = generateStory();
    Geolocation geolocation = new Geolocation();
    geolocation.setLatitude(0);
    geolocation.setLongitude(0);
    MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
    params.add("latitude",String.valueOf(geolocation.getLatitude()));
    params.add("longitude",String.valueOf(geolocation.getLongitude()));

    when(homepageService.retrieveNewStories(anyString(),any(Geolocation.class))).thenReturn(ImmutableList.of(story));

    mockMvc.perform(get("/homepage/retrieveNewStories").params(params).principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$[0].id").value(story.getId()));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:17,代码来源:HomepageControllerTest.java

示例4: subscribe

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@PermitAll
@GET
/**
 * Handle MQTT Subscribe Request in RESTful style
 * Granted QoS Levels will send back to client.
 * Retain Messages matched the subscriptions will NOT send back to client.
 */
public ResultEntity<List<Subscription>> subscribe(@PathParam("clientId") String clientId, @Auth UserPrincipal user) {
    List<Subscription> subscriptions = new ArrayList<>();

    // HTTP interface require valid Client Id
    if (!this.validator.isClientIdValid(clientId)) {
        logger.debug("Protocol violation: Client id {} not valid based on configuration", clientId);
        throw new ValidateException(new ErrorEntity(ErrorCode.INVALID));
    }

    // Read client's subscriptions from storage
    Map<String, MqttQoS> map = this.redis.getClientSubscriptions(clientId);
    map.forEach((topic, qos) -> subscriptions.add(new Subscription(topic, qos.value())));

    return new ResultEntity<>(subscriptions);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:23,代码来源:MqttSubscribeResource.java

示例5: checkPrincipal

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
private static void checkPrincipal(LoginContext loginContext,
        boolean principalShouldExist) {
    if (!principalShouldExist) {
        if (loginContext.getSubject().getPrincipals().size() != 0) {
            throw new RuntimeException("Test failed. Principal was not "
                    + "cleared.");
        }
        return;
    }
    for (Principal p : loginContext.getSubject().getPrincipals()) {
        if (p instanceof UserPrincipal
                && USER_NAME.equals(p.getName())) {
            //Proper principal was found, return.
            return;
        }
    }
    throw new RuntimeException("Test failed. UserPrincipal "
            + USER_NAME + " expected.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:JaasClientWithDefaultHandler.java

示例6: checkPrincipal

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
private static void checkPrincipal(LoginContext loginContext,
        boolean principalShouldExist) {
    if (!principalShouldExist) {
        if (loginContext.getSubject().getPrincipals().size() != 0) {
            throw new RuntimeException("Test failed. Principal was not "
                    + "cleared.");
        }
        return;
    }
    for (Principal p : loginContext.getSubject().getPrincipals()) {
        if (p instanceof UserPrincipal
                && USER_NAME.equals(p.getName())) {
            //Proper principal was found, return.
            return;
        }
    }
    throw new RuntimeException("Test failed. UserPrincipal "
            + USER_NAME + " expected.");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:JaasClient.java

示例7: subscribe

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
/**
 * Get client's exist subscriptions
 */
@PermitAll
@GET
public ResultEntity<List<Subscription>> subscribe(@PathParam("clientId") String clientId, @Auth UserPrincipal user) {
    List<Subscription> subscriptions = new ArrayList<>();

    // HTTP interface require valid Client Id
    if (!this.validator.isClientIdValid(clientId)) {
        logger.debug("Protocol violation: Client id {} not valid based on configuration", clientId);
        throw new ValidateException(new ErrorEntity(ErrorCode.INVALID));
    }

    // Read client's subscriptions from storage
    Map<String, MqttQoS> map = this.storage.getClientSubscriptions(clientId);
    map.forEach((topic, qos) -> subscriptions.add(new Subscription(topic, qos.value())));

    return new ResultEntity<>(subscriptions);
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:21,代码来源:MqttSubscribeResource.java

示例8: create

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Override
public SecurityContext create(final String userName, String credential, final boolean isSecure, final String authcScheme, String host) {
    final String principal = userName;
    return new SecurityContext() {
        @Override
        public Principal getUserPrincipal() {
            return new UserPrincipal(principal);
        }

        @Override
        public boolean isUserInRole(String role) {
            return false;
        }

        @Override
        public boolean isSecure() {
            return isSecure;
        }

        @Override
        public String getAuthenticationScheme() {
            return authcScheme;
        }
    };
}
 
开发者ID:graylog-labs,项目名称:jersey-netty,代码行数:26,代码来源:DefaultSecurityContextFactory.java

示例9: shouldCreateStory

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldCreateStory() throws Exception {
    StoryRequest storyRequest = new StoryRequest("test","test","1",new Geolocation(0.0,0.0));

    when(storyService.createStory(anyString(), any(StoryRequest.class))).thenReturn(Constants.OK);

    mockMvc.perform(post("/story/create")
                .content(asJsonString(storyRequest))
                .contentType(MediaType.APPLICATION_JSON).principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(mvcResult -> Constants.OK.equals(mvcResult));

}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:14,代码来源:StoryControllerTest.java

示例10: shouldDeleteStory

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldDeleteStory() throws Exception {
    when(storyService.deleteStory(anyString(), anyString())).thenReturn(Constants.OK);

    mockMvc.perform(delete("/story/delete/test").principal(new UserPrincipal("testUserId")))
            .andExpect(mvcResult -> Constants.OK.equals(mvcResult))
            .andExpect(status().isOk());
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:9,代码来源:StoryControllerTest.java

示例11: shouldCreateComment

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldCreateComment() throws Exception{
    CommentRequest comment = new CommentRequest("testHeader","test");

    when(storyService.createComment(eq("testUserId"), anyString(), any(CommentRequest.class))).thenReturn(Constants.OK);

    mockMvc.perform(post("/story/comment/testStoryId").contentType(MediaType.APPLICATION_JSON)
                        .content(asJsonString(comment)).principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(mvcResult -> Constants.OK.equals(mvcResult));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:12,代码来源:StoryControllerTest.java

示例12: shouldDeleteComment

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldDeleteComment() throws Exception{
    when(storyService.deleteComment(anyString(), anyString())).thenReturn(Constants.OK);

    mockMvc.perform(delete("/story/uncomment/testCommentId").principal(new UserPrincipal("testUserId")))
            .andExpect(status().isOk())
            .andExpect(mvcResult -> Constants.OK.equals(mvcResult));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:9,代码来源:StoryControllerTest.java

示例13: shouldCreateGroup

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldCreateGroup() throws Exception{
    GroupRequest groupRequest = new GroupRequest(null, "testName", "testAbout");

    when(administrativeService.createGroup(anyString(), any(GroupRequest.class))).thenReturn(Constants.OK);

    mockMvc.perform(post("/administrative/create").principal(new UserPrincipal("testUserId"))
            .content(asJsonString(groupRequest))
            .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(mvcResult -> Constants.OK.equals(mvcResult));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:AdministrativeControllerTest.java

示例14: shouldRetrieveGroup

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldRetrieveGroup() throws Exception{
    Group group = new Group("testModerator", "testName", "testAbout", null);

    when(administrativeService.retrieveGroup(anyString())).thenReturn(group);

    mockMvc.perform(get("/administrative/retrieve/testGroupId").principal(new UserPrincipal("testUserId"))
            .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.moderator").value(group.getModerator()));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:12,代码来源:AdministrativeControllerTest.java

示例15: shouldRetrieveMyGroups

import com.sun.security.auth.UserPrincipal; //导入依赖的package包/类
@Test
public void shouldRetrieveMyGroups() throws Exception{
    Group group = new Group("testModerator", "testName", "testAbout", null);

    when(administrativeService.retrieveMyGroups(anyString())).thenReturn(Arrays.asList(group));

    mockMvc.perform(get("/administrative/retrieveMyGroups").principal(new UserPrincipal("testModerator"))
            .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$[0].moderator").value(group.getModerator()));
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:12,代码来源:AdministrativeControllerTest.java


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