Package org.fluxtream.core.domain.oauth2

Examples of org.fluxtream.core.domain.oauth2.AuthorizationCode


    @Path("/{uid}")
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getApplication(@PathParam("uid") String uid) throws IOException {
        final long guestId = AuthHelper.getGuestId();
        try {
            final Application app = partnerAppsService.getApplication(guestId, uid);
            if (app!=null) {
                return Response.ok(mapper.writeValueAsString(new ApplicationModel(app))).build();
            } else {
                return Response.status(Response.Status.BAD_REQUEST).entity("No such application: " + uid).build();
            }
View Full Code Here


    public Response register(@PathParam("appSecret") final String appSecret,
                             @FormParam("email") final String email,
                             @FormParam("username") final String username,
                             @FormParam("firstname") final String firstname,
                             @FormParam("lastname") final String lastname) throws IOException {
        final Application application = partnerAppsService.getApplication(appSecret);
        if (application==null)
            return Responses.notFound().build();
        if (!application.registrationAllowed)
            return Response.status(Response.Status.FORBIDDEN).build();
        try {
            final Guest guest = guestService.createGuest(username, firstname, lastname, null, email, Guest.RegistrationMethod.REGISTRATION_METHOD_API, application.uid);
            final AuthorizationToken authorizationToken = oAuth2MgmtService.issueAuthorizationToken(guest.getId(), application.getId());
            TechnicalAuthorizationTokenModel authorizationTokenModel = new TechnicalAuthorizationTokenModel(authorizationToken, guest);
            final String json = (new ObjectMapper()).writeValueAsString(authorizationTokenModel);
            return Response.ok(json).build();
        } catch (UsernameAlreadyTakenException e) {
            return Response.status(Response.Status.BAD_REQUEST).entity("This username is already taken").build();
View Full Code Here

    }

    @Override
    @Transactional(readOnly=false)
    public AuthorizationCode issueAuthorizationCode(final Long id, final Set<String> scopes, final String state) {
        AuthorizationCode code = new AuthorizationCode(id, scopes, state);
        em.persist(code);
        return code;
    }
View Full Code Here

        return null;
    }

    @Override
    public AuthorizationCodeResponse getResponse(final String code) {
        AuthorizationCode authCode = getCode(code);
        if (authCode==null)
            return null;
        final TypedQuery<AuthorizationCodeResponse> query = em.createQuery(
                "SELECT authorizationCodeResponse FROM AuthorizationCodeResponse authorizationCodeResponse " +
                "WHERE authorizationCodeResponse.authorizationCodeId=?", AuthorizationCodeResponse.class);
        query.setParameter(1, authCode.getId());
        final List<AuthorizationCodeResponse> resultList = query.getResultList();
        if (resultList.size()>0)
            return resultList.get(0);
        return null;
    }
View Full Code Here

    @Override
    @Transactional(readOnly=false)
    public AuthorizationToken issueAuthorizationToken(long guestId, long applicationId)
    {
        AuthorizationCode code = new AuthorizationCode(guestId, null, null);
        code.applicationId = applicationId;
        em.persist(code);
        AuthorizationToken token = new AuthorizationToken(guestId);
        token.authorizationCodeId = code.getId();
        em.persist(token);
        return token;
    }
View Full Code Here

                        "WHERE authorizationToken.guestId=?", AuthorizationToken.class);
        query.setParameter(1, guestId);
        final List<AuthorizationToken> resultList = query.getResultList();
        final List<AuthorizationTokenModel> tokenModels = new ArrayList<AuthorizationTokenModel>();
        for (AuthorizationToken authorizationToken : resultList) {
            AuthorizationCode authCode = em.find(AuthorizationCode.class, authorizationToken.authorizationCodeId);
            Application application = em.find(Application.class, authCode.applicationId);
            AuthorizationTokenModel tokenModel = new AuthorizationTokenModel(authorizationToken.accessToken,
                    application.name, application.organization, application.website, authCode.creationTime);
            tokenModels.add(tokenModel);
        }
View Full Code Here

        query.executeUpdate();
    }

    @Override
    public Application getApplicationForToken(final AuthorizationToken token) {
        final AuthorizationCode authorizationCode = em.find(AuthorizationCode.class, token.authorizationCodeId);
        if (authorizationCode!=null) {
            Application application = em.find(Application.class, authorizationCode.applicationId);
            return application;
        }
        return null;
View Full Code Here

            response.setStatus(oauthResponse.getResponseStatus());
            return oauthResponse.getBody();
        }

        // Create the temporary code to be granted or rejected by the user.
        AuthorizationCode code = oAuth2MgmtService.issueAuthorizationCode(application.getId(),
                                                                          oauthRequest.getScopes(),
                                                                          oauthRequest.getState());

        // Set the redirect.
        response.sendRedirect(OAuthASResponse.authorizationResponse(request, HttpServletResponse.SC_FOUND)
View Full Code Here

        // reason, an exception will be thrown and the page will echo back the
        // reason.
        Guest guest = AuthHelper.getGuest();

        // Get the authorization code.
        AuthorizationCode authCode = oAuth2MgmtService.getCode(code);

        // If the code is unknown, we cannot redirect back to the third-party
        // because we don't know who they are.
        if (authCode == null) {
            throw new RuntimeException("The authorization code is unknown.");
View Full Code Here

                response.setStatus(oauthResponse.getResponseStatus());
                return oauthResponse.getBody();
            }

            // Attempt to lookup the actual AuthorizationCode object.
            AuthorizationCode code = oAuth2MgmtService.getCode(codeString);
            // If the code doesn't exist, reject the request.
            if (code == null) {
                // Create the OAuth response.
                OAuthResponse oauthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST)
                        .setError(OAuthError.TokenResponse.INVALID_REQUEST)
View Full Code Here

TOP

Related Classes of org.fluxtream.core.domain.oauth2.AuthorizationCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.