public Object getPrincipal() { return this.assertion.getPrincipal().getName(); }
@SuppressWarnings("unchecked") @Override protected UserDetails loadUserDetails(final Assertion assertion) { final List<GrantedAuthority> grantedAuthorities = new ArrayList<>(); for (final String attribute : this.attributes) { final Object value = assertion.getPrincipal().getAttributes().get(attribute); if (value == null) { continue; } if (value instanceof List) { final List list = (List) value; for (final Object o : list) { grantedAuthorities.add(new SimpleGrantedAuthority( this.convertToUpperCase ? o.toString().toUpperCase() : o .toString())); } } else { grantedAuthorities.add(new SimpleGrantedAuthority( this.convertToUpperCase ? value.toString().toUpperCase() : value .toString())); } } return new User(assertion.getPrincipal().getName(), NON_EXISTENT_PASSWORD_VALUE, true, true, true, true, grantedAuthorities); }
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); } }
public AuthenticationFilter casAuthenticationFilter() { AuthenticationFilter authenticationFilter = new AuthenticationFilter(); authenticationFilter.setCasServerLoginUrl(casServerLoginUrl); authenticationFilter.setServerName(serverUrl); authenticationFilter.setEncodeServiceUrl(true); return authenticationFilter; }
private Object[] getTestSubjects() { final SimplePrincipal simplePrincipal = new SimplePrincipal("simple"); final SimpleGroup simpleGroup = new SimpleGroup("group"); final AttributePrincipalImpl attributePrincipal = new AttributePrincipalImpl("attr", Collections.<String, Object> singletonMap("LOA", "3")); final AssertionPrincipal assertionPrincipal = new AssertionPrincipal("assertion", new AssertionImpl( attributePrincipal, Collections.<String, Object> singletonMap("authenticationMethod", "username"))); return new Object[] { simplePrincipal, simpleGroup, attributePrincipal, assertionPrincipal, }; } }
protected void initInternal(final FilterConfig filterConfig) throws ServletException { super.initInternal(filterConfig); log.warn("SAML1.1 compliance requires the [artifactParameterName] and [serviceParameterName] to be set to specified values."); log.warn("This filter will overwrite any user-provided values (if any are provided)"); setArtifactParameterName("SAMLart"); setServiceParameterName("TARGET"); } }
public String toString() { return getName(); }
public RegexUrlPatternMatcherStrategy(final String pattern) { this.setPattern(pattern); }
public ExactUrlPatternMatcherStrategy(final String pattern) { this.setPattern(pattern); }
public EntireRegionRegexUrlPatternMatcherStrategy(final String pattern) { this.setPattern(pattern); }
@Test public void correctlyExtractsNamedAttributesFromAssertionAndConvertsThemToAuthorities() { GrantedAuthorityFromAssertionAttributesUserDetailsService uds = new GrantedAuthorityFromAssertionAttributesUserDetailsService( new String[] { "a", "b", "c", "d" }); uds.setConvertToUpperCase(false); Assertion assertion = mock(Assertion.class); AttributePrincipal principal = mock(AttributePrincipal.class); Map<String, Object> attributes = new HashMap<>(); attributes.put("a", Arrays.asList("role_a1", "role_a2")); attributes.put("b", "role_b"); attributes.put("c", "role_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()); assertThat(roles).containsExactlyInAnyOrder( "role_a1", "role_a2", "role_b", "role_c"); } }
@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()) .extracting(GrantedAuthority::getAuthority) .containsOnly("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); }
/** * Constructs a new Assertion with a Principal of the supplied name, a valid from date of now, no valid until date, and no attributes. * * @param name the name of the principal for which this assertion is valid. */ public AssertionImpl(final String name) { this(new AttributePrincipalImpl(name)); }
public String toString() { return getName(); }
String username = principal.getName(); if (username != null) credentials.setUsername(username); Object credObj = principal.getAttributes().get("credential"); if (credObj != null) { String clearPass = decryptPassword(credObj.toString());
@Override public String toString() { return principal.getName(); } }
/** * Constructs a new Assertion with a Principal of the supplied name, a valid from date of now, no valid until date, and no attributes. * * @param name the name of the principal for which this assertion is valid. */ public AssertionImpl(final String name) { this(new AttributePrincipalImpl(name)); }
String userId = casPrincipal.getName(); log.debug("Validate ticket : {} in CAS server : {} to retrieve user : {}", new Object[]{ ticket, getCasServerUrlPrefix(), userId }); Map<String, Object> attributes = casPrincipal.getAttributes();
public String getRemoteUser() { return principal != null ? this.principal.getName() : null; }
public String getRemoteUser() { return principal != null ? this.principal.getName() : null; }