Search in sources :

Example 21 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.

the class SidTests method testGetters.

@Test
public void testGetters() throws Exception {
    Authentication authentication = new TestingAuthenticationToken("johndoe", "password");
    PrincipalSid principalSid = new PrincipalSid(authentication);
    GrantedAuthority ga = new SimpleGrantedAuthority("ROLE_TEST");
    GrantedAuthoritySid gaSid = new GrantedAuthoritySid(ga);
    assertThat("johndoe".equals(principalSid.getPrincipal())).isTrue();
    assertThat("scott".equals(principalSid.getPrincipal())).isFalse();
    assertThat("ROLE_TEST".equals(gaSid.getGrantedAuthority())).isTrue();
    assertThat("ROLE_TEST2".equals(gaSid.getGrantedAuthority())).isFalse();
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) Authentication(org.springframework.security.core.Authentication) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.Test)

Example 22 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.

the class CasAuthenticationTokenMixinTests method deserializeCasAuthenticationTest.

@Test
public void deserializeCasAuthenticationTest() throws IOException, JSONException {
    CasAuthenticationToken token = mapper.readValue(CAS_TOKEN_JSON, CasAuthenticationToken.class);
    assertThat(token).isNotNull();
    assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
    assertThat(((User) token.getPrincipal()).getUsername()).isEqualTo("admin");
    assertThat(((User) token.getPrincipal()).getPassword()).isEqualTo("1234");
    assertThat(token.getUserDetails()).isNotNull().isInstanceOf(User.class);
    assertThat(token.getAssertion()).isNotNull().isInstanceOf(AssertionImpl.class);
    assertThat(token.getKeyHash()).isEqualTo(KEY.hashCode());
    assertThat(token.getUserDetails().getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
    assertThat(token.getAssertion().getAuthenticationDate()).isEqualTo(START_DATE);
    assertThat(token.getAssertion().getValidFromDate()).isEqualTo(START_DATE);
    assertThat(token.getAssertion().getValidUntilDate()).isEqualTo(END_DATE);
    assertThat(token.getAssertion().getPrincipal().getName()).isEqualTo("assertName");
    assertThat(token.getAssertion().getAttributes()).hasSize(0);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) CasAuthenticationToken(org.springframework.security.cas.authentication.CasAuthenticationToken) Test(org.junit.Test)

Example 23 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.

the class CasAuthenticationTokenMixinTests method createCasAuthenticationToken.

private CasAuthenticationToken createCasAuthenticationToken() {
    User principal = new User("admin", "1234", Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER")));
    Collection<? extends GrantedAuthority> authorities = Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"));
    Assertion assertion = new AssertionImpl(new AttributePrincipalImpl("assertName"), START_DATE, END_DATE, START_DATE, Collections.<String, Object>emptyMap());
    return new CasAuthenticationToken(KEY, principal, principal.getPassword(), authorities, new User("admin", "1234", authorities), assertion);
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) CasAuthenticationToken(org.springframework.security.cas.authentication.CasAuthenticationToken) Assertion(org.jasig.cas.client.validation.Assertion) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl)

Example 24 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.

the class JdbcUserDetailsManagerTests method deleteGroupAuthorityRemovesCorrectRows.

@Test
public void deleteGroupAuthorityRemovesCorrectRows() throws Exception {
    GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_A");
    manager.removeGroupAuthority("GROUP_0", auth);
    assertThat(template.queryForList("select authority from group_authorities where group_id = 0")).isEmpty();
    manager.removeGroupAuthority("GROUP_2", auth);
    assertThat(template.queryForList("select authority from group_authorities where group_id = 2")).hasSize(2);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.Test)

Example 25 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.

the class JdbcUserDetailsManagerTests method addGroupAuthorityInsertsCorrectGroupAuthorityRow.

@Test
public void addGroupAuthorityInsertsCorrectGroupAuthorityRow() throws Exception {
    GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_X");
    manager.addGroupAuthority("GROUP_0", auth);
    template.queryForObject("select authority from group_authorities where authority = 'ROLE_X' and group_id = 0", String.class);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.Test)

Aggregations

SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)109 GrantedAuthority (org.springframework.security.core.GrantedAuthority)64 Test (org.junit.Test)49 ArrayList (java.util.ArrayList)30 Authentication (org.springframework.security.core.Authentication)27 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)22 HashSet (java.util.HashSet)14 User (org.springframework.security.core.userdetails.User)11 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)8 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)7 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)7 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)7 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)7 Before (org.junit.Before)6 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)6 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)6 List (java.util.List)5 Map (java.util.Map)5 DBUnitTest (org.orcid.test.DBUnitTest)5