Search in sources :

Example 16 with Vector

use of java.util.Vector in project OpenAM by OpenRock.

the class FSSingleLogoutHandler method doWMLGet.

/**
     * Performs the HTTP GET related operations when the user agent is
     * WML based.
     * @param providerId the first provider whose preferred profile is HTTP GET
     */
private FSLogoutStatus doWMLGet(String providerId) {
    FSUtils.debug.message("In WML based response");
    StringBuffer destination = new StringBuffer();
    destination.append(hostedDescriptor.getSingleLogoutServiceURL());
    if ((destination.toString()).indexOf(QUESTION_MARK) == -1) {
        destination.append(QUESTION_MARK);
    } else {
        destination.append(AMPERSAND);
    }
    destination.append("logoutSource=logoutGet");
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("Submit action : " + destination.toString());
    }
    // DO WML response
    FSUtils.debug.message("Calling getLogoutGETProviders");
    HashMap providerMap = FSLogoutUtil.getLogoutGETProviders(userID, providerId, sessionIndex, realm, metaAlias);
    Vector providerGetList = (Vector) providerMap.get("Provider");
    FSUtils.debug.message("Calling cleanSessionMapProviders");
    FSLogoutUtil.cleanSessionMapProviders(userID, providerGetList, metaAlias);
    FSUtils.debug.message("Calling getMultiLogoutRequest");
    String multiLogoutRequest = getMultiLogoutRequest(providerMap);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("Image Statements : " + multiLogoutRequest);
    }
    request.setAttribute("DESTINATION_URL", destination.toString());
    request.setAttribute("MULTI_LOGOUT_REQUEST", multiLogoutRequest);
    try {
        request.getRequestDispatcher(WML_LOGOUT_JSP).forward(request, response);
    } catch (ServletException sE) {
        FSUtils.debug.error("Error in performing HTTP GET for WML agent:", sE);
        return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
    } catch (IOException ioE) {
        FSUtils.debug.error("Error in performing HTTP GET for WML agent:", ioE);
        return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
    }
    return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
}
Also used : ServletException(javax.servlet.ServletException) HashMap(java.util.HashMap) IOException(java.io.IOException) Vector(java.util.Vector)

Example 17 with Vector

use of java.util.Vector in project OpenAM by OpenRock.

the class FSSingleLogoutHandler method processSingleLogoutRequest.

/**
     * Processes the logout request received from soap profile.
     * @param reqLogout the logout request
     * @param currentSessionProvider initial provider with whom to broadcast
     * @param userID who is presently logging out
     * @param sourceEntityId remote provider id
     * @param sessionIndex to be sent as part of logout message
     * @param isWMLAgent determines if response to be sent to AML agent
     * @param isSourceIDP determines the role of the provider
     * @return logout status
     */
