org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers Java Examples

The following examples show how to use org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: E2EProjectAPIControllerTest.java    From ods-provisioning-app with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {

  testUsersAndRoles.put(testAdminUsername, adminGroup);

  E2EProjectAPIControllerTest.initLocalStorage(
      realLocalStorageAdapter, E2EProjectAPIControllerTest.createTempDir(buildDir));

  apiController.setDirectStorage(realLocalStorageAdapter);

  mockMvc =
      MockMvcBuilders.webAppContextSetup(context)
          .apply(SecurityMockMvcConfigurers.springSecurity())
          .build();

  mockHelper = new RestClientMockHelper(restClient);

  // disable mail magic
  realMailAdapter.isMailEnabled = false;

  // override configuration in application.properties, some tests depends on cleanupAllowed
  apiController.setCleanupAllowed(true);

  when(mockAuthnzAdapter.getUserName()).thenReturn(testAdminUsername);
  when(mockAuthnzAdapter.getUserPassword()).thenReturn(TEST_VALID_CREDENTIAL);
}
 
Example #2
Source File: AeroRemoteApiControllerTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    mvc = MockMvcBuilders
            .webAppContextSetup(context)
            .alwaysDo(print())
            .apply(SecurityMockMvcConfigurers.springSecurity())
            .addFilters(new OpenCasStorageSessionForRequestFilter())
            .build();
    
    if (!initialized) {
        userRepository.create(new User("admin", Role.ROLE_ADMIN));
        initialized = true;
        
        FileSystemUtils.deleteRecursively(new File("target/RemoteApiController2Test"));
    }
}
 
Example #3
Source File: AuditEntryControllerTestIT.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() throws AlertDatabaseConstraintException {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
    cleanup();

    ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    providerConfigEnabled.setFieldValue("true");
    ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    providerConfigName.setFieldValue("My Black Duck Config");

    ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackduckUrl.setFieldValue("https://a-blackduck-server");
    ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackduckApiKey.setFieldValue("123456789012345678901234567890123456789012345678901234567890");
    ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackduckTimeout.setFieldValue("300");

    List<ConfigurationFieldModel> providerConfigFields = List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout);
    providerConfigModel = configurationAccessor.createConfiguration(new BlackDuckProviderKey(), ConfigContextEnum.GLOBAL, providerConfigFields);
    mockNotificationContent.setProviderConfigId(providerConfigModel.getConfigurationId());
}
 
Example #4
Source File: UserControllerIntegrationTest.java    From java-starthere with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    RestAssuredMockMvc.webAppContextSetup(webApplicationContext);

    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
                             .apply(SecurityMockMvcConfigurers.springSecurity())
                             .build();
}
 
Example #5
Source File: RoleResourceTest.java    From heimdall with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() {
     SimpleGrantedAuthority readRole = new SimpleGrantedAuthority("READ_ROLE");
     SimpleGrantedAuthority createRole = new SimpleGrantedAuthority("CREATE_ROLE");
     SimpleGrantedAuthority deleteRole = new SimpleGrantedAuthority("DELETE_ROLE");
     SimpleGrantedAuthority updateRole = new SimpleGrantedAuthority("UPDATE_ROLE");
     Authentication authentication =
             new UsernamePasswordAuthenticationToken("tester", "password",
                     Arrays.asList(readRole, createRole, deleteRole, updateRole));

     Mockito.when(tokenAuthenticationService.getAuthentication(Mockito.any(), Mockito.any())).thenReturn(authentication);
     mockMvc = MockMvcBuilders.webAppContextSetup(context)
             .apply(SecurityMockMvcConfigurers.springSecurity()).addFilter(filterChain).build();
}
 
Example #6
Source File: AccessTokenResourceTest.java    From heimdall with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() {

    Authentication authentication =
            new UsernamePasswordAuthenticationToken("tester", "password",
                    Collections.singletonList(new SimpleGrantedAuthority("CREATE_ACCESSTOKEN")));

    Mockito.when(tokenAuthenticationService.getAuthentication(Mockito.any(), Mockito.any())).thenReturn(authentication);
    mockMvc = MockMvcBuilders.webAppContextSetup(context)
            .apply(SecurityMockMvcConfigurers.springSecurity()).addFilter(filterChain).build();
}
 
Example #7
Source File: UserResourceTest.java    From heimdall with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() {
     SimpleGrantedAuthority readUser = new SimpleGrantedAuthority("READ_USER");
     SimpleGrantedAuthority createUser = new SimpleGrantedAuthority("CREATE_USER");
     SimpleGrantedAuthority deleteUser = new SimpleGrantedAuthority("DELETE_USER");
     SimpleGrantedAuthority updateUser = new SimpleGrantedAuthority("UPDATE_USER");
     Authentication authentication =
             new UsernamePasswordAuthenticationToken("tester", "password",
                     Arrays.asList(readUser, createUser, deleteUser, updateUser));

     Mockito.when(tokenAuthenticationService.getAuthentication(Mockito.any(), Mockito.any())).thenReturn(authentication);
     mockMvc = MockMvcBuilders.webAppContextSetup(context)
             .apply(SecurityMockMvcConfigurers.springSecurity()).addFilter(filterChain).build();
}
 
