@@ -98,8 +98,9 @@ public class Contentstack {
9898 * @since 2022-05-19
9999 */
100100 public User user () {
101- if (this .authtoken == null )
102- throw new NullPointerException (Util .LOGIN_FLAG );
101+ if (!isOAuthConfigured () && this .authtoken == null ) {
102+ throw new IllegalStateException ("Please login or configure OAuth to access user" );
103+ }
103104 user = new User (this .instance );
104105 return user ;
105106 }
@@ -291,7 +292,9 @@ Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException
291292 * @return the organization
292293 */
293294 public Organization organization () {
294- Objects .requireNonNull (this .authtoken , "Please Login to access user instance" );
295+ if (!isOAuthConfigured () && this .authtoken == null ) {
296+ throw new IllegalStateException ("Please login or configure OAuth to access organization" );
297+ }
295298 return new Organization (this .instance );
296299 }
297300
@@ -315,9 +318,12 @@ public Organization organization() {
315318 * </pre>
316319 */
317320 public Organization organization (@ NotNull String organizationUid ) {
318- Objects .requireNonNull (this .authtoken , "Please Login to access user instance" );
319- if (organizationUid .isEmpty ())
321+ if (!isOAuthConfigured () && this .authtoken == null ) {
322+ throw new IllegalStateException ("Please login or configure OAuth to access organization" );
323+ }
324+ if (organizationUid .isEmpty ()) {
320325 throw new IllegalStateException ("organizationUid can not be empty" );
326+ }
321327 return new Organization (this .instance , organizationUid );
322328 }
323329
@@ -339,7 +345,9 @@ public Organization organization(@NotNull String organizationUid) {
339345 * @return the stack instance
340346 */
341347 public Stack stack () {
342- Objects .requireNonNull (this .authtoken , ILLEGAL_USER );
348+ if (!isOAuthConfigured () && this .authtoken == null ) {
349+ throw new IllegalStateException ("Please login or configure OAuth to access stack" );
350+ }
343351 return new Stack (this .instance );
344352 }
345353
@@ -362,8 +370,9 @@ public Stack stack() {
362370 * @return the stack instance
363371 */
364372 public Stack stack (@ NotNull Map <String , Object > header ) {
365- if (this .authtoken == null && !header .containsKey (AUTHORIZATION ) && header .get (AUTHORIZATION ) == null )
366- throw new IllegalStateException (PLEASE_LOGIN );
373+ if (!isOAuthConfigured () && this .authtoken == null && !header .containsKey (AUTHORIZATION )) {
374+ throw new IllegalStateException ("Please login or configure OAuth to access stack" );
375+ }
367376 return new Stack (this .instance , header );
368377 }
369378
0 commit comments