List of usage examples for org.springframework.security.authentication TestingAuthenticationToken TestingAuthenticationToken
public TestingAuthenticationToken(Object principal, Object credentials)
From source file:org.finra.herd.service.JobServiceTest.java
@Test public void testGetJobAssertAccessDeniedGivenJobRunningAndUserDoesNotHavePermissions() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH); Job job = jobService.createAndStartJob( jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); String username = "username"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(username); applicationUser.setNamespaceAuthorizations(new HashSet<>()); SecurityContextHolder.getContext()//from w ww . j a v a 2 s . c o m .setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); try { jobService.getJob(job.getId(), false); fail(); } catch (Exception e) { assertEquals(AccessDeniedException.class, e.getClass()); assertEquals(String.format("User \"%s\" does not have \"[READ]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage()); } }
From source file:org.finra.herd.service.JobServiceTest.java
@Test public void testGetJobAssertNoErrorGivenJobRunningAndUserDoesHasPermissions() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH); Job job = jobService.createAndStartJob( jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); String username = "username"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(username); applicationUser.setNamespaceAuthorizations(new HashSet<>()); applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ))); SecurityContextHolder.getContext()//from w w w. j a va 2s . c o m .setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); try { jobService.getJob(job.getId(), false); } catch (AccessDeniedException e) { fail(); } }
From source file:org.finra.herd.service.JobServiceTestHelper.java
/** * Sets specified namespace authorizations for the current user by updating the security context. * * @param namespace the namespace// w w w . java 2 s. c o m * @param namespacePermissions the list of namespace permissions */ public void setCurrentUserNamespaceAuthorizations(String namespace, List<NamespacePermissionEnum> namespacePermissions) { String username = AbstractServiceTest.USER_ID; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(username); Set<NamespaceAuthorization> namespaceAuthorizations = new LinkedHashSet<>(); namespaceAuthorizations.add(new NamespaceAuthorization(namespace, namespacePermissions)); applicationUser.setNamespaceAuthorizations(namespaceAuthorizations); SecurityContextHolder.getContext() .setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); }
From source file:org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProviderTests.java
License:asdf
@Test public void authenticateUnsupportedAuthentication() { assertThat(provider.authenticate(new TestingAuthenticationToken("user", "password"))).isNull(); }
From source file:org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServicesTests.java
@Test public void obtainPasswordReturnsNullForTokenWithNullCredentials() throws Exception { TestingAuthenticationToken token = new TestingAuthenticationToken("username", null); assertThat(services.retrievePassword(token)).isNull(); }