Search in sources :

Example 91 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException in project OpenAM by OpenRock.

the class PendingRequestEmailTemplate method getLocale.

private Locale getLocale(String username, String realm) {
    try {
        String localeAttributeName = settingsFactory.get(realm).getUserProfilePreferredLocaleAttribute();
        if (localeAttributeName != null) {
            AMIdentity identity = IdUtils.getIdentity(username, realm);
            @SuppressWarnings("unchecked") Set<String> localeAttribute = identity.getAttribute(localeAttributeName);
            if (localeAttribute != null && !localeAttribute.isEmpty()) {
                return Locale.forLanguageTag(CollectionUtils.getFirstItem(localeAttribute, ""));
            }
        }
        String defaultLocale = authServiceSettings.getStringSetting(realm, "iplanet-am-auth-locale");
        if (defaultLocale != null) {
            return Locale.forLanguageTag(defaultLocale);
        }
    } catch (SSOException | IdRepoException | ServerException | SMSException | NotFoundException e) {
        debug.warning("Failed to get locale for user, " + username + ", in realm, " + realm, e);
    }
    return Locale.ROOT;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) SSOException(com.iplanet.sso.SSOException)

Example 92 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException in project OpenAM by OpenRock.

the class UmaTokenStore method deleteRPT.

public void deleteRPT(String id) throws NotFoundException, ServerException {
    try {
        // check token is RPT
        readRPT(id);
        cts.delete(id);
    } catch (CoreTokenException e) {
        throw new ServerException("Could not delete token: " + id);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 93 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException in project OpenAM by OpenRock.

the class UmaUrisFactory method get.

/**
     * <p>Gets the instance of the UmaProviderSettings.</p>
     *
     * <p>Cache each provider settings on the realm it was created for.</p>
     *
     * @param context The context instance from which the base URL can be deduced.
     * @param realmInfo The realm.
     * @return The OAuth2ProviderSettings instance.
     */
public UmaUris get(Context context, RealmInfo realmInfo) throws NotFoundException, ServerException {
    String absoluteRealm = realmInfo.getAbsoluteRealm();
    HttpContext httpContext = context.asContext(HttpContext.class);
    String baseUrl;
    try {
        baseUrl = baseURLProviderFactory.get(absoluteRealm).getRealmURL(httpContext, "/uma", absoluteRealm);
    } catch (InvalidBaseUrlException e) {
        throw new ServerException("Configuration error");
    }
    UmaUris uris = urisMap.get(baseUrl);
    if (uris == null) {
        OAuth2Uris oAuth2Uris = oAuth2UriFactory.get(context, realmInfo);
        uris = get(absoluteRealm, oAuth2Uris, baseUrl);
    }
    return uris;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) OAuth2Uris(org.forgerock.oauth2.core.OAuth2Uris) HttpContext(org.forgerock.json.resource.http.HttpContext) InvalidBaseUrlException(org.forgerock.openam.services.baseurl.InvalidBaseUrlException)

Example 94 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException in project OpenAM by OpenRock.

the class UmaTokenStore method createRPT.

RequestingPartyToken createRPT(PermissionTicket permissionTicket) throws ServerException, NotFoundException {
    UmaProviderSettings settings = settingsFactory.get(realm);
    Permission permission = new Permission(permissionTicket.getResourceSetId(), permissionTicket.getScopes());
    RequestingPartyToken rpt = new RequestingPartyToken(null, permissionTicket.getResourceServerClientId(), asSet(permission), System.currentTimeMillis() + (settings.getRPTLifetime() * 1000), permissionTicket.getId(), permissionTicket.getClientClientId());
    rpt.setRealm(realm);
    try {
        cts.create(rptAdapter.toToken(rpt));
    } catch (CoreTokenException e) {
        throw new ServerException(e);
    }
    return rpt;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 95 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException in project OpenAM by OpenRock.

the class UmaResourceSetRegistrationHook method resourceSetCreated.

/**
     * Creates a ResourceType for the Resource Set and adds it to the Resource Server's policy Application.
     *
     * @param realm {@inheritDoc}
     * @param resourceSet {@inheritDoc}
     */
@Override
public void resourceSetCreated(String realm, ResourceSetDescription resourceSet) throws ServerException {
    Map<String, Boolean> resourceTypeActions = new HashMap<String, Boolean>();
    for (String umaScope : resourceSet.getScopes()) {
        resourceTypeActions.put(umaScope, Boolean.TRUE);
    }
    ResourceType resourceType = ResourceType.builder().setName(resourceSet.getName() + " - " + resourceSet.getId()).setUUID(resourceSet.getId()).setDescription("Dynamically created resource type for the UMA resource set. " + "Used to find all Policy Engine Policies that make up an UMA Policy").setActions(resourceTypeActions).addPattern(UmaConstants.UMA_POLICY_SCHEME_PATTERN).build();
    Subject adminSubject = SubjectUtils.createSuperAdminSubject();
    try {
        resourceTypeService.saveResourceType(adminSubject, realm, resourceType);
    } catch (EntitlementException e) {
        logger.error("Failed to create resource type for resource set, {}", resourceSet, e);
        throw new ServerException(e);
    }
    try {
        Application application = applicationManager.getApplication(adminSubject, realm, resourceSet.getClientId().toLowerCase());
        application.addResourceTypeUuid(resourceType.getUUID());
        applicationManager.saveApplication(adminSubject, realm, application);
    } catch (EntitlementException e) {
        logger.error("Failed to add Resource Type, " + resourceType.getUUID() + " to application, " + resourceSet.getClientId(), e);
        throw new ServerException(e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) HashMap(java.util.HashMap) ResourceType(org.forgerock.openam.entitlement.ResourceType) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)60 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)31 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)25 JsonValue (org.forgerock.json.JsonValue)18 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)18 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)14 HashMap (java.util.HashMap)13 AccessToken (org.forgerock.oauth2.core.AccessToken)13 HashSet (java.util.HashSet)12 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 SSOException (com.iplanet.sso.SSOException)9 Request (org.restlet.Request)9 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8 Map (java.util.Map)7 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)7 JSONObject (org.json.JSONObject)7 SMSException (com.sun.identity.sm.SMSException)6 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)6