Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to Jasig under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Jasig licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.jasig.cas3.extensions.clearpass.integration.uportal;
 
 import  org.jasig.portal.security.provider.cas.CasAssertionSecurityContext;
 import  org.jasig.portal.security.provider.NotSoOpaqueCredentials;
 import  org.jasig.portal.security.IOpaqueCredentials;
 import  org.springframework.util.Assert;

Author(s):
Scott Battaglia
Version:
$Revision$ $Date$
Since:
1.0.0.GA
 
 public final class PasswordCachingCasAssertionSecurityContext extends CasAssertionSecurityContext {
 
     private final String clearPassUrl;
 
     private byte[] cachedCredentials;
 
     protected PasswordCachingCasAssertionSecurityContext(final String clearPassUrl) {
         super();
         Assert.notNull(clearPassUrl"clearPassUrl cannot be null.");
         this. = clearPassUrl;
     }
 
     @Override
     protected void postAuthenticate(final Assertion assertion) {
         final String proxyTicket = assertion.getPrincipal().getProxyTicketFor(this.);
 
         if (proxyTicket == null) {
             log.error("Unable to obtain proxy ticket for ClearPass service.");
             return;
         }
 
         final String password = retrievePasswordFromResponse(proxyTicket);
 
         if (password != null) {
             log.debug("Password retrieved from ClearPass.");
             this. = password.getBytes();
         } else {
             log.debug("Unable to retrieve password from ClearPass.");
         }
     }
 
     @Override
     public IOpaqueCredentials getOpaqueCredentials() {
         if (this. == null) {
             return super.getOpaqueCredentials();
         }
 
         final NotSoOpaqueCredentials credentials = new CacheOpaqueCredentials();
         credentials.setCredentials(this.);
         return credentials;
     }
 
     protected final String retrievePasswordFromResponse(final String proxyTicket) {
         final String url = this. + (this..contains("?") ? "&" : "?") + "ticket=" + proxyTicket;
         final String response = CommonUtils.getResponseFromServer(url);
         final String password = XmlUtils.getTextForElement(response"credentials");
 
         if (password != null) {
             return password;
         }
 
         log.error("Unable to Retrieve Password.  Full Response from ClearPass was [" + response + "]");
         return null;
     }


    
Copied from org.jasig.portal.security.provider.CacheSecurityContext
 
 	private class CacheOpaqueCredentials extends ChainingOpaqueCredentials implements NotSoOpaqueCredentials {
 
 		private static final long serialVersionUID = 1l;
 
 		public String getCredentials() {
             return this. != null ? new String(this.) : null;
		}
	}
New to GrepCode? Check out our FAQ X