Examples of AttributePrincipal


Examples of org.jasig.cas.client.authentication.AttributePrincipal

    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<String, Object>();
        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());
        assertTrue(roles.size() == 4);
        assertTrue(roles.contains("role_a1"));
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

    protected CasProfile retrieveUserProfile(final CasCredentials credentials, final WebContext context) {
        final String ticket = credentials.getServiceTicket();
        try {
            final String contextualCallbackUrl = getContextualCallbackUrl(context);
            final Assertion assertion = this.ticketValidator.validate(ticket, contextualCallbackUrl);
            final AttributePrincipal principal = assertion.getPrincipal();
            logger.debug("principal : {}", principal);
            final CasProfile casProfile;
            if (this.casProxyReceptor != null) {
                casProfile = new CasProxyProfile();
            } else {
                casProfile = new CasProfile();
            }
            casProfile.setId(principal.getName());
            casProfile.addAttributes(principal.getAttributes());
            if (this.casProxyReceptor != null) {
                ((CasProxyProfile) casProfile).setPrincipal(principal);
            }
            logger.debug("casProfile : {}", casProfile);
            return casProfile;
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

      validateService = SingletonConfig.getInstance().getConfigValue("CAS_SSO.VALIDATE-USER.SERVICE");
      logger.debug("Read validateService=" + validateService);
  }
  logger.debug("userId:"+userId);
  try {
    AttributePrincipal principal = null;
    Cas20ProxyTicketValidator sv = new Cas20ProxyTicketValidator(validateUrl);
    sv.setAcceptAnyProxy(true);

      Assertion a = sv.validate(ticket, validateService);
    principal = a.getPrincipal();
    logger.debug("Ticket is VALID, username=" + principal.getName());
     
  } catch (TicketValidationException e) {
    logger.error("An exception occured while validating the cas token");
    throw new SecurityException("An exception occured while validating the cas token", e);
  } catch (Throwable e) {
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

        try {
            // contact CAS server to validate service ticket
            Assertion casAssertion = ticketValidator.validate(ticket, getCasService());
            // get principal, user id and attributes
            AttributePrincipal casPrincipal = casAssertion.getPrincipal();
            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();
            // refresh authentication token (user id + remember me)
            casToken.setUserId(userId);
            String rememberMeAttributeName = getRememberMeAttributeName();
            String rememberMeStringValue = (String)attributes.get(rememberMeAttributeName);
            boolean isRemembered = rememberMeStringValue != null && Boolean.parseBoolean(rememberMeStringValue);
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

        final HttpServletRequestWrapperFilter filter = new HttpServletRequestWrapperFilter();
        filter.init(config);

        final Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put("memberOf", "administrators");
        final AttributePrincipal principal = new AttributePrincipalImpl("alice", attributes);
        session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, new AssertionImpl(principal));

        request.setSession(session);

        filter.doFilter(request, new MockHttpServletResponse(), createFilterChain());
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

        final HttpServletRequestWrapperFilter filter = new HttpServletRequestWrapperFilter();
        filter.init(config);

        final Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put("groupMembership", Arrays.asList(new Object[] { "animals", "ducks" }));
        final AttributePrincipal principal = new AttributePrincipalImpl("daffy", attributes);
        session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, new AssertionImpl(principal));

        request.setSession(session);

        filter.doFilter(request, new MockHttpServletResponse(), createFilterChain());
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

        }

        final Assertion assertion;
        final Map<String, Object> attributes = extractCustomAttributes(response);
        if (CommonUtils.isNotBlank(proxyGrantingTicket)) {
            final AttributePrincipal attributePrincipal = new AttributePrincipalImpl(principal, attributes,
                    proxyGrantingTicket, this.proxyRetriever);
            assertion = new AssertionImpl(attributePrincipal);
        } else {
            assertion = new AssertionImpl(new AttributePrincipalImpl(principal, attributes));
        }
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

     * <code>request.getRemoteUser</code> to the underlying Assertion object
     * stored in the user session.
     */
    public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
            final FilterChain filterChain) throws IOException, ServletException {
        final AttributePrincipal principal = retrievePrincipalFromSessionOrRequest(servletRequest);

        filterChain.doFilter(new CasHttpServletRequestWrapper((HttpServletRequest) servletRequest, principal),
                servletResponse);
    }
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

                    final List<?> values = getValuesFrom(samlAttribute);

                    personAttributes.put(samlAttribute.getAttributeName(), values.size() == 1 ? values.get(0) : values);
                }

                final AttributePrincipal principal = new AttributePrincipalImpl(subject.getNameIdentifier()
                        .getNameIdentifier(), personAttributes);

                final Map<String, Object> authenticationAttributes = new HashMap<String, Object>();
                authenticationAttributes.put("samlAuthenticationStatement::authMethod",
                        authenticationStatement.getAuthenticationMethod());
View Full Code Here

Examples of org.jasig.cas.client.authentication.AttributePrincipal

      HttpServletRequest req = reqCtx.getRequest();
      //Punto 1
      Assertion assertion = (Assertion) req.getSession().getAttribute(CasClientPluginSystemCostants.JPCASCLIENT_CONST_CAS_ASSERTION);
      this._log.trace(" Assertion " + assertion);
      if (null != assertion) {
        AttributePrincipal attributePrincipal = assertion.getPrincipal();
        name = attributePrincipal.getName();
        this._log.trace(" Princ " + attributePrincipal);
        this._log.trace(" Princ - Name " + attributePrincipal.getName());
      }
      this._log.trace("jpcasclient: request From User with Principal [CAS tiket validation]: " + name + " - info: AuthType " + req.getAuthType() + " " + req.getProtocol() + " " + req.getRemoteAddr() + " " + req.getRemoteHost());
      HttpSession session = req.getSession();
      if (null != name) {
        String username = name;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.