Esempio n. 1
0
        //public object clone()
        //{
        //    AbstractRegisteredService clone = newInstance();
        //    clone.copyFrom(this);
        //    return clone;
        //}

        /**
         * Copies the properties of the source service into this instance.
         *
         * @param source Source service from which to copy properties.
         */
        public void copyFrom(RegisteredService source)
        {
            this.setId(source.getId());
            this.setAllowedAttributes(new List <string>(source.getAllowedAttributes()));
            this.setAllowedToProxy(source.isAllowedToProxy());
            this.setDescription(source.getDescription());
            this.setEnabled(source.isEnabled());
            this.setName(source.getName());
            this.setServiceId(source.getServiceId());
            this.setSsoEnabled(source.isSsoEnabled());
            this.setTheme(source.getTheme());
            this.setAnonymousAccess(source.isAnonymousAccess());
            this.setIgnoreAttributes(source.isIgnoreAttributes());
            this.setEvaluationOrder(source.getEvaluationOrder());
            this.setUsernameAttribute(source.getUsernameAttribute());
        }
        /**
     * Determines the principal id to use for a {@link RegisteredService} using the following rules: 
     * 
     * <ul>
     *  <li> If the service is marked to allow anonymous access, a persistent id is returned. </li>
     *  <li> If the attribute name matches {@link RegisteredService#DEFAULT_USERNAME_ATTRIBUTE}, then the default principal id is returned.</li>
     *  <li>If the service is set to ignore attributes, or the username attribute exists in the allowed attributes for the service, 
     *      the corresponding attribute value will be returned.
     *  </li>
     *   <li>Otherwise, the default principal's id is returned as the username attribute with an additional warning.</li>
     * </ul>
     * 
     * @param principal The principal object to be validated and constructed
     * @param registeredService Requesting service for which a principal is being validated. 
     * @param serviceTicket An instance of the service ticket used for validation
     * 
     * @return The principal id to use for the requesting registered service
     */
        private string determinePrincipalIdForRegisteredService(Principal principal, RegisteredService registeredService,
                                                                 ServiceTicket serviceTicket)
        {
            string principalId = null;
            string serviceUsernameAttribute = registeredService.getUsernameAttribute();

            if (registeredService.isAnonymousAccess())
            {
                principalId = this.persistentIdGenerator.generate(principal, serviceTicket.getService());
            }
            else if (string.IsNullOrEmpty(serviceUsernameAttribute))
            {
                principalId = principal.getId();
            }
            else
            {
                if ((registeredService.isIgnoreAttributes() || registeredService.getAllowedAttributes().Contains(serviceUsernameAttribute)) &&
                    principal.getAttributes().ContainsKey(serviceUsernameAttribute))
                {
                    principalId = principal.getAttributes().First(x => x.Key == registeredService.getUsernameAttribute()).Value.ToString();
                }
                else
                {
                    principalId = principal.getId();
                    Object[] errorLogParameters = new Object[] { principalId, registeredService.getUsernameAttribute(),
                                                                     principal.getAttributes(), registeredService.getServiceId(), principalId };
                    //log.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot "
                    //        + "provide on the validation response the user attribute the registered service [{}] expects. "
                    //        + "CAS will instead return the default username attribute [{}]", errorLogParameters);
                }

            }

            //log.debug("Principal id to return for service [{}] is [{}]. The default principal id is [{}].", 
            //          new Object[] {registeredService.getName(), principal.getId(), principalId});
            return principalId;
        }
Esempio n. 3
0
        /**
         * Determines the principal id to use for a {@link RegisteredService} using the following rules:
         *
         * <ul>
         *  <li> If the service is marked to allow anonymous access, a persistent id is returned. </li>
         *  <li> If the attribute name matches {@link RegisteredService#DEFAULT_USERNAME_ATTRIBUTE}, then the default principal id is returned.</li>
         *  <li>If the service is set to ignore attributes, or the username attribute exists in the allowed attributes for the service,
         *      the corresponding attribute value will be returned.
         *  </li>
         *   <li>Otherwise, the default principal's id is returned as the username attribute with an additional warning.</li>
         * </ul>
         *
         * @param principal The principal object to be validated and constructed
         * @param registeredService Requesting service for which a principal is being validated.
         * @param serviceTicket An instance of the service ticket used for validation
         *
         * @return The principal id to use for the requesting registered service
         */
        private string determinePrincipalIdForRegisteredService(Principal principal, RegisteredService registeredService,
                                                                ServiceTicket serviceTicket)
        {
            string principalId = null;
            string serviceUsernameAttribute = registeredService.getUsernameAttribute();

            if (registeredService.isAnonymousAccess())
            {
                principalId = this.persistentIdGenerator.generate(principal, serviceTicket.getService());
            }
            else if (string.IsNullOrEmpty(serviceUsernameAttribute))
            {
                principalId = principal.getId();
            }
            else
            {
                if ((registeredService.isIgnoreAttributes() || registeredService.getAllowedAttributes().Contains(serviceUsernameAttribute)) &&
                    principal.getAttributes().ContainsKey(serviceUsernameAttribute))
                {
                    principalId = principal.getAttributes().First(x => x.Key == registeredService.getUsernameAttribute()).Value.ToString();
                }
                else
                {
                    principalId = principal.getId();
                    Object[] errorLogParameters = new Object[] { principalId, registeredService.getUsernameAttribute(),
                                                                 principal.getAttributes(), registeredService.getServiceId(), principalId };
                    //log.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot "
                    //        + "provide on the validation response the user attribute the registered service [{}] expects. "
                    //        + "CAS will instead return the default username attribute [{}]", errorLogParameters);
                }
            }

            //log.debug("Principal id to return for service [{}] is [{}]. The default principal id is [{}].",
            //          new Object[] {registeredService.getName(), principal.getId(), principalId});
            return(principalId);
        }
        //public object clone()
        //{
        //    AbstractRegisteredService clone = newInstance();
        //    clone.copyFrom(this);
        //    return clone;
        //}

        /**
     * Copies the properties of the source service into this instance.
     *
     * @param source Source service from which to copy properties.
     */
        public void copyFrom(RegisteredService source)
        {
            this.setId(source.getId());
            this.setAllowedAttributes(new List<string>(source.getAllowedAttributes()));
            this.setAllowedToProxy(source.isAllowedToProxy());
            this.setDescription(source.getDescription());
            this.setEnabled(source.isEnabled());
            this.setName(source.getName());
            this.setServiceId(source.getServiceId());
            this.setSsoEnabled(source.isSsoEnabled());
            this.setTheme(source.getTheme());
            this.setAnonymousAccess(source.isAnonymousAccess());
            this.setIgnoreAttributes(source.isIgnoreAttributes());
            this.setEvaluationOrder(source.getEvaluationOrder());
            this.setUsernameAttribute(source.getUsernameAttribute());
        }