Search in sources :

Example 61 with SecurityContextImpl

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
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Test(org.junit.Test)

Example 62 with SecurityContextImpl

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);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 63 with SecurityContextImpl

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);
    }
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) BusinessRuleException(org.mifos.service.BusinessRuleException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) LocalDate(org.joda.time.LocalDate)

Example 64 with SecurityContextImpl

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);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) TgolUserDetails(org.asqatasun.webapp.security.userdetails.TgolUserDetails) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) AuthenticationDetails(org.springframework.security.authentication.AuthenticationDetails)

Example 65 with SecurityContextImpl

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);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Aggregations

SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)69 Authentication (org.springframework.security.core.Authentication)48 SecurityContext (org.springframework.security.core.context.SecurityContext)46 MifosUser (org.mifos.security.MifosUser)38 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)38 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 Test (org.junit.Test)18 Before (org.junit.Before)16 GrantedAuthority (org.springframework.security.core.GrantedAuthority)15 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)11 ArrayList (java.util.ArrayList)8 TgolUserDetails (org.asqatasun.webapp.security.userdetails.TgolUserDetails)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)5 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 Money (org.mifos.framework.util.helpers.Money)4 BigDecimal (java.math.BigDecimal)3