Example #8
Source File: ManagementIntegrationTest.java    From credhub with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  mockMvc = MockMvcBuilders
    .webAppContextSetup(webApplicationContext)
    .apply(SecurityMockMvcConfigurers.springSecurity())
    .build();
}
 
Example #9
Source File: ManualSecurityIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mockMvc = MockMvcBuilders.webAppContextSetup(wac).apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
 
Example #10
Source File: UserControllerUnitTest.java    From java-starthere with MIT License 4 votes vote down vote up
@Before
public void setUp() throws Exception
{
    userList = new ArrayList<>();

    Role r1 = new Role("admin");
    r1.setRoleid(1);
    Role r2 = new Role("user");
    r2.setRoleid(2);
    Role r3 = new Role("data");
    r3.setRoleid(3);

    // admin, data, user
    ArrayList<UserRoles> admins = new ArrayList<>();
    admins.add(new UserRoles(new User(), r1));
    admins.add(new UserRoles(new User(), r2));
    admins.add(new UserRoles(new User(), r3));
    User u1 = new User("admin", "ILuvM4th!", "[email protected]", admins);

    u1.getUseremails()
      .add(new Useremail(u1, "[email protected]"));
    u1.getUseremails().get(0).setUseremailid(10);

    u1.getUseremails()
      .add(new Useremail(u1, "[email protected]"));
    u1.getUseremails().get(1).setUseremailid(11);

    u1.setUserid(101);
    userList.add(u1);

    // data, user
    ArrayList<UserRoles> datas = new ArrayList<>();
    datas.add(new UserRoles(new User(), r3));
    datas.add(new UserRoles(new User(), r2));
    User u2 = new User("cinnamon", "1234567", "[email protected]", datas);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(0).setUseremailid(20);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(1).setUseremailid(21);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(2).setUseremailid(22);

    u2.setUserid(102);
    userList.add(u2);

    // user
    ArrayList<UserRoles> users = new ArrayList<>();
    users.add(new UserRoles(new User(), r1));
    User u3 = new User("testingbarn", "ILuvM4th!", "[email protected]", users);

    u3.getUseremails()
      .add(new Useremail(u3, "[email protected]"));
    u3.getUseremails().get(0).setUseremailid(30);

    u3.setUserid(103);
    userList.add(u3);

    users = new ArrayList<>();
    users.add(new UserRoles(new User(), r2));
    User u4 = new User("testingcat", "password", "[email protected]", users);
    u4.setUserid(104);
    userList.add(u4);

    users = new ArrayList<>();
    users.add(new UserRoles(new User(), r2));
    User u5 = new User("testingdog", "password", "[email protected]", users);
    u5.setUserid(105);
    userList.add(u5);

    System.out.println("\n*** Seed Data ***");
    for (User u : userList)
    {
        System.out.println(u);
    }
    System.out.println("*** Seed Data ***\n");

    RestAssuredMockMvc.webAppContextSetup(webApplicationContext);

    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
                             .apply(SecurityMockMvcConfigurers.springSecurity())
                             .build();
}
 
Example #11
Source File: ResourceControllerUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
        .apply(SecurityMockMvcConfigurers.springSecurity())
        .build();
}
 
Example #12
Source File: BootMvcWithSecurityBaseITest.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@Override
public MockMvc buildMockMvc(WebApplicationContext webApplicationContext){
	return MockMvcBuilders.webAppContextSetup(webApplicationContext)
			.apply(SecurityMockMvcConfigurers.springSecurity())
			.build();
}
 
Example #13
Source File: CorsTest.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setup() {
    final DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(context)
            .apply(SecurityMockMvcConfigurers.springSecurity()).dispatchOptions(true);
    mvc = builder.build();
}
 
Example #14
Source File: JobConfigControllerTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
 
Example #15
Source File: CertificateControllerTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void init() throws Exception {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
    certTestUtil.init(alertProperties);
}
 
Example #16
Source File: HomeControllerTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
 
Example #17
Source File: DescriptorControllerSpeedTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
 
Example #18
Source File: UploadEndpointControllerTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void initialize() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
 
Example #19
Source File: SystemControllerTestIT.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void initialize() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
    systemActions = Mockito.mock(SystemActions.class);
}
 
Example #20
Source File: GreetingsRestControllerTest.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	this.mvc = MockMvcBuilders.webAppContextSetup(this.context)
			.apply(SecurityMockMvcConfigurers.springSecurity()).build();
}