List of usage examples for org.springframework.security.cas.authentication CasAssertionAuthenticationToken CasAssertionAuthenticationToken
public CasAssertionAuthenticationToken(final Assertion assertion, final String ticket)
From source file:edu.acu.cs.spring.security.cas.userdetails.GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
@Test public void correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities() { GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds = new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService(); uds.setConvertToUpperCase(false);// www .j a v a 2 s .co m uds.setConvertSpacesToUnderscores(false); uds.setAttribute("a"); uds.setRolePrefix(""); Assertion assertion = mock(Assertion.class); AttributePrincipal principal = mock(AttributePrincipal.class); Map<String, Object> attributes = new HashMap<>(); attributes.put("a", Arrays.asList("CN=role_a1,OU=roles,DC=spring,DC=io", "CN=role_a2,OU=roles,DC=spring,DC=io")); attributes.put("b", "b"); attributes.put("c", "c"); attributes.put("d", null); attributes.put("someother", "unused"); when(assertion.getPrincipal()).thenReturn(principal); when(principal.getAttributes()).thenReturn(attributes); when(principal.getName()).thenReturn("somebody"); CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket"); UserDetails user = uds.loadUserDetails(token); Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities()); assertTrue(roles.size() == 2); assertTrue(roles.contains("role_a1")); assertTrue(roles.contains("role_a2")); }
From source file:edu.acu.cs.spring.security.cas.userdetails.GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
@Test public void correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities() { GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds = new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService(); Assertion assertion = mock(Assertion.class); AttributePrincipal principal = mock(AttributePrincipal.class); Map<String, Object> attributes = new HashMap<>(); attributes.put("memberOf", Arrays.asList("CN=a1,ou=other,OU=roles,DC=spring,DC=io", "CN=a2,OU=roles,dc=spring,DC=io", null)); attributes.put("someother", "unused"); when(assertion.getPrincipal()).thenReturn(principal); when(principal.getAttributes()).thenReturn(attributes); when(principal.getName()).thenReturn("somebody"); CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket"); UserDetails user = uds.loadUserDetails(token); Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities()); assertTrue(roles.size() == 2);// w w w. j a v a 2 s .c o m assertTrue(roles.contains("ROLE_A1")); assertTrue(roles.contains("ROLE_A2")); }
From source file:org.fao.geonet.kernel.security.ecas.ECasAuthenticationProvider.java
/** * Template method for retrieving the UserDetails based on the assertion. * Default is to call configured userDetailsService and pass the username. * Deployers can override this method and retrieve the user based on any * criteria they desire.//from w w w. java 2s. com * * @param assertion * The CAS Assertion. * @return the UserDetails. */ protected UserDetails loadUserByAssertion(final Assertion assertion) { final CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, ""); return this.authenticationUserDetailsService.loadUserDetails(token); }