Code Monkey home page Code Monkey logo

mipsdk-file-java-basic's Introduction

page_type languages products name description urlFragment
sample
java
m365
office-365
MIP File SDK Java Sample
This sample application demonstrates using the Microsoft Information Protection SDK Java wrapper to label and read a label from a file.
MipSDK-File-Java-Basic

MIP SDK Java Wrapper Sample

This sample application demonstrates a very basic MIP SDK Java wrapper sample. It'll demonstrate how to create the project, add dependencies, and get to a place where the app can run on both Windows and Ubuntu.

Features

This project framework provides the following features:

  • User authentication
  • List Labels
  • Apply Label
  • Read Label
  • Read Protection Information

Getting Started

Prerequisites

Installation

  • Windows

    • Install your JDK of choice.
    • Install Maven
  • Ubuntu

    • Install JDK: sudo apt-get install default-jdk
    • Install Maven: sudo apt-get install maven
    • Install MIP SDK Dependencies: sudo apt-get install scons libgsf-1-dev libssl-dev libsecret-1-dev freeglut3-dev libcpprest-dev libcurl3-dev uuid-dev libboost-all-dev

Quickstart

  1. git clone https://github.com/Azure-Samples/mipsdk-filesdk-java-sample.git
  2. cd mipsdk-filesdk-java-sample
  3. Install the MIP SDK JAR. This JAR file is located inside the MIP SDK Java Wrapper, available at https://aka.ms/mipsdkbins. Download and extract the JAR locally.
  • Windows: <PATH TO MAVEN>\mvn.cmd org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=<PATH TO MIP SDK>\java-sdk-wrapper.jar
  • Ubuntu: mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=java-sdk-wrapper.jar

Note: Not using a fully qualified path for the -Dfile parameter may cause an exception. Use a full path.

  1. The Java wrapper download contains two folders: file_sdk and java_wrapper.

    • Copy all DLLs or SOs from the bins\debug folder in file_sdk for the appropriate architecture into your project folder root (the cloned project root).
    • Copy mip_java.dll or mip_java.so from the java_wrapper folder into the project folder root (the cloned project root).

    This requirement of copying to the project root is a bug and will be fixed in a future version.

  2. Update the ApplicationId on line 22 in App.java to match your application registration in Azure AD.

  3. Open the project folder in VS Code and load the project when prompted.

  4. Update the following block in App.java to include your clientId.

  appInfo.setApplicationId("YOUR CLIENT ID");
  appInfo.setApplicationName("MIP SDK Java Sample");
  appInfo.setApplicationVersion("1.14");

At this point, you should be able to build the project. If your app states that dependencies are missing:

  1. Press CTRL-SHIFT-P and finding Maven: Add a dependency...
  2. Search for msal4j and install.
  3. Press CTRL-SHIFT-P and finding Maven: Add a dependency...
  4. Search for slf4j-simple and install.

Resources

mipsdk-file-java-basic's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar simofiuz avatar tommoser avatar zhang-yangchen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mipsdk-file-java-basic's Issues

Plan to support MIP SDK for JAVA on RHEL

Hi,

We need to use MIP classification technology in our server grade product which is written in JAVA.
As I need to support Windows and RHEL servers for my product I am looking for MIP SDK which I can use from JAVA code and which works on Windows and RHEL platform. As per https://learn.microsoft.com/en-us/information-protection/develop/setup-configure-mip at present I can see only support for Windows and Ubuntu but not for RHEL.
So can you please let me know if there is any plan to support this for RHEL as well, also can I use Ubuntu version with RHEL ?

Thanks,
Bishnu

Default configuration doesn't work

Hello!

I have compiled java sample and created Application Registration in Azure AD with corresponding premissions, according to instructions. I have amended code

    appInfo.setApplicationId("xxxxx-xxxx-xxxx-xxxx-xxxxxxxx");
    appInfo.setApplicationName("MIP SDK Java Sample");
    appInfo.setApplicationVersion("1.10"); 

but it give error about token. Firewall is disabled. Any idea?

