本文整理汇总了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()));
}
示例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()));
}
示例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()));
}
示例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);
}
示例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.");
}
示例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.");
}
示例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);
}
示例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;
}
};
}
示例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));
}
示例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());
}
示例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));
}
示例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));
}
示例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));
}
示例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()));
}
示例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()));
}