Provide a way to determine if the connection is anonymous

This commit is contained in:
Stephen Connolly
2013-08-29 14:33:04 +01:00
parent c96e6c7c92
commit fb078de627

View File

@@ -192,8 +192,16 @@ public class GitHub {
return new GitHub(null,null,null);
}
/**
* Is this an anonymous connection
* @return {@code true} if operations that require authentication will fail.
*/
public boolean isAnonymous() {
return login==null && encodedAuthorization==null;
}
/*package*/ void requireCredential() {
if (login==null && encodedAuthorization==null)
if (isAnonymous())
throw new IllegalStateException("This operation requires a credential but none is given to the GitHub constructor");
}