Package org.apache.jetspeed.sso

Examples of org.apache.jetspeed.sso.SSOException


        }
        catch (Exception e)
        {
            String msg = "Unable to remove SSO Site: " + site.getName();
            logger.error(msg, e);
            throw new SSOException(msg, e);
        }       
    }
View Full Code Here


      }
      catch (MalformedURLException e)
      {
        String msg = ("Error -- Malformed URL [" + destUrl +"] for SSO authenticated destination");
        log.error(msg);
        throw new SSOException(msg, e);
      }
     
      /*
       * Setup HTTPClient
       * Check if an HTTP Client already exists for the given /user/site
       */
      HttpClient client = (HttpClient)this.clientProxy.get(proxyID);
      GetMethod get = null;
     
      if (bRefresh == true || client == null)
      {
        if (log.isInfoEnabled())
          log.info("SSO Component -- Create new HTTP Client object for Principal/URL [" + proxyID+ "]");
       
        client = new HttpClient();
        client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
       
        int numberOfSites = sites.length;
       
        // Do all the logins for the site
        for (int i=0; i<numberOfSites; i++)
        {
          SSOSite site = sites[i];
         
          if (site != null)
          {
            Iterator itRemotePrincipals = site.getRemotePrincipals().iterator();
            while (itRemotePrincipals.hasNext() )
            {
              InternalUserPrincipal remotePrincipal = (InternalUserPrincipal)itRemotePrincipals.next();
                  if (remotePrincipal != null)
                  {
                    InternalCredential credential = null;
                    if ( remotePrincipal.getCredentials() != null)
                      credential = (InternalCredential)remotePrincipal.getCredentials().iterator().next();
                   
                    if (credential != null)
                    {
                      if (log.isInfoEnabled())
                        log.info("SSOComponent -- Remote Principal ["+stripPrincipalName(remotePrincipal.getFullPath())+"] has credential ["+this.unscramble(credential.getValue())+ "]");
                     
                      client.getState().setCredentials(
                            site.getRealm(),
                                  urlObj.getHost(),
                                  new UsernamePasswordCredentials(stripPrincipalName(remotePrincipal.getFullPath())this.unscramble(credential.getValue()))
                              );
                     
                      // Build URL if it's Form authentication
                      StringBuffer siteURL = new StringBuffer(site.getSiteURL());
                    
                    // Check if it's form based or ChallengeResponse
                    if (site.isFormAuthentication())
                    {
                      siteURL.append("?").append(site.getFormUserField()).append("=").append(stripPrincipalName(remotePrincipal.getFullPath())).append("&").append(site.getFormPwdField()).append("=").append(this.unscramble(credential.getValue()));
                    }
                     
                      get = new GetMethod(siteURL.toString());
 
                            // Tell the GET method to automatically handle authentication. The
                            // method will use any appropriate credentials to handle basic
                            // authentication requests.  Setting this value to false will cause
                            // any request for authentication to return with a status of 401.
                            // It will then be up to the client to handle the authentication.
                            get.setDoAuthentication( true );
                            try {
                                // execute the GET
                                int status = client.executeMethod( get );
                               
                                if (log.isInfoEnabled() )
                                    log.info("Accessing site [" + site.getSiteURL() + "]. HTTP Status [" +status+ "]" );
                               
                                /*
                             * If the destination URL and the SSO url match
                             * use the authentication process but return immediately
                             * the result page.
                             */
                                if( destUrl.compareTo(site.getSiteURL()) == 0 && numberOfSites == 1)
                                {
                                  if (log.isInfoEnabled() )
                                    log.info("SSO Component --SSO Site and destination URL match. Go and get the content." );
                                 
                                  //try
                                //{
                                  //bis = new BufferedInputStream(get.getResponseBodyAsStream());
                                  resultPage = get.getResponseBodyAsString();
                                //}
                                //catch(IOException ioe)
                                //{
                                //  log.error(strErrorMessage, ioe);
                                //  throw new SSOException (strErrorMessage, ioe); 
                                //}

                                get.releaseConnection();
                               
                                //  Add the client object to the cache
                                this.clientProxy.put(proxyID, client);
                               
                                //return bis;
                                return resultPage;
                                }
                       
                      } catch (Exception e) {
                              log.error("Exception while authentication. Error: " +e);                         
                            }
                     
                      get.releaseConnection();
                     }
                  }
            }
          }      
        }
       
        // Add the client object to the cache
        this.clientProxy.put(proxyID, client);
      }
      else
      {
        if (log.isInfoEnabled())
          log.info("SSO Component -- Use cached HTTP Client object for Principal/URL [" + proxyID+ "]");
      }
     
      // All the SSO authentication done go to the destination url
    get = new GetMethod(destUrl);
    try {
            // execute the GET
            int status = client.executeMethod( get );
           
            log.info("Accessing site [" + destUrl + "]. HTTP Status [" +status+ "]" );
   
    } catch (Exception e) {
          log.error("Exception while authentication. Error: " +e);                         
        }
   
   
    try
    {
      //bis = new BufferedInputStream(get.getResponseBodyAsStream());
      resultPage = get.getResponseBodyAsString();
    }
    catch(IOException ioe)
    {
      log.error(strErrorMessage, ioe);
      throw new SSOException (strErrorMessage, ioe);
        }
    catch (Exception e)
    {
      log.error(strErrorMessage, e);
      throw new SSOException (strErrorMessage, e);
     
    }
        finally
        {
            get.releaseConnection();
View Full Code Here

     
      if (sites == null)
      {
        String msg = "SSO Component useSSO -- Couldn't find any SSO sites for user ["+fullPath+"]";
        log.error(msg);
        throw new SSOException(msg);
      }
     
      // Load all the sites
      int siteSize = sites.size();
      int siteIndex =0;
View Full Code Here

        ssoSite.setRealm(realm);
        getPersistenceBrokerTemplate().store(ssoSite);
      }
      catch (Exception e)
      {
        throw new SSOException("Failed to set the realm for site [" + site + "] Error" +e );
      }
    }
    }