PS C:> java -jar mipsdksample.jar
Enter a username: [email protected]
Error reading data from file: null
java.lang.RuntimeException: java.lang.NullPointerException
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:63)
at com.microsoft.mipsdksample.TokenCacheAspect.(TokenCacheAspect.java:41)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireTokenInteractive(AuthDelegateImpl.java:80)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireToken(AuthDelegateImpl.java:67)
at com.microsoft.informationprotection.internal.NativeAuthDelegate.AcquireOAuth2Token(NativeAuthDelegate.java:21)
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_AuthDelegate_AcquireOAuth2Token__SWIG_0(SdkWrapperJNI.java:1958)
Caused by: java.lang.NullPointerException
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:60)
... 5 more
Error reading data from file: null
java.lang.RuntimeException: java.lang.NullPointerException
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:63)
at com.microsoft.mipsdksample.TokenCacheAspect.(TokenCacheAspect.java:41)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireTokenInteractive(AuthDelegateImpl.java:80)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireToken(AuthDelegateImpl.java:67)
at com.microsoft.informationprotection.internal.NativeAuthDelegate.AcquireOAuth2Token(NativeAuthDelegate.java:21)
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_AuthDelegate_AcquireOAuth2Token__SWIG_0(SdkWrapperJNI.java:1958)
Caused by: java.lang.NullPointerException
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:60)
... 5 more
Exception in thread "main" java.util.concurrent.ExecutionException: com.microsoft.informationprotection.internal.gen.Error: NoAuthTokenError: Client application failed to provide authentication token for HTTP request.
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
at java.util.concurrent.CompletableFuture.get(Unknown Source)
at com.microsoft.mipsdksample.Action.CreateFileEngine(Action.java:105)
at com.microsoft.mipsdksample.Action.(Action.java:78)
at com.microsoft.mipsdksample.App.main(App.java:54)
Caused by: com.microsoft.informationprotection.internal.gen.Error: NoAuthTokenError: Client application failed to provide authentication token for HTTP request.
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_FileProfile_Observer_OnAddEngineFailure(SdkWrapperJNI.java:2315)

SDK fails "silently" on Ubuntu 20.04

We're trying to get this SDK to work both on Windows 10 and Ubuntu 20.04.

The SDK seems to work OK on Windows, even though manually copying DLLs here and there is not ideal for anything other than a POC, but at least we can get it to label documents correctly.

After getting it to work on Windows we tried to get the exact same code (but with the mip_sdk_java_wrapper_ubuntu2004_1.11.72_preview.tar.gz files of course) to run on Linux. It compiles and runs but the Java app crashes when trying to execute mipContext = MIP.createMipContext(mipConfiguration);
No exception is thrown. When I decompile the java wrapper JAR file I can see that it's probably because it calls into the compiled C++ .so libs and presumably something goes wrong there. I am pasting below the logs from mip_sdk.miplog (logging at Trace level).

Info	2022-05-12 10:37:08.746	default_logger_delegate.cpp:162	java (128896)	"Logger initialized with format:%level	%datetime{%Y-%M-%d %H:%m:%s.%g}	%fbase:%line	%process	""%msg""	%func	%thread"	void mipns::DefaultLoggerDelegate::InitHelper(const string&)	139762585151232
Info	2022-05-12 10:37:08.800	default_logger_delegate.cpp:163	java (128896)	"Log file:mip_data/mip/logs/mip_sdk.miplog"	void mipns::DefaultLoggerDelegate::InitHelper(const string&)	139762585151232
Info	2022-05-12 10:37:08.800	default_logger_delegate.cpp:164	java (128896)	"Machine name: [unknown-host], User name: [ubuntu]"	void mipns::DefaultLoggerDelegate::InitHelper(const string&)	139762585151232
Trace	2022-05-12 10:37:08.800	diagnostic_factory.cpp:363	java (128896)	"Initializing OneDS"	std::shared_ptr<mipns::OneDSAriaHelper> mipns::CreateOneDSAriaHelper(const string&, const mipns::DiagnosticConfiguration&)	139762585151232
Trace	2022-05-12 10:37:08.801	oneds_helper.cpp:198	java (128896)	"Initializing OneDS LogManager, fastShutdownEnabled: false"	evt_handle_t mipns::OneDSHelper::InitLogManager(const string&, const mipns::DiagnosticConfiguration&, const string&)	139762585151232
Info	2022-05-12 10:37:08.801	oneds_helper.cpp:254	java (128896)	"OneDS configuration: {""name"":""mip-sdk-for-cpp"",""maxTeardownUploadTimeInSec"":1,""stats"":{""interval"":0},""enableNetworkDetector"":true,""cacheFilePath"":""mip_data/mip/mip/telemetry"",""enableTrace"":false,""traceLevelMask"":4294967295,""minimumTraceLevel"":0}"	evt_handle_t mipns::OneDSHelper::InitLogManager(const string&, const mipns::DiagnosticConfiguration&, const string&)	139762585151232

ANy ideas? Is Ubuntu 20.04 supported or not?

Lots of mistakes in TokenCacheAspect

