org.apache.oltu.oauth2.common.message.types.ResponseType Java Examples

The following examples show how to use org.apache.oltu.oauth2.common.message.types.ResponseType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractResponseTypeHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validateAccessDelegation(OAuthAuthzReqMessageContext oauthAuthzMsgCtx)
        throws IdentityOAuth2Exception {

    OAuth2AuthorizeReqDTO authzReqDTO = oauthAuthzMsgCtx.getAuthorizationReqDTO();
    String responseType = authzReqDTO.getResponseType();

    OAuthAppDO oAuthAppDO = (OAuthAppDO)oauthAuthzMsgCtx.getProperty("OAuthAppDO");
    // If the application has defined a limited set of grant types, then check the grant
    if (oAuthAppDO.getGrantTypes() != null) {
        if (ResponseType.CODE.toString().equals(responseType)) {
            //Do not change this log format as these logs use by external applications
            if (!oAuthAppDO.getGrantTypes().contains("authorization_code")) {
                log.debug("Unsupported Response Type : " + responseType +
                        " for client id : " + authzReqDTO.getConsumerKey());
                handleErrorRequest(oauthAuthzMsgCtx, OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE,
                        "Unsupported Response Type!");
                return false;
            }
        } else if (StringUtils.contains(responseType, ResponseType.TOKEN.toString()) &&
                !oAuthAppDO.getGrantTypes().contains(IMPLICIT)) {
            //Do not change this log format as these logs use by external applications
            log.debug("Unsupported Response Type : " + responseType + " for client id : " + authzReqDTO
                    .getConsumerKey());
            handleErrorRequest(oauthAuthzMsgCtx, OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE,
                    "Unsupported Response Type!");
            return false;
        }
    }

    OAuth2AuthorizeReqDTO authorizationReqDTO = oauthAuthzMsgCtx.getAuthorizationReqDTO();
    OAuthCallback authzCallback = new OAuthCallback(authorizationReqDTO.getUser(),
            authorizationReqDTO.getConsumerKey(), OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_AUTHZ);
    authzCallback.setRequestedScope(authorizationReqDTO.getScopes());
    authzCallback.setResponseType(authorizationReqDTO.getResponseType());
    callbackManager.handleCallback(authzCallback);

    oauthAuthzMsgCtx.setValidityPeriod(authzCallback.getValidityPeriod());
    return authzCallback.isAuthorized();
}
 
Example #2
Source File: OAuthServiceImpl.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public String generateForwardUrl(String registrationEndpoint, String authorizeUrl, String returnUrl) throws ServerException, UserException {
	try (DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY)) {
		OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_RegistrationEndpoint(), registrationEndpoint);
		if (oAuthServer == null) {
			throw new UserException("Application not registered");
		}
		OAuthClientRequest request2 = OAuthClientRequest.authorizationLocation(authorizeUrl).setParameter("auth_type", "service").setClientId(oAuthServer.getClientId()).setRedirectURI(returnUrl).setResponseType(ResponseType.CODE.toString()).setState("state").buildQueryMessage();
		return request2.getLocationUri();
	} catch (Exception e) {
		return handleException(e);
	}
}