Search in sources :

Example 1 with WSSecurityException

use of com.ibm.websphere.security.WSSecurityException in project iaf by ibissource.

the class SsoUtil method getSsoToken.

public static String getSsoToken() throws WSSecurityException, CredentialDestroyedException, CredentialExpiredException {
    String result = null;
    Subject subj = WSSubject.getCallerSubject();
    if (subj == null) {
        throw new WSSecurityException("could not find Subject");
    }
    Set pubs = subj.getPublicCredentials();
    if (pubs == null) {
        throw new WSSecurityException("could not find PublicCredentials");
    }
    for (Iterator it = pubs.iterator(); result == null && it.hasNext(); ) {
        Object pc = it.next();
        if (pc instanceof WSCredentialImpl) {
            WSCredentialImpl wsci = (WSCredentialImpl) pc;
            byte[] token = wsci.getCredentialToken();
            if (token != null && token.length > 0) {
                result = Base64.encodeBase64String(token);
            }
        }
    }
    return result;
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) WSSecurityException(com.ibm.websphere.security.WSSecurityException) WSCredentialImpl(com.ibm.ws.security.auth.WSCredentialImpl) WSSubject(com.ibm.websphere.security.auth.WSSubject) Subject(javax.security.auth.Subject)

Aggregations

WSSecurityException (com.ibm.websphere.security.WSSecurityException)1 WSSubject (com.ibm.websphere.security.auth.WSSubject)1 WSCredentialImpl (com.ibm.ws.security.auth.WSCredentialImpl)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Subject (javax.security.auth.Subject)1