public String registerScope ( FullHttpRequest req ) throws OAuthException { String contentType = ( req . headers ( ) != null ) ? req . headers ( ) . get ( HttpHeaderNames . CONTENT_TYPE ) : null ; // check Content-Type if ( contentType != null && contentType . contains ( ResponseBuilder . APPLICATION_JSON ) ) { try { Scope scope = InputValidator . validate ( req . content ( ) . toString ( CharsetUtil . UTF_8 ) , Scope . class ) ; if ( scope . valid ( ) ) { if ( ! Scope . validScopeName ( scope . getScope ( ) ) ) { LOG . error ( "scope name is not valid" ) ; throw new OAuthException ( SCOPE_NAME_INVALID_ERROR , HttpResponseStatus . BAD_REQUEST ) ; } LOG . info ( ">>>>>>>>>>>>>>> scope = " + scope ) ; Scope foundScope = DBManagerFactory . getInstance ( ) . findScope ( scope . getScope ( ) ) . blockingGet ( ) ; if ( foundScope != null ) { LOG . error ( "scope already exists" ) ; throw new OAuthException ( SCOPE_ALREADY_EXISTS , HttpResponseStatus . BAD_REQUEST ) ; } else { // store in the DB, if already exists such a scope, overwrites it DBManagerFactory . getInstance ( ) . storeScope ( scope ) . blockingGet ( ) ; } } else { LOG . error ( "scope is not valid" ) ; throw new OAuthException ( MANDATORY_FIELDS_ERROR , HttpResponseStatus . BAD_REQUEST ) ; } } catch ( Throwable e ) { LOG . error ( "cannot handle scope request" , e ) ; throw new OAuthException ( e , null , HttpResponseStatus . BAD_REQUEST ) ; } } else { throw new OAuthException ( ResponseBuilder . UNSUPPORTED_MEDIA_TYPE , HttpResponseStatus . BAD_REQUEST ) ; } return SCOPE_STORED_OK_MESSAGE ; }
Register an oauth scope . If the scope already exists returns an error .