Search in sources :

Example 21 with WormholeUserDetails

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();
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) MvcResult(org.springframework.test.web.servlet.MvcResult) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with WormholeUserDetails

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());
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with WormholeUserDetails

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());
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 24 with WormholeUserDetails

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;
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails)

Example 25 with WormholeUserDetails

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);
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) WebAuthenticationDetailsSource(org.springframework.security.web.authentication.WebAuthenticationDetailsSource)

Aggregations

WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)29 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)18 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)9 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AuthToken (com.vmware.flowgate.common.model.AuthToken)3 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)3 AuthorityUtil (com.vmware.flowgate.util.AuthorityUtil)3 IOException (java.io.IOException)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2 Optional (java.util.Optional)2 Cookie (javax.servlet.http.Cookie)2 PageRequest (org.springframework.data.domain.PageRequest)2