public ServerAccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException { ServerAccessToken token = new BearerAccessToken(reg.getClient(), 3600L); List<String> scope = reg.getApprovedScope().isEmpty() ? reg.getRequestedScope() : reg.getApprovedScope(); token.setScopes(convertScopeToPermissions(reg.getClient(), scope)); token.setSubject(reg.getSubject()); token.setGrantType(reg.getGrantType()); at = token; return token; }
protected AccessTokenRegistration createTokenRegistration(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject) { AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(super.getSupportedGrantType()); reg.setResponseType(state.getResponseType()); reg.setSubject(userSubject); reg.setRequestedScope(requestedScope); reg.setApprovedScope(getApprovedScope(requestedScope, approvedScope)); reg.setAudiences(Collections.singletonList(state.getAudience())); reg.setNonce(state.getNonce()); reg.getExtraProperties().putAll(state.getExtraProperties()); return reg; } protected void finalizeResponse(StringBuilder sb, OAuthRedirectionState state) {
@Override public ServerAccessToken createAccessToken(final AccessTokenRegistration accessToken) throws OAuthServiceException { if (!accessToken.getRequestedScope().contains(OAuthConstants.REFRESH_TOKEN_SCOPE)) { accessToken.setRequestedScope(new ArrayList<>(accessToken.getRequestedScope())); accessToken.getRequestedScope().add(OAuthConstants.REFRESH_TOKEN_SCOPE); } if (!accessToken.getApprovedScope().contains(OAuthConstants.REFRESH_TOKEN_SCOPE)) { accessToken.setApprovedScope(new ArrayList<>(accessToken.getApprovedScope())); accessToken.getApprovedScope().add(OAuthConstants.REFRESH_TOKEN_SCOPE); } return delegate.createAccessToken(accessToken); }
protected ServerAccessToken doCreateAccessToken(Client client, UserSubject subject, String requestedGrant, List<String> requestedScopes, List<String> audiences) { ServerAccessToken token = getPreAuthorizedToken(client, subject, requestedGrant, requestedScopes, audiences); if (token != null) { return token; } // Delegate to the data provider to create the one AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(requestedGrant); reg.setSubject(subject); reg.setRequestedScope(requestedScopes); reg.setApprovedScope(getApprovedScopes(client, subject, requestedScopes)); reg.setAudiences(audiences); return dataProvider.createAccessToken(reg); }
protected ServerAccessToken doCreateAccessToken(AccessTokenRegistration atReg) { ServerAccessToken at = createNewAccessToken(atReg.getClient(), atReg.getSubject()); at.setAudiences(atReg.getAudiences()); at.setGrantType(atReg.getGrantType()); List<String> theScopes = atReg.getApprovedScope(); List<OAuthPermission> thePermissions = convertScopeToPermissions(atReg.getClient(), theScopes); at.setScopes(thePermissions); at.setSubject(atReg.getSubject()); at.setClientCodeVerifier(atReg.getClientCodeVerifier()); at.setNonce(atReg.getNonce()); at.setResponseType(atReg.getResponseType()); at.setGrantCode(atReg.getGrantCode()); at.getExtraProperties().putAll(atReg.getExtraProperties());
public ServerAccessToken createAccessToken(Client client, MultivaluedMap<String, String> params) throws OAuthServiceException { AccessTokenRegistration atr = new AccessTokenRegistration(); atr.setClient(client); return dataProvider.createAccessToken(atr); } }
@Override public ServerAccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException { ServerAccessToken at = doCreateAccessToken(reg); saveAccessToken(at); if (isRefreshTokenSupported(reg.getApprovedScope())) { createNewRefreshToken(at); } return at; }
protected ServerAccessToken doCreateAccessToken(Client client, UserSubject subject, String requestedGrant, List<String> requestedScopes, List<String> audiences) { ServerAccessToken token = getPreAuthorizedToken(client, subject, requestedGrant, requestedScopes, audiences); if (token != null) { return token; } // Delegate to the data provider to create the one AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(requestedGrant); reg.setSubject(subject); reg.setRequestedScope(requestedScopes); reg.setApprovedScope(getApprovedScopes(client, subject, requestedScopes)); reg.setAudiences(audiences); return dataProvider.createAccessToken(reg); }
protected ServerAccessToken doCreateAccessToken(AccessTokenRegistration atReg) { ServerAccessToken at = createNewAccessToken(atReg.getClient(), atReg.getSubject()); at.setAudiences(atReg.getAudiences()); at.setGrantType(atReg.getGrantType()); List<String> theScopes = atReg.getApprovedScope(); List<OAuthPermission> thePermissions = convertScopeToPermissions(atReg.getClient(), theScopes); at.setScopes(thePermissions); at.setSubject(atReg.getSubject()); at.setClientCodeVerifier(atReg.getClientCodeVerifier()); at.setNonce(atReg.getNonce()); at.setResponseType(atReg.getResponseType()); at.setGrantCode(atReg.getGrantCode()); at.getExtraProperties().putAll(atReg.getExtraProperties());
@Override public ServerAccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException { ServerAccessToken at = doCreateAccessToken(reg); saveAccessToken(at); if (isRefreshTokenSupported(reg.getApprovedScope())) { createNewRefreshToken(at); } return at; }
protected AccessTokenRegistration createTokenRegistration(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject) { AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(super.getSupportedGrantType()); reg.setResponseType(state.getResponseType()); reg.setSubject(userSubject); reg.setRequestedScope(requestedScope); reg.setApprovedScope(getApprovedScope(requestedScope, approvedScope)); reg.setAudiences(Collections.singletonList(state.getAudience())); reg.setNonce(state.getNonce()); reg.getExtraProperties().putAll(state.getExtraProperties()); return reg; } protected void finalizeResponse(StringBuilder sb, OAuthRedirectionState state) {
@POST @Consumes("application/x-www-form-urlencoded") @Produces("text/html") public Response authorize(MultivaluedMap<String, String> params) { SecurityContext sc = getAndValidateSecurityContext(params); Client client = getClient(params); // Create a UserSubject representing the end user UserSubject userSubject = createUserSubject(sc, params); AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(OAuthConstants.DIRECT_TOKEN_GRANT); reg.setSubject(userSubject); String providedScope = params.getFirst(OAuthConstants.SCOPE); List<String> requestedScope = OAuthUtils.getRequestedScopes(client, providedScope, useAllClientScopes, partialMatchScopeValidation); reg.setRequestedScope(requestedScope); reg.setApprovedScope(requestedScope); ServerAccessToken token = getDataProvider().createAccessToken(reg); ClientAccessToken clientToken = OAuthUtils.toClientAccessToken(token, isWriteOptionalParameters()); return Response.ok(clientToken).build(); }
AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setGrantCode(grant.getCode()); reg.setClient(client); reg.setGrantType(requestedGrant); reg.setSubject(grant.getSubject()); reg.setRequestedScope(grant.getRequestedScopes()); reg.setNonce(grant.getNonce()); if (grant.getApprovedScopes() != null) { reg.setApprovedScope(grant.getApprovedScopes()); } else { reg.setApprovedScope(Collections.emptyList()); reg.setAudiences(audiences); reg.setResponseType(grant.getResponseType()); reg.setClientCodeVerifier(codeVerifier); reg.getExtraProperties().putAll(grant.getExtraProperties()); return getDataProvider().createAccessToken(reg);
@POST @Consumes("application/x-www-form-urlencoded") @Produces("text/html") public Response authorize(MultivaluedMap<String, String> params) { SecurityContext sc = getAndValidateSecurityContext(params); Client client = getClient(params); // Create a UserSubject representing the end user UserSubject userSubject = createUserSubject(sc, params); AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setClient(client); reg.setGrantType(OAuthConstants.DIRECT_TOKEN_GRANT); reg.setSubject(userSubject); String providedScope = params.getFirst(OAuthConstants.SCOPE); List<String> requestedScope = OAuthUtils.getRequestedScopes(client, providedScope, useAllClientScopes, partialMatchScopeValidation); reg.setRequestedScope(requestedScope); reg.setApprovedScope(requestedScope); ServerAccessToken token = getDataProvider().createAccessToken(reg); ClientAccessToken clientToken = OAuthUtils.toClientAccessToken(token, isWriteOptionalParameters()); return Response.ok(clientToken).build(); }
AccessTokenRegistration reg = new AccessTokenRegistration(); reg.setGrantCode(grant.getCode()); reg.setClient(client); reg.setGrantType(requestedGrant); reg.setSubject(grant.getSubject()); reg.setRequestedScope(grant.getRequestedScopes()); reg.setNonce(grant.getNonce()); if (grant.getApprovedScopes() != null) { reg.setApprovedScope(grant.getApprovedScopes()); } else { reg.setApprovedScope(Collections.emptyList()); reg.setAudiences(audiences); reg.setResponseType(grant.getResponseType()); reg.setClientCodeVerifier(codeVerifier); reg.getExtraProperties().putAll(grant.getExtraProperties()); return getDataProvider().createAccessToken(reg);