View Full Code Here

   
    // Initialization
    SSOSite ssoSite = getSSOSiteObject(site);
   
    if ( ssoSite == null)
      throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE)// no entry for site
   
    // Get the principal from the subject
    BasePrincipal principal = (BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class);
    String fullPath = principal.getFullPath();
   
    // Filter the credentials for the given principals
    SSOContext context = getCredential(ssoSite, fullPath)
   
    if ( context == null)
      throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE)// no entry for site
   
    return context;
  }
View Full Code Here

               getPersistenceBrokerTemplate().store(ssoSite);
            }
           catch (Exception e)
           {
             e.printStackTrace();
              throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
           }
    }
   
    // Get the Principal information (logged in user)
    String fullPath = ((BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class)).getFullPath();
    String principalName = ((BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class)).getName();
   
    // Add an entry for the principal to the site if it doesn't exist
    SSOPrincipal principal = this.getPrincipalForSite(ssoSite, fullPath);
   
    if (principal == null )
    {
        principal = getSSOPrincipal(fullPath);
        ssoSite.addPrincipal(principal);
    }
    else
    {
        // Check if the entry the user likes to update exists already
        Collection remoteForSite = ssoSite.getRemotePrincipals();
        Collection principalsForSite = ssoSite.getPrincipals();
       
        if ( remoteForSite != null && principalsForSite != null)
        {
            Collection remoteForPrincipals = this.getRemotePrincipalsForPrincipal(principalsForSite, fullPath);
            if ( remoteForPrincipals != null)
            {
              if (findRemoteMatch(remoteForPrincipals, remoteForSite) != null )
              {
                  // Entry exists can't to an add has to call update
                  throw new SSOException(SSOException.REMOTE_PRINCIPAL_EXISTS_CALL_UPDATE);
              }
            }
        }
    }
   
    if (principal == null)
      throw new SSOException(SSOException.FAILED_ADDING_PRINCIPAL_TO_MAPPING_TABLE_FOR_SITE);
   
    // Create a remote principal and credentials
    InternalUserPrincipalImpl remotePrincipal = new InternalUserPrincipalImpl(remoteUser);
   
    /*
     * The RemotePrincipal (class InternalUserPrincipal) will have a fullPath that identifies the entry as an SSO credential.
     * The entry has to be unique for a site and principal  (GROUP -or- USER ) an therefore it needs to be encoded as following:
     * The convention for the path is the following: /sso/SiteID/{user|group}/{user name | group name}/remote user name
     */
    if ( fullPath.indexOf("/group/") > -1)
        remotePrincipal.setFullPath("/sso/" + ssoSite.getSiteId() + "/group/"+  principalName + "/" + remoteUser);
    else
        remotePrincipal.setFullPath("/sso/" + ssoSite.getSiteId() + "/user/"+ principalName + "/" + remoteUser);
   
    // New credential object for remote principal
     InternalCredentialImpl credential =
            new InternalCredentialImpl(remotePrincipal.getPrincipalId(),
                this.scramble(pwd), 0, DefaultPasswordCredentialImpl.class.getName());
    
     if ( remotePrincipal.getCredentials() == null)
       remotePrincipal.setCredentials(new ArrayList(0));
    
    remotePrincipal.getCredentials().add( credential);
   
    // Add it to Principals remotePrincipals list
    principal.addRemotePrincipal(remotePrincipal);

    // Update the site remotePrincipals list
    ssoSite.getRemotePrincipals().add(remotePrincipal);
   
      
    // Update database and reset cache
     try
         {
             getPersistenceBrokerTemplate().store(ssoSite);
            
             // Persist Principal/Remote
         getPersistenceBrokerTemplate().store(principal);
          }
         catch (Exception e)
         {
           e.printStackTrace();
            throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
         }
        
         // Add to site
         this.mapSite.put(site, ssoSite);
  }
