Search in sources :

Example 1 with NullUser

use of com.thoughtworks.go.domain.NullUser in project gocd by gocd.

the class GoCacheTest method shouldAllowAddingUnpersistedNullObjects.

@Test
public void shouldAllowAddingUnpersistedNullObjects() {
    NullUser user = new NullUser();
    goCache.put("loser_user", user);
    assertThat(goCache.get("loser_user"), is(user));
    try (LogFixture logFixture = logFixtureFor(GoCache.class, Level.DEBUG)) {
        String allLogs = logFixture.allLogs();
        assertThat(allLogs, not(containsString("added to cache without an id.")));
        assertThat(allLogs, not(containsString("without an id served out of cache.")));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) NullUser(com.thoughtworks.go.domain.NullUser) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with NullUser

use of com.thoughtworks.go.domain.NullUser in project gocd by gocd.

the class UserEnabledCheckFilterTest method shouldNotSetUserIdInSessionIfUserServiceReturnANullUser.

@Test
public void shouldNotSetUserIdInSessionIfUserServiceReturnANullUser() throws IOException, ServletException {
    String userName = "none";
    SecurityContextHelper.setCurrentUser(userName);
    Authentication actual = SecurityContextHolder.getContext().getAuthentication();
    when(session.getAttribute(USERID_ATTR)).thenReturn(null);
    NullUser nullUser = new NullUser();
    when(userService.findUserByName(userName)).thenReturn(nullUser);
    filter.doFilterHttp(req, res, chain);
    assertThat(SecurityContextHolder.getContext().getAuthentication(), is(actual));
    verify(session, never()).setAttribute(eq(USERID_ATTR), Matchers.<Object>any());
    verify(chain).doFilter(req, res);
}
Also used : Authentication(org.springframework.security.Authentication) NullUser(com.thoughtworks.go.domain.NullUser) Test(org.junit.Test)

Example 3 with NullUser

use of com.thoughtworks.go.domain.NullUser in project gocd by gocd.

the class UserSqlMapDao method deleteUser.

@Override
public boolean deleteUser(final String username) {
    return (Boolean) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            User user = findUser(username);
            if (user instanceof NullUser) {
                throw new UserNotFoundException();
            }
            if (user.isEnabled()) {
                throw new UserEnabledException();
            }
            sessionFactory.getCurrentSession().delete(user);
            return Boolean.TRUE;
        }
    });
}
Also used : UserNotFoundException(com.thoughtworks.go.server.exceptions.UserNotFoundException) TransactionCallback(org.springframework.transaction.support.TransactionCallback) User(com.thoughtworks.go.domain.User) NullUser(com.thoughtworks.go.domain.NullUser) NullUser(com.thoughtworks.go.domain.NullUser) UserEnabledException(com.thoughtworks.go.server.exceptions.UserEnabledException) TransactionStatus(org.springframework.transaction.TransactionStatus)

Aggregations

NullUser (com.thoughtworks.go.domain.NullUser)3 Test (org.junit.Test)2 User (com.thoughtworks.go.domain.User)1 UserEnabledException (com.thoughtworks.go.server.exceptions.UserEnabledException)1 UserNotFoundException (com.thoughtworks.go.server.exceptions.UserNotFoundException)1 LogFixture (com.thoughtworks.go.util.LogFixture)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Authentication (org.springframework.security.Authentication)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1