use of org.springframework.security.core.context.SecurityContextImpl in project spring-security by spring-projects.
the class Gh3409Tests method unauthenticatedNullAuthenitcation.
@Test
public void unauthenticatedNullAuthenitcation() throws Exception {
// @formatter:off
this.mockMvc.perform(get("/").with(securityContext(new SecurityContextImpl())));
this.mockMvc.perform(get("/")).andExpect(unauthenticated());
// @formatter:on
}
use of org.springframework.security.core.context.SecurityContextImpl in project head by mifos.
the class AuthenticationAuthorizationServiceFacadeImpl method reloadUserDetailsForSecurityContext.
@Override
public void reloadUserDetailsForSecurityContext(String username) {
UserDetails userSecurityDetails = loadUserByUsername(username);
MifosUser reloadedUserDetails = (MifosUser) userSecurityDetails;
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext == null) {
securityContext = new SecurityContextImpl();
SecurityContextHolder.setContext(securityContext);
}
Authentication authentication = new UsernamePasswordAuthenticationToken(reloadedUserDetails, reloadedUserDetails, reloadedUserDetails.getAuthorities());
securityContext.setAuthentication(authentication);
}
use of org.springframework.security.core.context.SecurityContextImpl in project head by mifos.
the class SavingsIntPostingHelper method execute.
@Override
public void execute(final long scheduledFireTime) throws BatchJobException {
MifosUser principal = createMifosAdminUser();
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext == null) {
securityContext = new SecurityContextImpl();
SecurityContextHolder.setContext(securityContext);
}
if (securityContext.getAuthentication() == null || !securityContext.getAuthentication().isAuthenticated()) {
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal, principal.getAuthorities());
securityContext.setAuthentication(authentication);
}
LocalDate dateOfBatchJob = new LocalDate(scheduledFireTime);
List<String> errorList = new ArrayList<String>();
try {
this.savingsServiceFacade.postInterestForLastPostingPeriod(dateOfBatchJob);
} catch (BusinessRuleException e) {
errorList.add(e.getMessageKey());
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
use of org.springframework.security.core.context.SecurityContextImpl in project Asqatasun by Asqatasun.
the class AuditSetUpControllerTest method setUpMockAuthenticationContext.
private void setUpMockAuthenticationContext() {
// initialise the context with the user identified by the email
// "test1@test.com" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
TgolUserDetails tud = new TgolUserDetails("test1@test.com", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("test1@test.com").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("test1@test.com").anyTimes();
replay(mockAuthenticationDetails);
}
use of org.springframework.security.core.context.SecurityContextImpl in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method setUpSecurityContextForClientOnly.
private void setUpSecurityContextForClientOnly(String clientId, Set<String> scopes) {
SecurityContextImpl securityContext = new SecurityContextImpl();
OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
securityContext.setAuthentication(mockedAuthentication);
SecurityContextHolder.setContext(securityContext);
when(mockedAuthentication.getPrincipal()).thenReturn(new ProfileEntity(clientId));
when(mockedAuthentication.isClientOnly()).thenReturn(true);
OAuth2Request authorizationRequest = new OAuth2Request(Collections.<String, String>emptyMap(), clientId, Collections.<GrantedAuthority>emptyList(), true, scopes, Collections.<String>emptySet(), null, Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap());
when(mockedAuthentication.getOAuth2Request()).thenReturn(authorizationRequest);
}
Aggregations