protected FSLogoutStatus processSingleLogoutRequest(FSLogoutNotification reqLogout, FSSessionPartner currentSessionProvider, String userID, String sourceEntityId, String sessionIndex, boolean isWMLAgent, String isSourceIDP) {
    FSUtils.debug.message("Entered FSSingleLogoutHandler::processSingleLogoutRequest - SOAP");
    if (currentSessionProvider != null) {
        isCurrentProviderIDPRole = currentSessionProvider.getIsRoleIDP();
        remoteEntityId = currentSessionProvider.getPartner();
        setRemoteDescriptor(getRemoteDescriptor(remoteEntityId));
    }
    this.requestLogout = reqLogout;
    this.userID = userID;
    this.sessionIndex = sessionIndex;
    this.isWMLAgent = isWMLAgent;
    if (reqLogout != null) {
        FSUtils.debug.message("FSLogoutNotification formed really well");
        if (currentSessionProvider == null) {
            FSUtils.debug.message("currentSessionProvider is null. destroy and return");
            // get ssoToken corresponding to the session index
            Vector sessionObjList = FSLogoutUtil.getSessionObjectList(userID, metaAlias, sessionIndex);
            if ((sessionObjList != null) && !sessionObjList.isEmpty()) {
                String sessid = ((FSSession) sessionObjList.get(0)).getSessionID();
                try {
                    ssoToken = SessionManager.getProvider().getSession(sessid);
                } catch (SessionException ex) {
                // ignore;
                }
            }
            // handle idp proxy case
            FSLogoutStatus proxyStatus = handleIDPProxyLogout(sourceEntityId);
            if (proxyStatus != null && !proxyStatus.getStatus().equalsIgnoreCase(IFSConstants.SAML_SUCCESS)) {
                logoutStatus = false;
            }
            FSLogoutUtil.destroyPrincipalSession(userID, metaAlias, reqLogout.getSessionIndex(), request, response);
            // call multi-federation protocol processing
            int retStatus = handleMultiProtocolLogout(true, null, sourceEntityId);
            if ((retStatus == SingleLogoutManager.LOGOUT_FAILED_STATUS) || (retStatus == SingleLogoutManager.LOGOUT_PARTIAL_STATUS)) {
                return new FSLogoutStatus(IFSConstants.LOGOUT_FAILURE);
            } else {
                return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
            }
        } else {
            // get ssoToken corresponding to the session index
            Vector sessionObjList = FSLogoutUtil.getSessionObjectList(userID, metaAlias, sessionIndex);
            if ((sessionObjList != null) && !sessionObjList.isEmpty()) {
                String sessid = ((FSSession) sessionObjList.get(0)).getSessionID();
                try {
                    ssoToken = SessionManager.getProvider().getSession(sessid);
                } catch (SessionException ex) {
                // ignore;
                }
            }
            // handle idp proxy case.
            FSLogoutStatus proxyStatus = handleIDPProxyLogout(sourceEntityId);
            // Check if any of the connections use HTTP GET/Redirect
            String currentEntityId = currentSessionProvider.getPartner();
            isCurrentProviderIDPRole = currentSessionProvider.getIsRoleIDP();
            if (!supportSOAPProfile(remoteDescriptor)) {
                return new FSLogoutStatus(IFSConstants.SAML_UNSUPPORTED);
            }
            FSSessionManager sessionManager = FSSessionManager.getInstance(metaAlias);
            FSSession session = sessionManager.getSession(sessionManager.getSessionList(userID), sessionIndex);
            FSUtils.debug.message("FSSLOHandler, process logout case 4");
            FSLogoutUtil.cleanSessionMapPartnerList(userID, currentEntityId, metaAlias, session);
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Communicate with provider " + currentEntityId + " using soap profile.");
            }
            // In the middle of a SOAP call you can only use
            // SOAP profile
            FSUtils.debug.message("In SOAP profile");
            // This func should take care of initiating
            // next provider also as it has control
            FSLogoutStatus bLogoutStatus = doIDPSoapProfile(currentEntityId);
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Logout completed first round " + "with status : " + bLogoutStatus);
            }
            if (bLogoutStatus.getStatus().equalsIgnoreCase(IFSConstants.SAML_SUCCESS) && (proxyStatus != null) && !proxyStatus.getStatus().equalsIgnoreCase(IFSConstants.SAML_SUCCESS)) {
                bLogoutStatus = proxyStatus;
            }
            return bLogoutStatus;
        }
    } else {
        String[] data = { userID };
        LogUtil.error(Level.INFO, LogUtil.LOGOUT_FAILED_REQUEST_IMPROPER, data);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("Request not proper " + "Cannot proceed federation termination");
        }
        return new FSLogoutStatus(IFSConstants.SAML_REQUESTER);
    }
}
Also used : FSSession(com.sun.identity.federation.services.FSSession) SessionException(com.sun.identity.plugin.session.SessionException) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) Vector(java.util.Vector)

Example 18 with Vector

use of java.util.Vector in project OpenAM by OpenRock.

the class FSSingleLogoutHandler method getMultiLogoutRequest.

/**
     * Prepares the IMG tags that correspond to Single logout requests that
     * will all be shown in a single page when HTTP GET profile is used.
     * @param providerMap contains information about all the providers
     *  for whom GET is the logout profile
     * @return String that has the IMG tags for each provider to be notified
     */
