Search in sources :

Example 1 with WormholeUserDetails

use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample1.

// query by currentUser
@Test
public void facilitySoftwareQueryByPageExample1() 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>();
    // not admin
    roles.add("queryFacility");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setUserId("5b7d208d55368540fcba1692");
    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()));
    } 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 2 with WormholeUserDetails

use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.

the class SDDCSoftwareControllerTest method createuser.

WormholeUserDetails createuser() {
    WormholeUserDetails user = new WormholeUserDetails();
    user.setUserId("1001");
    return user;
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails)

Example 3 with WormholeUserDetails

use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.

the class AuthControllerTest method readOneUserByUserNameExample1.

@Test
public void readOneUserByUserNameExample1() throws Exception {
    WormholeUserDetails userdetail = new WormholeUserDetails();
    String userId = UUID.randomUUID().toString();
    userdetail.setUserId(userId);
    List<String> rolenames = new ArrayList<String>();
    rolenames.add("sysuser");
    WormholeUser sysuser = new WormholeUser();
    sysuser.setRoleNames(rolenames);
    sysuser.setId(userId);
    sysuser.setUserName("lucy");
    userRepository.save(sysuser);
    Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
    this.mockMvc.perform(get("/v1/auth/user/username/" + sysuser.getUserName() + "")).andExpect(status().isOk()).andReturn();
    userRepository.deleteById(sysuser.getId());
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with WormholeUserDetails

use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.

the class AuthControllerTest method readOneUserByNameExample.

@Test
public void readOneUserByNameExample() throws Exception {
    WormholeUserDetails userdetail = new WormholeUserDetails();
    String userId = UUID.randomUUID().toString();
    userdetail.setUserId(userId);
    List<String> rolenames = new ArrayList<String>();
    rolenames.add("admin");
    WormholeUser adminUser = new WormholeUser();
    adminUser.setRoleNames(rolenames);
    adminUser.setId(userId);
    userRepository.save(adminUser);
    Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
    WormholeUser user = createUser();
    userRepository.save(user);
    this.mockMvc.perform(get("/v1/auth/user/username/{userName}", user.getUserName())).andExpect(status().isOk()).andDo(document("AuthController-readOneUserByUserName-example", pathParameters(parameterWithName("userName").description("The name of user")), responseFields(fieldWithPath("id").description("ID of User, created by flowgate"), fieldWithPath("userName").description("userName.").type(JsonFieldType.STRING), fieldWithPath("gender").description("gender").type(JsonFieldType.NUMBER), fieldWithPath("password").description("password"), fieldWithPath("mobile").description("mobile").type(JsonFieldType.STRING), fieldWithPath("status").description("status").type(JsonFieldType.NUMBER), fieldWithPath("createTime").description("createTime").type(Date.class), fieldWithPath("emailAddress").description("emailAddress").type(JsonFieldType.STRING), fieldWithPath("roleNames").description("roleNames").type(List.class), fieldWithPath("userGroupIDs").description("userGroupIDs").type(List.class), fieldWithPath("lastPasswordResetDate").description("lastPasswordResetDate").type(JsonFieldType.NUMBER)))).andReturn();
    userRepository.deleteById(userId);
    userRepository.deleteById(user.getId());
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with WormholeUserDetails

use of com.vmware.flowgate.util.WormholeUserDetails in project flowgate by vmware.

the class AuthController method getPrivilegeName.

@RequestMapping(value = "/privileges", method = RequestMethod.GET)
public Set<String> getPrivilegeName(HttpServletRequest request) {
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    AuthorityUtil util = new AuthorityUtil();
    return util.getPrivilege(user);
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) AuthorityUtil(com.vmware.flowgate.util.AuthorityUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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