@Test public void successfulWhoAmIWithoutFullName() { SecurityContext sec = mock(SecurityContext.class); Principal principal = mock(Principal.class); when(principal.getName()).thenReturn("testuser"); when(sec.getUserPrincipal()).thenReturn(principal); NamespacedOpenShiftClient client = mock(NamespacedOpenShiftClient.class); @SuppressWarnings("unchecked") Resource<User,DoneableUser> user = mock(Resource.class); when(user.get()).thenReturn(new UserBuilder().withNewMetadata().withName("testuser").and().build()); @SuppressWarnings("unchecked") NonNamespaceOperation<User, UserList, DoneableUser, Resource<User, DoneableUser>> users = mock(NonNamespaceOperation.class); when(users.withName("testuser")).thenReturn(user); when(client.users()).thenReturn(users); SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken("testuser", "doesn'tmatter")); UserConfigurationProperties properties = new UserConfigurationProperties(); properties.setMaxDeploymentsPerUser(1); UserHandler userHandler = new UserHandler(null, new OpenShiftServiceImpl(client, null), properties); io.syndesis.common.model.user.User whoAmI = userHandler.whoAmI(sec); Assertions.assertThat(whoAmI).isNotNull(); Assertions.assertThat(whoAmI.getUsername()).isEqualTo("testuser"); Assertions.assertThat(whoAmI.getFullName()).isEmpty(); }
@Path("~") @GET @Produces(MediaType.APPLICATION_JSON) public User whoAmI(@Context SecurityContext sec) { String username = sec.getUserPrincipal().getName(); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(username); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); }
UserHandler extends BaseHandler implements Lister<User>, Getter<User> { @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) public User whoAmI(@Context SecurityContext sec) { String username = sec.getUserPrincipal().getName(); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(username); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); } }
UserHandler extends BaseHandler implements Lister<User>, Getter<User> { @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) public User whoAmI(@Context SecurityContext sec) { String username = sec.getUserPrincipal().getName(); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(username); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); } @Autowired  UserHandler(DataManager dataMgr, OpenShiftService openShiftService, UserConfigurationProperties properties); }
UserHandler extends BaseHandler implements Lister<User>, Getter<User> { @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) public User whoAmI(@Context SecurityContext sec) { String username = sec.getUserPrincipal().getName(); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(username); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); } @Autowired  UserHandler(DataManager dataMgr, OpenShiftService openShiftService, UserConfigurationProperties properties); @Override Kind resourceKind(); @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) User whoAmI(@Context SecurityContext sec); @Path("~/quota") @GET @Produces(MediaType.APPLICATION_JSON) Quota quota(@Context SecurityContext sec); }
UserHandler extends BaseHandler implements Lister<User>, Getter<User> { @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) public User whoAmI(@Context SecurityContext sec) { String username = sec.getUserPrincipal().getName(); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(username); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); } @Autowired  UserHandler(DataManager dataMgr, OpenShiftService openShiftService, UserConfigurationProperties properties); @Override Kind resourceKind(); @Path("~") @GET @Produces(MediaType.APPLICATION_JSON) User whoAmI(@Context SecurityContext sec); @Path("~/quota") @GET @Produces(MediaType.APPLICATION_JSON) Quota quota(@Context SecurityContext sec);  }