Search in sources :

Example 46 with SSOToken

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

the class RealmTest method createRealmTwice.

/**
     * Test case for Issue #181. When a realm is deleted and created
     * again, it fails with "Realm already exists".
     */
//, expectedExceptions={SMSException.class})
@Test(groups = { "api" })
public void createRealmTwice() throws SMSException, SSOException {
    SSOToken adminToken = getAdminSSOToken();
    OrganizationConfigManager ocm = new OrganizationConfigManager(adminToken, "/");
    String realm = "sm-issue181-create-realm-twice";
    ocm.createSubOrganization(realm, Collections.EMPTY_MAP);
    ocm.deleteSubOrganization(realm, true);
    ocm.createSubOrganization(realm, Collections.EMPTY_MAP);
    ocm.deleteSubOrganization(realm, true);
    ocm.createSubOrganization(realm, Collections.EMPTY_MAP);
    ocm.deleteSubOrganization(realm, true);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Test(org.testng.annotations.Test)

Example 47 with SSOToken

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

the class UmaPolicyServiceImpl method getLoggedInUserId.

private String getLoggedInUserId(Context context) throws InternalServerErrorException {
    try {
        SubjectContext subjectContext = context.asContext(SubjectContext.class);
        SSOToken token = subjectContext.getCallerSSOToken();
        return token.getPrincipal().getName();
    } catch (SSOException e) {
        throw new InternalServerErrorException(e);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException)

Example 48 with SSOToken

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

the class RemoveRedundantDefaultApplicationTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    initMocks(this);
    System.setProperty("com.iplanet.am.version", "12.0.0");
    SSOToken token = mock(SSOToken.class);
    given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("abc");
    given(ssoTokenAction.run()).willReturn(token);
    upgradeStep = new RemoveRedundantDefaultApplication(asSet("app1", "app2"), applicationService, ssoTokenAction, connectionFactory);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 49 with SSOToken

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

the class TokenCleanupRunnable method run.

public void run() {
    if (!runCleanup()) {
        // no need to run cleanup on this instance
        return;
    }
    CoreTokenUtils.debug.message("TokenCleanupRunnable.run : START");
    Set<String> tokenSet = getAllTokens();
    Iterator<String> tokens = tokenSet.iterator();
    if (CoreTokenUtils.debug.messageEnabled()) {
        CoreTokenUtils.debug.message("TokenCleanupRunnable.run : found " + tokenSet.size() + " tokens");
    }
    while (tokens.hasNext()) {
        String token = tokens.next();
        String dn = OpenSSOCoreTokenStore.getCoreTokenDN(token);
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        if (SMSEntry.checkIfEntryExists(dn, adminToken)) {
            try {
                SMSEntry s = new SMSEntry(adminToken, dn);
                String tokenExpiry = getTokenExpiry(s);
                if (CoreTokenUtils.isTokenExpired(tokenExpiry)) {
                    s.delete();
                    // add logging
                    TokenLogUtils.access(Level.INFO, TokenLogUtils.EXPIRED_TOKEN_DELETE_SUCCESS, null, null, token);
                    if (CoreTokenUtils.debug.messageEnabled()) {
                        CoreTokenUtils.debug.message("TokenCleanupRunnable" + ".run: removed expired token " + token);
                    }
                }
            } catch (SMSException ex) {
                CoreTokenUtils.debug.error("TokenCleanupRunnable.run", ex);
            } catch (SSOException ex) {
                CoreTokenUtils.debug.error("TokenCleanupRunnable.run", ex);
            } catch (CoreTokenException ce) {
                CoreTokenUtils.debug.error("TokenCleanupRunnable.run", ce);
            }
        }
    }
    CoreTokenUtils.debug.message("TokenCleanupRunnable.run : END");
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

Example 50 with SSOToken

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

the class OpenSSOCoreTokenStore method updateToken.

/**
     * Updates a token.
     * @param subject caller subject.
     * @param tokenId token.id of the token to be updated.
     * @param eTag
     * @param newVals
     * @throws CoreTokenException
     * @throws JSONException
     */
public void updateToken(Subject subject, String tokenId, String eTag, JSONObject newVals) throws CoreTokenException, JSONException {
    SSOToken token = SubjectUtils.getSSOToken(subject);
    if (token == null) {
        throw new CoreTokenException(210, null, 401);
    }
    String dn = null;
    try {
        dn = getCoreTokenDN(tokenId);
        if (SMSEntry.checkIfEntryExists(dn, token)) {
            SMSEntry s = new SMSEntry(token, dn);
            String tokenAttrs = getTokenAttributeValueFromSM(s, JSON_ATTR);
            JSONObject json = new JSONObject(tokenAttrs);
            checkETag(eTag, json, tokenId);
            // validate attribute names and convert to lower case
            newVals = validateAndToLowerCase(newVals);
            // token.id attribute can't be modified
            if (newVals.has(CoreTokenConstants.TOKEN_ID)) {
                throw new CoreTokenException(221, null, 409);
            }
            // token.type attribute can't be modified
            if (newVals.has(CoreTokenConstants.TOKEN_TYPE)) {
                throw new CoreTokenException(224, null, 409);
            }
            json = updateAttributeValues(json, newVals);
            Map<String, Set<String>> map = validateAndCreateMap(tokenId, json);
            s.setAttributes(map);
            s.save();
        } else {
            throw new CoreTokenException(203, null, 404);
        }
    } catch (SMSException e) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.updateToken", e);
        throw new CoreTokenException(206, null, e);
    } catch (SSOException e) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.updateToken", e);
        throw new CoreTokenException(301, null, e);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) JSONObject(org.json.JSONObject) SMSException(com.sun.identity.sm.SMSException) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

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