Error reading data from file: Cannot invoke "java.net.URL.toURI()" because "path" is null
java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "java.net.URL.toURI()" because "path" is null
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:63)
at com.microsoft.mipsdksample.TokenCacheAspect.(TokenCacheAspect.java:41)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireTokenInteractive(AuthDelegateImpl.java:80)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireToken(AuthDelegateImpl.java:67)
at com.microsoft.informationprotection.internal.NativeAuthDelegate.AcquireOAuth2Token(NativeAuthDelegate.java:21)
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_AuthDelegate_AcquireOAuth2Token__SWIG_0(SdkWrapperJNI.java:2022)
Caused by: java.lang.NullPointerException: Cannot invoke "java.net.URL.toURI()" because "path" is null
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:60)
... 5 more
Error reading data from file: Cannot invoke "java.net.URL.toURI()" because "path" is null
java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "java.net.URL.toURI()" because "path" is null
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:63)
at com.microsoft.mipsdksample.TokenCacheAspect.(TokenCacheAspect.java:41)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireTokenInteractive(AuthDelegateImpl.java:80)
at com.microsoft.mipsdksample.AuthDelegateImpl.acquireToken(AuthDelegateImpl.java:67)
at com.microsoft.informationprotection.internal.NativeAuthDelegate.AcquireOAuth2Token(NativeAuthDelegate.java:21)
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_AuthDelegate_AcquireOAuth2Token__SWIG_0(SdkWrapperJNI.java:2022)
Caused by: java.lang.NullPointerException: Cannot invoke "java.net.URL.toURI()" because "path" is null
at com.microsoft.mipsdksample.TokenCacheAspect.readDataFromFile(TokenCacheAspect.java:60)
... 5 more
Exception in thread "main" java.util.concurrent.ExecutionException: com.microsoft.informationprotection.internal.gen.Error: NoAuthTokenError: Client application failed to provide authentication token for HTTP request., CorrelationId=xxx, CorrelationId.Description=PolicyProfile
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
at com.microsoft.mipsdksample.Action.CreateFileEngine(Action.java:110)
at com.microsoft.mipsdksample.Action.(Action.java:79)
at com.microsoft.mipsdksample.App.main(App.java:54)
Caused by: com.microsoft.informationprotection.internal.gen.Error: NoAuthTokenError: Client application failed to provide authentication token for HTTP request., CorrelationId=xxx, CorrelationId.Description=PolicyProfile
at com.microsoft.informationprotection.internal.gen.SdkWrapperJNI.SwigDirector_FileProfile_Observer_OnAddEngineFailure(SdkWrapperJNI.java:2397)

Process finished with exit code 1

Please rewrite code and do not provide low quality products in the future.
Thank you for your cooperation.

Error message [ Exception in thread "Thread-12985214" java.lang.NullPointerException: null upcall object in mipns::Stream::Read ]

When we stress testing the MIP SDK instance (MIP SDK File Sample Source) created as a singleton in the Java Spring environment, the error occurs.

We used MIP SDK is "mip_sdk_java_ubuntu1804_1.12.61_preview.tar.gz", and when an error occurs during the stress testing, the STDOUT contents are as follows. ( https://www.microsoft.com/en-us/download/details.aspx?id=104267 )

Exception in thread "Thread-9336141" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12966921" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12970196" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12971973" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12975081" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12985049" java.lang.NullPointerException: null upcall object in mipns::FileHandler::Observer::OnCommitSuccess
Exception in thread "Thread-12985207" java.lang.NullPointerException: null upcall object in mipns::Stream::Seek
Exception in thread "Thread-12985214" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
Exception in thread "Thread-12985218" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
Exception in thread "Thread-12985220" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
Exception in thread "Thread-12985221" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
Exception in thread "Thread-12985222" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
Exception in thread "Thread-12985224" java.lang.NullPointerException: null upcall object in mipns::Stream::Read
...
( Infinite loop output )
...
Exception in thread "Thread-12999999" java.lang.NullPointerException: null upcall object in mipns::Stream::Read

Doing a "MIP File::Delete Label" stress test with that MIP SDK for about 5 minutes may copy the error.

This error slows down the process and eventually crashes the process due to stack overflow.

We have already registered with Microsoft Case ( Case No: 32221263 ) and hope that the issue will be resolved as soon as possible.

Thanks!

ACTION REQUIRED: Microsoft needs this private repository to complete compliance info

There are open compliance tasks that need to be reviewed for your mipsdk-fileapi-java-sample repo.

Action required: 4 compliance tasks

To bring this repository to the standard required for 2021, we require administrators of this and all Microsoft GitHub repositories to complete a small set of tasks within the next 60 days. This is critical work to ensure the compliance and security of your Azure-Samples GitHub organization.

Please take a few minutes to complete the tasks at: https://repos.opensource.microsoft.com/orgs/Azure-Samples/repos/mipsdk-fileapi-java-sample/compliance

  • The GitHub AE (GitHub inside Microsoft) migration survey has not been completed for this private repository
  • No Service Tree mapping has been set for this repo. If this team does not use Service Tree, they can also opt-out of providing Service Tree data in the Compliance tab.
  • No repository maintainers are set. The Open Source Maintainers are the decision-makers and actionable owners of the repository, irrespective of administrator permission grants on GitHub.
  • Classification of the repository as production/non-production is missing in the Compliance tab.

You can close this work item once you have completed the compliance tasks, or it will automatically close within a day of taking action.

If you no longer need this repository, it might be quickest to delete the repo, too.

GitHub inside Microsoft program information

More information about GitHub inside Microsoft and the new GitHub AE product can be found at https://aka.ms/gim.

FYI: current admins at Microsoft include @RafaelDominguez, @tommoser, @k-bren, @kkanakas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.