View Full Code Here

    InternalUserPrincipal remotePrincipal = null;
    //Get the site
    SSOSite ssoSite = getSSOSiteObject(site);
    if (ssoSite == null)
    {
      throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
    }
   
    // Get the Principal information
    String fullPath = ((BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class)).getFullPath();
   
    try
    {
      //  Get remotePrincipals for Site and match them with the Remote Principal for the Principal attached to site
      Collection principalsForSite = ssoSite.getPrincipals();
      Collection remoteForSite = ssoSite.getRemotePrincipals();
     
      // If any of them don't exist just return
      if (principalsForSite == null || remoteForSite== null )
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
     
      Collection remoteForPrincipals = getRemotePrincipalsForPrincipal(principalsForSite, fullPath);
     
      if ( remoteForPrincipals == null)
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
     
      // Get remote Principal that matches the site and the principal
      if ((remotePrincipal = findRemoteMatch(remoteForPrincipals, remoteForSite)) == null )
      {
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
      }

      // Update assocation tables
      ssoSite.getRemotePrincipals().remove(remotePrincipal);
     
      if (remoteForPrincipals.remove(remotePrincipal) == true)
     
      // Update the site
      getPersistenceBrokerTemplate().store(ssoSite);

      // delete the remote Principal from the SECURITY_PRINCIPAL table
        getPersistenceBrokerTemplate().delete(remotePrincipal);
       
           
    }
    catch(SSOException ssoex)
    {
      throw new SSOException(ssoex);
    }
    catch (Exception e)
        {
          e.printStackTrace();
           throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
        }
               
    // Update database
     try
         {
             getPersistenceBrokerTemplate().store(ssoSite);
          }
         catch (Exception e)
         {
           e.printStackTrace();
            throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
         }
        
  }
View Full Code Here

     
      //Get the site
      SSOSite ssoSite = getSSOSiteObject(site);
      if (ssoSite == null)
      {
        throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
      }
     
      // Get the Principal information
      String fullPath = ((BasePrincipal)SecurityHelper.getBestPrincipal(subject, UserPrincipal.class)).getFullPath();
     
      //  Get remotePrincipals for Site and match them with the Remote Principal for the Principal attached to site
      Collection principalsForSite  = ssoSite.getPrincipals();
      Collection remoteForSite    = ssoSite.getRemotePrincipals();
     
      // If any of them don't exist just return
      if (principalsForSite == null || remoteForSite== null )
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
     
      Collection remoteForPrincipals = getRemotePrincipalsForPrincipal(principalsForSite, fullPath);
     
      if ( remoteForPrincipals == null)
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
     
      // Get remote Principal that matches the site and the principal
      if ((remotePrincipal = findRemoteMatch(remoteForPrincipals, remoteForSite)) == null )
      {
          throw new SSOException(SSOException.NO_CREDENTIALS_FOR_SITE);
      }
           
      // Update principal information
      //remotePrincipal.setFullPath("/sso/" + ssoSite.getSiteId() + "/user/"+ principalName + "/" + remoteUser);
     
      InternalCredential credential = (InternalCredential)remotePrincipal.getCredentials().iterator().next();
         
      // New credential object
       if ( credential != null)
        // Remove credential and principal from mapping
         credential.setValue(this.scramble(pwd));
     
      // Update database and reset cache
       try
       {
           getPersistenceBrokerTemplate().store(credential);
        }
       catch (Exception e)
       {
         e.printStackTrace();
          throw new SSOException(SSOException.FAILED_STORING_SITE_INFO_IN_DB + e.toString() );
       }      
      }
View Full Code Here

        }
        catch (Exception e)
        {
            String msg = "Unable to remove SSO Site: " + site.getName();
            logger.error(msg, e);
            throw new SSOException(msg, e);
        }       
    }
View Full Code Here

        }
        catch (Exception e)
        {
            String msg = "Unable to add SSO Site: " + siteName;
            logger.error(msg, e);
            throw new SSOException(msg, e);
       
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.sso.SSOException

Copyright © 2018 www.massapicom. 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.