use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.
the class AuthControllerTest method readOneUserByUserNameExample2.
@Test
public void readOneUserByUserNameExample2() throws Exception {
expectedEx.expect(WormholeRequestException.class);
expectedEx.expectMessage("Forbidden");
String userId = UUID.randomUUID().toString();
WormholeUserDetails userdetail = new WormholeUserDetails();
userdetail.setUserId(userId);
List<String> rolenames = new ArrayList<String>();
rolenames.add("sysuser");
WormholeUser sysuser = createUser();
sysuser.setId(userId);
sysuser.setRoleNames(rolenames);
sysuser.setUserName("lucy");
userRepository.save(sysuser);
Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
MvcResult result = this.mockMvc.perform(get("/v1/auth/user/username/tom")).andExpect(status().isForbidden()).andReturn();
if (result.getResolvedException() != null) {
userRepository.deleteById(sysuser.getId());
throw result.getResolvedException();
}
}
use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.
the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageAndTypeExample.
// facilitySoftwareConfigsByType
@Test
public void facilitySoftwareQueryByPageAndTypeExample() throws Exception {
WormholeUserDetails userDeails = createuser();
userDeails.setUserId("5b7d208d55368540fcba1692");
Mockito.doReturn(userDeails).when(tokenService).getCurrentUser(any());
WormholeUser user = new WormholeUser();
user.setId("5b7d208d55368540fcba1692");
List<String> roles = new ArrayList<String>();
roles.add("admin");
user.setRoleNames(roles);
userRepository.save(user);
// userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
facilitySoftwareRepository.save(facilitySoftware);
int pageNumber = 1;
int pageSize = 5;
try {
this.mockMvc.perform(get("/v1/facilitysoftware/page/{pageNumber}/pagesize/{pageSize}", pageNumber, pageSize).param("softwaretypes", "Nlyte")).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId())).andExpect(jsonPath("$..content[0].type").value(facilitySoftware.getType().name())).andDo(document("facilitySoftware-queryByTypeAndPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20")), requestParameters(parameterWithName("softwaretypes").description("A list of software, maybe contain Nlyte/PowerIQ/InfoBlox/OpenManage/Labsdb"))));
} finally {
facilitySoftwareRepository.deleteById(facilitySoftware.getId());
userRepository.deleteById(user.getId());
}
}
use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.
the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample.
// admin can find all facilitySoftwareConfigs
@Test
public void facilitySoftwareQueryByPageExample() throws Exception {
WormholeUserDetails userDeails = createuser();
userDeails.setUserId("5b7d208d55368540fcba1692");
Mockito.doReturn(userDeails).when(tokenService).getCurrentUser(any());
WormholeUser user = new WormholeUser();
user.setId("5b7d208d55368540fcba1692");
List<String> roles = new ArrayList<String>();
roles.add("admin");
user.setRoleNames(roles);
userRepository.save(user);
// userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
facilitySoftwareRepository.save(facilitySoftware);
int pageNumber = 1;
int pageSize = 5;
try {
this.mockMvc.perform(get("/v1/facilitysoftware/page/{pageNumber}/pagesize/{pageSize}", pageNumber, pageSize)).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId())).andDo(document("facilitySoftware-queryByPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20"))));
} finally {
facilitySoftwareRepository.deleteById(facilitySoftware.getId());
userRepository.deleteById(user.getId());
}
}
use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.
the class FacilitySoftwareControllerTest method createuser.
WormholeUserDetails createuser() {
WormholeUserDetails user = new WormholeUserDetails();
user.setUserId("1");
return user;
}
use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.
the class AuthenticationTokenFilter method doFilterInternal.
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String resUrl = request.getRequestURI();
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
if (user != null && SecurityContextHolder.getContext().getAuthentication() == null) {
logger.debug("checking authentication for user " + user.getUsername());
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(user.getUsername(), "N/A", user.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authentication);
filterChain.doFilter(request, response);
} else if (InitializeConfigureData.unauthirzedURLs.containsKey(resUrl) && request.getMethod().equals(InitializeConfigureData.unauthirzedURLs.get(resUrl))) {
filterChain.doFilter(request, response);
} else {
unauthorizedHandler.commence(request, response, null);
}
}
Aggregations