class AuthorizationRequestEndpoint extends ServerResource {

    @Post
    public Representation requestAuthorization(JsonRepresentation entity) throws BadRequestException, UmaException,
            EntitlementException, ServerException, NotFoundException {
        UmaProviderSettings umaProviderSettings = umaProviderSettingsFactory.get(this.getRequest());
        final OAuth2Request oauth2Request = requestFactory.create(getRequest());
        OAuth2ProviderSettings oauth2ProviderSettings = oauth2ProviderSettingsFactory.get(oauth2Request);
        OAuth2Uris oAuth2Uris = oAuth2UrisFactory.get(oauth2Request);
        final UmaTokenStore umaTokenStore = umaProviderSettings.getUmaTokenStore();
        String realm = oauth2Request.getParameter("realm");

        JsonValue requestBody = json(toMap(entity));

        PermissionTicket permissionTicket = getPermissionTicket(umaTokenStore, requestBody);
        validatePermissionTicketHolder(umaTokenStore, permissionTicket);

        final String resourceSetId = permissionTicket.getResourceSetId();
        final Request request = getRequest();
        final String resourceOwnerId = getResourceOwnerId(oauth2ProviderSettings, resourceSetId);

        AMIdentity resourceOwner = createIdentity(resourceOwnerId, realm);
        String requestingPartyId = null;
        try {
            requestingPartyId = getRequestingPartyId(umaProviderSettings, oAuth2Uris, requestBody);
        } finally {
            auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.REQUEST, request,
                    requestingPartyId == null ? getAuthorisationApiToken().getResourceOwnerId() : requestingPartyId);
        }

        if (isEntitled(umaProviderSettings, oauth2ProviderSettings, permissionTicket, requestingPartyId)) {
            getResponse().setStatus(new Status(200));
            auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.GRANTED, request, requestingPartyId);
            return createJsonRpt(umaTokenStore, permissionTicket);
        } else {
            try {
                if (verifyPendingRequestDoesNotAlreadyExist(resourceSetId, resourceOwnerId, permissionTicket.getRealm(),
                        requestingPartyId, permissionTicket.getScopes())) {
                    auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.DENIED, request, requestingPartyId);
                    throw new UmaException(403, UmaConstants.NOT_AUTHORISED_ERROR_CODE,
                            "The client is not authorised to access the requested resource set");
                } else {
                    pendingRequestsService.createPendingRequest(ServletUtils.getRequest(getRequest()), resourceSetId,
                            auditLogger.getResourceName(resourceSetId, request), resourceOwnerId, requestingPartyId,
                            permissionTicket.getRealm(), permissionTicket.getScopes());
                    auditLogger.log(resourceSetId, resourceOwner, UmaAuditType.REQUEST_SUBMITTED, request,
                            requestingPartyId);
                }
            } catch (org.forgerock.openam.sm.datalayer.store.ServerException e) {
                logger.error("Failed to create pending request", e);
                throw new UmaException(403, UmaConstants.NOT_AUTHORISED_ERROR_CODE, "Failed to create pending request");
            }
            throw newRequestSubmittedException();
        }
    }

    @Inject public  AuthorizationRequestEndpoint(UmaProviderSettingsFactory umaProviderSettingsFactory,
            TokenStore oauth2TokenStore, OAuth2RequestFactory requestFactory,
            OAuth2ProviderSettingsFactory oauth2ProviderSettingsFactory, OAuth2UrisFactory<RealmInfo> oAuth2UrisFactory,
            UmaAuditLogger auditLogger, PendingRequestsService pendingRequestsService,
            Map<String, ClaimGatherer> claimGatherers, ExtensionFilterManager extensionFilterManager,
            UmaExceptionHandler exceptionHandler, JacksonRepresentationFactory jacksonRepresentationFactory);

}