Search in sources :

Example 1 with AdAuthManager

use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.

the class SignOutCommandHandler method doSignOut.

public static void doSignOut(Shell shell) {
    try {
        AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
        String artifact = (authMethodManager.getAuthMethod() == AuthMethod.AD) ? "Signed in as " + authMethodManager.getAuthMethodDetails().getAccountEmail() : "Signed in using file \"" + authMethodManager.getAuthMethodDetails().getCredFilePath() + "\"";
        MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        messageBox.setMessage(artifact + "\n" + "Do you really want to sign out?");
        messageBox.setText("Azure Sign Out");
        int response = messageBox.open();
        if (response == SWT.YES) {
            AdAuthManager adAuthManager = AdAuthManager.getInstance();
            if (adAuthManager.isSignedIn()) {
                adAuthManager.signOut();
            }
            authMethodManager.signOut();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) ExecutionException(org.eclipse.core.commands.ExecutionException) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with AdAuthManager

use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.

the class SignInWindow method doSignIn.

private void doSignIn() {
    try {
        AdAuthManager adAuthManager = AdAuthManager.getInstance();
        if (adAuthManager.isSignedIn()) {
            doSingOut();
        }
        signInAsync();
        accountEmail = adAuthManager.getAccountEmail();
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("doSignIn", ex);
        ErrorWindow.show(project, ex.getMessage(), "Sign In Error");
    }
}
Also used : AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) IOException(java.io.IOException) AuthCanceledException(com.microsoft.azuretools.adauth.AuthCanceledException)

Example 3 with AdAuthManager

use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.

the class AzureSignInAction method onAzureSignIn.

public static void onAzureSignIn(Project project) {
    JFrame frame = WindowManager.getInstance().getFrame(project);
    try {
        AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
        boolean isSignIn = authMethodManager.isSignedIn();
        if (isSignIn) {
            String artifact = (authMethodManager.getAuthMethod() == AuthMethod.AD) ? "Signed in as " + authMethodManager.getAuthMethodDetails().getAccountEmail() : "Signed in using file \"" + authMethodManager.getAuthMethodDetails().getCredFilePath() + "\"";
            int res = JOptionPane.showConfirmDialog(frame, artifact + "\n" + "Do you really want to sign out?", "Azure Sign Out", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon("icons/azure.png"));
            if (res == JOptionPane.OK_OPTION) {
                AdAuthManager adAuthManager = AdAuthManager.getInstance();
                if (adAuthManager.isSignedIn())
                    adAuthManager.signOut();
                authMethodManager.signOut();
            }
        } else {
            //                SignInWindow w = SignInWindow.go(authMethodManager.getAuthMethodDetails(), project);
            //                if (w != null) {
            //                    AuthMethodDetails authMethodDetailsUpdated = w.getAuthMethodDetails();
            //                    authMethodManager.setAuthMethodDetails(authMethodDetailsUpdated);
            //                    SelectSubscriptionsAction.onShowSubscriptions(project);
            //                }
            doSignIn(authMethodManager, project);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("onAzureSignIn", ex);
        ErrorWindow.show(project, ex.getMessage(), "AzureSignIn Action Error");
    }
}
Also used : AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Example 4 with AdAuthManager

use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.

the class Program method graphApiAction.

@SuppressWarnings("unused")
private static void graphApiAction() throws Exception {
    AdAuthManager adAuthManager = AdAuthManager.getInstance();
    if (!adAuthManager.isSignedIn()) {
        adAuthManager.signIn();
    }
    String request = "tenantDetails";
    List<com.microsoft.azure.management.resources.Tenant> tl = AccessTokenAzureManager.getTenants("common");
    for (com.microsoft.azure.management.resources.Tenant t : tl) {
        String tid = t.tenantId();
        System.out.println("==> tenant ID: " + tid);
        String tenantId = tid;
        try {
            GraphRestHelper grh = new GraphRestHelper(tenantId);
            String resp = grh.doGet(request, null);
            System.out.println("Graph response:" + resp);
        } catch (Exception ex) {
            System.out.println("GraphApiAction ex: " + ex.getMessage());
        }
    }
}
Also used : GraphRestHelper(com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) IOException(java.io.IOException)

Example 5 with AdAuthManager

use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.

the class Program method createSp.

@SuppressWarnings("unused")
private static void createSp() {
    try {
        LogManager.getLogManager().reset();
        boolean doFirst = false;
        AdAuthManager adAuthManager = AdAuthManager.getInstance();
        if (doFirst) {
            if (adAuthManager.isSignedIn()) {
                adAuthManager.signOut();
            //AuthMethodManager.getInstance().clean(AuthMethod.AD);
            }
            adAuthManager.signIn();
        } else {
            if (!adAuthManager.isSignedIn())
                adAuthManager.signIn();
        }
        Map<String, List<String>> tsm = adAuthManager.getAccountTenantsAndSubscriptions();
        for (String tid : tsm.keySet()) {
            List<String> sids = tsm.get(tid);
            if (!sids.isEmpty()) {
                try {
                    SrvPriManager.createSp(tid, sids, "808", new IListener<Status>() {

                        @Override
                        public void listen(Status message) {
                            System.out.format(">> Status report: %s\t:\t%s\t:\t%s\n", message.getAction(), message.getResult(), message.getDetails());
                        }
                    }, null);
                } catch (Exception t1) {
                    System.out.println("CreateServicePrincipalsAction ex: " + t1.getMessage());
                    t1.printStackTrace();
                }
            }
        }
    } catch (Exception t) {
        t.printStackTrace();
    }
}
Also used : Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) List(java.util.List) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) IOException(java.io.IOException)

Aggregations

AdAuthManager (com.microsoft.azuretools.authmanage.AdAuthManager)8 IOException (java.io.IOException)6 AuthCanceledException (com.microsoft.azuretools.adauth.AuthCanceledException)3 List (java.util.List)3 AuthMethodManager (com.microsoft.azuretools.authmanage.AuthMethodManager)2 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)2 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)2 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 GraphRestHelper (com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper)1 Status (com.microsoft.azuretools.authmanage.srvpri.step.Status)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1