Search in sources :

Example 51 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method searchTokens.

/**
     * 
     * @param subject
     * @param queryString
     * @return JSON array of tokens matching the queryString
     * @throws CoreTokenException
     */
public JSONArray searchTokens(Subject subject, String queryString) throws CoreTokenException {
    try {
        SSOToken token = SubjectUtils.getSSOToken(subject);
        if (token == null) {
            throw new CoreTokenException(216, null, 401);
        }
        JSONArray results = new JSONArray();
        if (SMSEntry.checkIfEntryExists(SERVICE_DN, token)) {
            String filter = createSearchFilter(queryString);
            Set<String> dns = SMSEntry.search(token, SERVICE_DN, filter, 0, 0, false, false);
            for (String dn : dns) {
                if (!LDAPUtils.dnEquals(SERVICE_DN, dn)) {
                    results.put(LDAPUtils.rdnValueFromDn(dn));
                }
            }
        }
        return results;
    } catch (SMSException ex) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.searchToken", ex);
        throw new CoreTokenException(215, ex);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) JSONArray(org.json.JSONArray) CoreTokenException(com.sun.identity.coretoken.CoreTokenException)

Example 52 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class LogManagerUtil method logEndRecords.

/**
     *  Log a LogRecord indicating the end of logging to all opened files
     */
public static void logEndRecords() {
    if (lmgr != null) {
        try {
            SSOToken ssot = getLoggingSSOToken();
            LogMessageProviderBase provider = (LogMessageProviderBase) MessageProviderFactory.getProvider("Logging");
            String[] s = new String[1];
            Enumeration e = lmgr.getLoggerNames();
            com.sun.identity.log.LogRecord lr = null;
            while (e.hasMoreElements()) {
                String logger = (String) e.nextElement();
                if (logger.length() != 0 && !logger.equals("global")) {
                    Logger result = (Logger) Logger.getLogger(logger);
                    s[0] = logger;
                    lr = provider.createLogRecord(LogConstants.END_LOG_NAME, s, ssot);
                    result.log(lr, ssot);
                    result.flush();
                }
            }
        } catch (IOException ioex) {
        // can't do much here
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Enumeration(java.util.Enumeration) LogMessageProviderBase(com.sun.identity.log.messageid.LogMessageProviderBase) IOException(java.io.IOException)

Example 53 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class Logger method extractInfoFromLogFor.

static void extractInfoFromLogFor(ILogRecord rec) throws SSOException {
    Object logFor = rec.getLogFor();
    Object cred = (logFor instanceof Subject) ? getPrivateCred((Subject) logFor) : logFor;
    if (!(cred instanceof SSOToken)) {
        return;
    }
    SSOToken ssoToken = (SSOToken) cred;
    rec.addLogInfo(LogConstants.LOGIN_ID_SID, ssoToken.getTokenID().toString());
    String ctxID = ssoToken.getProperty(Constants.AM_CTX_ID);
    if ((ctxID != null) && (ctxID.length() > 0)) {
        rec.addLogInfo(LogConstants.CONTEXT_ID, ctxID);
    }
    resolveHostName(rec, ssoToken);
    String clientDomain = ssoToken.getProperty("Organization");
    if (clientDomain == null || clientDomain.length() == 0) {
        clientDomain = ssoToken.getProperty("cdomain");
    }
    rec.addLogInfo(LogConstants.DOMAIN, clientDomain);
    rec.addLogInfo(LogConstants.LOGIN_ID, ssoToken.getPrincipal().getName());
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /*
         * these are the compulsory fields ... to be logged even if there are
         * exceptions while getting domain, loginid, ipaddr, hostname
         */
    rec.addLogInfo(LogConstants.TIME, sdf.format(date));
    if (rec instanceof java.util.logging.LogRecord) {
        java.util.logging.LogRecord jLogRecord = (java.util.logging.LogRecord) rec;
        rec.addLogInfo(LogConstants.DATA, jLogRecord.getMessage());
        rec.addLogInfo(LogConstants.LOG_LEVEL, jLogRecord.getLevel().toString());
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogRecord(java.util.logging.LogRecord) LogRecord(java.util.logging.LogRecord) SimpleDateFormat(java.text.SimpleDateFormat) Subject(javax.security.auth.Subject) Date(java.util.Date)

Example 54 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class LogManager method logIt.

private void logIt(Logger logger, String[] msg, String msgName) {
    try {
        LogMessageProviderBase provider = (LogMessageProviderBase) MessageProviderFactory.getProvider("Logging");
        SSOToken ssot = LogManagerUtil.getLoggingSSOToken();
        com.sun.identity.log.LogRecord lr = provider.createLogRecord(msgName, msg, ssot);
        logger.log(lr, ssot);
        logger.flush();
    } catch (IOException ioex) {
        Debug.error("LogManager.logIt:could not log to " + logger.getName() + ": " + ioex.getMessage());
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogMessageProviderBase(com.sun.identity.log.messageid.LogMessageProviderBase) IOException(java.io.IOException)

Example 55 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method createAndPopulateTree.

/**
     * Populates a new instance of a index rule tree with policy path indexes retrieved from the associated realm.
     *
     * @param realm
     *         The realm for which policy path indexes are to be read from.
     * @return A newly created tree populated with rules configured against the realm.
     * @throws EntitlementException
     *         When an error occurs reading policy data.
     */
private IndexRuleTree createAndPopulateTree(String realm) throws EntitlementException {
    IndexRuleTree indexTree = null;
    String baseDN = String.format(REALM_DN_TEMPLATE, dnMapper.orgNameToDN(realm));
    SSOToken token = AccessController.doPrivileged(adminAction);
    if (smDAO.checkIfEntryExists(baseDN, token)) {
        indexTree = new SimpleReferenceTree();
        try {
            Set<String> excludes = Collections.emptySet();
            // Carry out search.
            Iterator<SMSDataEntry> i = smDAO.search(token, baseDN, SEARCH_FILTER, 0, 0, false, false, excludes);
            while (i.hasNext()) {
                SMSDataEntry e = i.next();
                // Suppressed warning as unchecked assignment is valid.
                @SuppressWarnings("unchecked") Set<String> policyPathIndexes = e.getAttributeValues(INDEX_PATH_ATT);
                indexTree.addIndexRules(policyPathIndexes);
            }
        } catch (SMSException smsE) {
            throw new EntitlementException(52, new Object[] { baseDN }, smsE);
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message(String.format("Index rule tree created for '%s'.", realm));
        }
    }
    return indexTree;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SimpleReferenceTree(org.forgerock.openam.entitlement.utils.indextree.SimpleReferenceTree) SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Aggregations

SSOToken (com.iplanet.sso.SSOToken)776 SSOException (com.iplanet.sso.SSOException)390 Set (java.util.Set)226 SMSException (com.sun.identity.sm.SMSException)218 HashSet (java.util.HashSet)179 IdRepoException (com.sun.identity.idm.IdRepoException)144 HashMap (java.util.HashMap)130 Test (org.testng.annotations.Test)130 CLIException (com.sun.identity.cli.CLIException)117 Iterator (java.util.Iterator)115 AMIdentity (com.sun.identity.idm.AMIdentity)113 Map (java.util.Map)113 IOutput (com.sun.identity.cli.IOutput)99 IOException (java.io.IOException)68 List (java.util.List)57 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)56 IdType (com.sun.identity.idm.IdType)54 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)53 EntitlementException (com.sun.identity.entitlement.EntitlementException)52 ServiceConfig (com.sun.identity.sm.ServiceConfig)52