private String getMultiLogoutRequest(HashMap providerMap) {
    try {
        Vector providerList = (Vector) providerMap.get(IFSConstants.PROVIDER);
        HashMap sessionList = (HashMap) providerMap.get(IFSConstants.SESSION_INDEX);
        StringBuffer imgString = new StringBuffer();
        if (providerList != null) {
            for (int i = 0; i < providerList.size(); i++) {
                String providerId = (String) providerList.elementAt(i);
                FSAccountFedInfo currentAccount = FSLogoutUtil.getCurrentWorkingAccount(userID, providerId, metaAlias);
                FSLogoutNotification reqLogout = createSingleLogoutRequest(currentAccount, (String) sessionList.get(providerId));
                ProviderDescriptorType descriptor = metaManager.getSPDescriptor(realm, providerId);
                reqLogout.setMinorVersion(getMinorVersion(descriptor));
                String urlEncodedRequest = reqLogout.toURLEncodedQueryString();
                // Sign the request querystring
                String certAlias = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.SIGNING_CERT_ALIAS);
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("certalias  : " + certAlias);
                }
                if (certAlias == null || certAlias.length() == 0) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSingleLogoutHandler" + " getMultiLogoutRequest: couldn't obtain " + "this site's cert alias.");
                    }
                    continue;
                }
                urlEncodedRequest = FSSignatureUtil.signAndReturnQueryString(urlEncodedRequest, certAlias);
                StringBuffer redirectURL = new StringBuffer();
                String retURL = descriptor.getSingleLogoutServiceURL();
                redirectURL.append(retURL);
                if (retURL.indexOf(QUESTION_MARK) == -1) {
                    redirectURL.append(QUESTION_MARK);
                } else {
                    redirectURL.append(AMPERSAND);
                }
                redirectURL.append(urlEncodedRequest);
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSingleLogoutHandler::" + "doHttpRedirect URL is " + redirectURL.toString());
                }
                imgString.append("<IMG SRC=\"").append(redirectURL.toString()).append("\" />");
            }
            return imgString.toString();
        }
    } catch (FSMsgException e) {
        FSUtils.debug.error("FSSingleLogoutHandler::getMultiLogoutRequest" + " FSMsgException", e);
    } catch (IDFFMetaException e) {
        FSUtils.debug.error("FSSingleLogoutHandler::getMultiLogoutRequest" + "  IDFFMetaException", e);
    }
    FSUtils.debug.error("Returning null from getMultiLogoutRequest");
    return null;
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) FSAccountFedInfo(com.sun.identity.federation.accountmgmt.FSAccountFedInfo) HashMap(java.util.HashMap) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) ProviderDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType) FSLogoutNotification(com.sun.identity.federation.message.FSLogoutNotification) Vector(java.util.Vector)

Example 19 with Vector

use of java.util.Vector in project OpenAM by OpenRock.

the class FSLogoutUtil method getLogoutGETProviders.

/**
     * Returns the list of all providers who want to be
     * notified of logout using HTTP GET profile.
     * @param userID principal who needs to be logged out
     * @param entityId current provider who uses HTTP GET profile for logout
     * @param sessionIndex for the current provider
     * @param realm the realm in which the provider resides
     * @param metaAlias the hosted provider performing logout
     * @return HashMap list of providers who indicate preference to be notified 
     * of logout using GET profile
     */
