Search in sources :

Example 1 with TgolUserDetails

use of org.asqatasun.webapp.security.userdetails.TgolUserDetails in project Asqatasun by Asqatasun.

the class UserManagementControllerTest 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, mockAdminUser);
    mockAuthentication = createMock(Authentication.class);
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    expect(mockAuthentication.getName()).andReturn("admin@test.com").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    replay(mockAuthentication);
}
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) ArrayList(java.util.ArrayList)

Example 2 with TgolUserDetails

use of org.asqatasun.webapp.security.userdetails.TgolUserDetails in project Asqatasun by Asqatasun.

the class PageListControllerTest 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();
    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 3 with TgolUserDetails

use of org.asqatasun.webapp.security.userdetails.TgolUserDetails in project Asqatasun by Asqatasun.

the class ContractControllerTest 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();
    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 4 with TgolUserDetails

use of org.asqatasun.webapp.security.userdetails.TgolUserDetails in project Asqatasun by Asqatasun.

the class HomeControllerTest 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 5 with TgolUserDetails

use of org.asqatasun.webapp.security.userdetails.TgolUserDetails in project Asqatasun by Asqatasun.

the class AbstractController method updateCurrentUser.

/**
     * 
     * @param user 
     */
protected void updateCurrentUser(User user) {
    TgolUserDetails userDetails = ((TgolUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    userDetails.updateUser(user);
}
Also used : TgolUserDetails(org.asqatasun.webapp.security.userdetails.TgolUserDetails)

Aggregations

TgolUserDetails (org.asqatasun.webapp.security.userdetails.TgolUserDetails)6 Authentication (org.springframework.security.core.Authentication)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)5 AuthenticationDetails (org.springframework.security.authentication.AuthenticationDetails)4 ArrayList (java.util.ArrayList)1