Police in Tokyo have monitored the activities of Muslims in Japan, based on their religion alone, since at least 2008. A court case challenging the constitutionality of this surveillance program was recently denied.
On May 31, 2016, Japan's Supreme Court dismissed the case questioning the legality of conducting surveillance on and profiling Muslims in Japan, even though surveillance based on religion or ethnicity is generally illegal under Japan's constitution, which enshrines  the right to privacy, equal protection under the law, and freedom of religion. This marked the culmination of several years of lawsuits by the same group of plaintiffs in different courts, resulting in a variety of judgements.
The fact that Tokyo police were conducting surveillance of Muslims first became public in 2010, when over 100 internal Metropolitan Police Department documents were leaked online. The documents included the names, addresses and other personal information of Muslims residing in Japan. The surveillance dated back several years prior to 2010, and was apparently motivated by security arrangements for the 2008 G-8 summit held in Japan.
According to English-language newspaper Japan Times: 
The leak revealed that the police had compiled detailed profiles on 72,000 Muslims, including personal information such as bank account statements, passport details and records of their movements. The leak also showed that police had at times planted cameras inside mosques and used undercover agents to infiltrate Islamic nonprofit organizations and halal grocers and restaurants.
Following the leak, 17 of the Muslims named in the documents sued the government and police in order to have the spying declared illegal. In 2014, Tokyo District Court agreed that the leak had violated the plaintiffs’ right to privacy and awarded them ¥90 million (about US $900,000) in compensation . However, the court also ruled that the intelligence-gathering was “necessary and inevitable”  in order to protect Japan against the threat of international terrorism, despite constitutional protections for freedom of religion and equal protection under the law.
In the 2014 court case related to the leak, the plaintiffs alleged :
The Metropolitan Police Department and the National Police Agency had, as of 31 May, 2008, assessed and digitalized the personal information of ‘roughly 12,677 individuals’ equaling ‘roughly 89 percent of the 14,254 foreign nationals from Muslim countries registered in Tokyo,’ and later, by the time the Hokkaido Toya Lake summit convened in July of that year, had ‘profiled roughly 72,000 individuals from OIC (Organisation of the Islamic Conference) countries (assessment rate of 98 percent).’
Earlier in 2016 the group asked the Supreme Court of Japan to rule on the legality of the surveillance. On May 31, the Supreme Court dismissed the case, while upholding the decision to award compensation to Muslims affected by the leak.
On the Center for Constitutional Rights blog , Igeta Daisuke, one of the plaintiff attorneys involved in the case, described the extent of the surveillance program in more detail:
Police agents were stationed undercover in mosques all over the country, and the surveillance program extended to almost every other center of Muslim life, from halal shops to what the police bizarrely deemed “Islam-related” organizations that included Doctors Without Borders, UNESCO, and other prominent NGOs.
Further documentation of the surveillance program indicates that police regularly approached Muslim residents of Japan, asking them to provide information about and effectively spy on other members of their community. This reportedly affected their relationships with their friends, neighbors and family, leaving psychological wounds .
With no census data available , it's estimated that there are about 100,000 people who identify as Muslim residing in Japan. Some of these people are Japanese citizens, while others are non-Japanese students and permanent residents with deep ties to the country.
去る7月9日、マスジド大塚はNPOてのはしさんの池袋東公園炊き出し運動に参加、約150名のホームレスの方々に320食分のカレーを配りました。今回は順天堂大学の学生さんたちの参加もありました。ご協力頂いた皆様方ありがとうございました！ pic.twitter.com/8iJhC5aCkY 
— Otsuka Masjid/大塚マスジド (@otsukamasjid) July 26, 2016 
On July 9, the Otsuka Mosque (Majid) joined a volunteer event in a park in Ikebukuro (in Tokyo). We helped provide 320 servings of curry to about 150 homeless people. A number of university students joined us to help out as well. Thanks to everyone who played a part today!
Thanks to the Silk Road  trading route, Japan been connected with predominantly Muslim regions of the world for more than a thousand years. However, it was not until the end of Japan's long period of isolation in the 19th century and the opening of the country when a larger local Muslim community started to develop.
Ertugrul was first Islamic ship carrying Muslims to Japan in 1890, and the first known official contact between… https://t.co/omQLbmHPWV 
— Islam In Japan Media (@IslamJapanMedia) August 3, 2016 
By 1935  a mosque had been established in the major western trading port of Kobe. The Tokyo Camii  mosque was established in 1938. The postwar years have seen migrants arriving from Bangladesh, Iran, Indonesia  and other Muslim countries. Some come to study in Japanese schools, while others arrive as temporary workers. Today there are mosques in every region of the country .
It's hard to say whether or not the actions of the Metropolitan Police and the National Police Association are indicative of Japan's attitudes towards Muslims. For example, the Tokyo Metropolitan Government recently launched this guide book aimed at Muslim travelers:
— Tokyo Gov (@Tokyo_gov) July 31, 2016 
In November 2015, following the Paris attacks , a meme circulated on the English-language Internet about a list of supposed restrictions  by Japan that effectively bans Muslim immigration. The meme was later debunked . Muslims are allowed to visit, reside in and even become citizens in Japan. Leading politicians including Prime Minister Abe Shinzo  have also stressed the importance of tolerance. Nevertheless, the police monitoring program continues.
For now Japan's tolerant attitude towards Islam may have more to do with the fact that there are relatively few Muslims living in Japan. It's difficult to say if the attitudes held by police towards Muslims are an exception to Japanese public opinion, or a symptom of a deeper social stigma.