Search in sources :

Example 1 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class UserHelperTest method shouldGetNameFromLdapUserDetailsIfCannotGetFullName.

@Test
public void shouldGetNameFromLdapUserDetailsIfCannotGetFullName() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new LdapUserDetailsImpl() {

        public String getUsername() {
            return "test1";
        }

        public String getDn() {
            return "n=Test User, ou=Beijing, ou=Employees, ou=Enterprise, ou=Principal";
        }
    }, null, null);
    assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("test1"));
}
Also used : LdapUserDetailsImpl(org.springframework.security.userdetails.ldap.LdapUserDetailsImpl) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 2 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class UserHelperTest method shouldGetDisplayNameForAPasswordFileUser.

@Test
public void shouldGetDisplayNameForAPasswordFileUser() {
    GrantedAuthority[] authorities = { new GrantedAuthorityImpl("anything") };
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "Full Name", "password", true, true, true, true, authorities), null, authorities);
    assertThat(UserHelper.getUserName(authentication), is(new Username(new CaseInsensitiveString("user"), "Full Name")));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class UserHelperTest method shouldReturnTrueWhenCheckIsAgentIfGrantedAuthorityContainsAgentRole.

@Test
public void shouldReturnTrueWhenCheckIsAgentIfGrantedAuthorityContainsAgentRole() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(null, null, new GrantedAuthorityImpl[] { new GrantedAuthorityImpl("ROLE_AGENT") });
    assertThat(UserHelper.matchesRole(authentication, X509AuthoritiesPopulator.ROLE_AGENT), is(true));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 4 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class UserHelperTest method shouldGetNameFromUserDetails.

@Test
public void shouldGetNameFromUserDetails() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new User("user", "pass", true, false, true, true, new GrantedAuthority[0]), null, null);
    assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("user"));
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 5 with TestingAuthenticationToken

use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.

the class GoVelocityViewTest method shouldSetTemplateViewUserRightsForTemplateViewUser.

@Test
public void shouldSetTemplateViewUserRightsForTemplateViewUser() throws Exception {
    securityContext.setAuthentication(new TestingAuthenticationToken("templateView", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_TEMPLATE_VIEW_USER.toString()) }));
    request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
    view.exposeHelpers(velocityContext, request);
    assertThat(velocityContext.get(GoVelocityView.TEMPLATE_VIEW_USER), is(true));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)17 Test (org.junit.Test)14 GrantedAuthority (org.springframework.security.GrantedAuthority)10 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)9 Authentication (org.springframework.security.Authentication)4 User (org.springframework.security.userdetails.User)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 LdapUserDetailsImpl (org.springframework.security.userdetails.ldap.LdapUserDetailsImpl)3 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 Username (com.thoughtworks.go.server.domain.Username)1