protected static HashMap getLogoutGETProviders(String userID, String entityId, String sessionIndex, String realm, String metaAlias) {
    try {
        FSUtils.debug.message("Entered FSLogoutUtil::getLogoutGETProviders");
        HashMap retMap = new HashMap();
        Vector providerVector = new Vector();
        HashMap sessionProvider = new HashMap();
        providerVector.addElement(entityId);
        sessionProvider.put(entityId, sessionIndex);
        FSSessionManager sessionMgr = FSSessionManager.getInstance(metaAlias);
        synchronized (sessionMgr) {
            FSUtils.debug.message("About to call getSessionList");
            List sessionList = sessionMgr.getSessionList(userID);
            if (sessionList != null && !sessionList.isEmpty()) {
                FSUtils.debug.message("Session List is not empty");
                Iterator iSessionIter = sessionList.iterator();
                FSSession sessionObj;
                while (iSessionIter.hasNext()) {
                    sessionObj = (FSSession) iSessionIter.next();
                    if ((sessionObj.getSessionPartners()).isEmpty()) {
                        continue;
                    } else {
                        String nSessionIndex = sessionObj.getSessionIndex();
                        List sessionPartners = sessionObj.getSessionPartners();
                        Iterator iPartnerIter = sessionPartners.iterator();
                        FSSessionPartner sessionPartner;
                        while (iPartnerIter.hasNext()) {
                            sessionPartner = (FSSessionPartner) iPartnerIter.next();
                            // Only SP can specify GET profile for logout
                            if (!sessionPartner.getIsRoleIDP()) {
                                String curEntityId = sessionPartner.getPartner();
                                ProviderDescriptorType curDesc = metaManager.getSPDescriptor(realm, curEntityId);
                                if (curDesc != null) {
                                    List profiles = curDesc.getSingleLogoutProtocolProfile();
                                    if (profiles != null && !profiles.isEmpty()) {
                                        if (((String) profiles.iterator().next()).equals(IFSConstants.LOGOUT_IDP_GET_PROFILE)) {
                                            if (FSUtils.debug.messageEnabled()) {
                                                FSUtils.debug.message("provider " + curEntityId + " Added for GET");
                                            }
                                            providerVector.addElement(curEntityId);
                                            sessionProvider.put(curEntityId, nSessionIndex);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("Session List is  empty, returning " + "current provider from getLogoutGETProviders");
                }
            }
            retMap.put(IFSConstants.PROVIDER, providerVector);
            retMap.put(IFSConstants.SESSION_INDEX, sessionProvider);
            return retMap;
        }
    } catch (IDFFMetaException e) {
        FSUtils.debug.error("IDFFMetaException in function " + " getLogoutGETProviders", e);
        return null;
    }
}
Also used : FSSessionPartner(com.sun.identity.federation.services.FSSessionPartner) HashMap(java.util.HashMap) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) ProviderDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType) Iterator(java.util.Iterator) FSSession(com.sun.identity.federation.services.FSSession) List(java.util.List) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) Vector(java.util.Vector)

Example 20 with Vector

use of java.util.Vector in project pulsar by yahoo.

the class EntryCacheTest method getLedgerHandle.

private static LedgerHandle getLedgerHandle() {
    final LedgerHandle lh = mock(LedgerHandle.class);
    final LedgerEntry ledgerEntry = mock(LedgerEntry.class, Mockito.CALLS_REAL_METHODS);
    doReturn(new byte[10]).when(ledgerEntry).getEntry();
    doReturn(Unpooled.wrappedBuffer(new byte[10])).when(ledgerEntry).getEntryBuffer();
    doReturn((long) 10).when(ledgerEntry).getLength();
    doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            long firstEntry = (Long) args[0];
            long lastEntry = (Long) args[1];
            ReadCallback callback = (ReadCallback) args[2];
            Object ctx = args[3];
            Vector<LedgerEntry> entries = new Vector<LedgerEntry>();
            for (int i = 0; i <= (lastEntry - firstEntry); i++) {
                entries.add(ledgerEntry);
            }
            callback.readComplete(0, lh, entries.elements(), ctx);
            return null;
        }
    }).when(lh).asyncReadEntries(anyLong(), anyLong(), any(ReadCallback.class), any());
    return lh;
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) ReadCallback(org.apache.bookkeeper.client.AsyncCallback.ReadCallback) Vector(java.util.Vector)

Aggregations

Vector (java.util.Vector)3045 IOException (java.io.IOException)239 ArrayList (java.util.ArrayList)224 Test (org.junit.Test)182 Enumeration (java.util.Enumeration)174 Iterator (java.util.Iterator)173 Hashtable (java.util.Hashtable)170 File (java.io.File)159 List (java.util.List)143 HashMap (java.util.HashMap)128 ResultSet (java.sql.ResultSet)122 SQLException (java.sql.SQLException)95 Collection (java.util.Collection)87 PreparedStatement (java.sql.PreparedStatement)79 StringTokenizer (java.util.StringTokenizer)79 Statement (java.sql.Statement)60 Fault (com.sun.ts.lib.harness.EETest.Fault)54 HashSet (java.util.HashSet)54 Expression (cbit.vcell.parser.Expression)52 Map (java.util.Map)50