Transcript
Hi everyone, today I would like to talk to you about how we can leverage the flexibility and sort of the popularity of the Angular framework to make it easier to get into using Identity, IQ plugins. I've got to give kudos to Mike who we just saw because he gave me the idea from his presentation last year where he demonstrated a very nice plugin that allows you to show the organizational structure of a population in Identity, IQ which was basically an Angular app. I thought that was a very powerful idea and I thought it would be maybe interesting to dive a little bit more into that and so I will try to show you how to build a plugin from scratch. So we will be doing a live coding and set up an Angular application and then turn that into a plugin. I have some slides but I'm going to go over them really quickly because there's really a lot to show. So I'm just going to quickly go through these. So the idea is to create a little app, we'll turn that into a plugin and that will be our profit. So the cool thing about this is that Angular is very popular, a lot of people are familiar with that. So you can leverage that knowledge in your organization. I'm going to just go through these things. So the big idea here, the magic trick is that Angular is a single page application that you compile into a bunch of JavaScript and then that single page application just runs all the code from that JavaScript and so does a plugin. So if you combine those two, that means that you could leverage one and use that into the other. So let's just jump to our development setup and start coding. All right. So I did see some comments in the chat about font size so I just want to make sure that let's see, I'm going to make this like this and if we look at that, how does that look size-wise? All right, thank you. So to set the stage, so we're going to make a little plugin. The functionality is not going to be really groundbreaking. The idea is just to show you that we can create an application and turn that into a plugin. So let's quickly look at our identity IQ and what I would like to do as just the example is extend our preferences screen configuration here. So wouldn't it be nice that if Jerry went away on leave and he can send his notifications to Amanda and we already do that, obviously, but wouldn't it be nice that we could say Amanda only needs to do certifications because for every work item that will get created, Amanda will get that notification but maybe she's not interested in approvals or work items but we want to make sure that she gets the certification notifications. So currently in the UI, that is not possible. Luckily, we do provide a way to intervene there. So there is a global work item forwarding rule that we can invoke that would be checked for every work item that gets created. So here we could check for each type of work item, for example, an approval or certification. We define a certain preference attribute and then we can check if the forwarder has a preference set for that attribute and if so, then we will forward that particular work item to that person. All right. So now the only trick is we have to add sort of that custom preference. So that's sort of our scenario. We're going to create something that hopefully looks very similar to what exists that will allow us to set this particular thing. All right. So this is our work area. As you can see, this is currently empty. I'm going to start by creating my plugin fold structure, if my copy paste will work. So usually we use Eclipse with the development accelerator plugin, but in the end, plugins really require a certain fold structure. Here I'm using a local Maven archetype. So we have now created a folder. Let's open that in our Visual Studio Code. My Visual Studio Code is hiding. There we go. And I'll clean up these tabs a little bit here. So the critical part is that we just need to... My Maven archetype created these files and that's all that we need really. So you can just create those by hand. You can use the Eclipse plugin or you can do something like I did here. So now it is actually a Maven project, which is a little bit different than Ant, what we usually use. But in the end, the thing here is that when we invoke Maven, it will package our files up into a plugin by referring here to this configuration file that uses the Maven assembly plugin. And here we just define which files we are going to assemble into a zip file. And that would be a jar file with all the Java files that we have compiled in the compile phase, followed by any web-related UI files that we will find in the web app folder. So, first off, let's start by specifying what we want to do by setting some attributes in our manifest file. I'll just copy-paste this. So here we do want to specify that we are going to use a full-page application and that we are going to inject some JavaScript that will create a clickable link so that we can get to that application. So let's go ahead and create that file. So we need a file header inject in folder UI.js. So let's go ahead and create that. And then we'll create our file. So this is a snippet of JavaScript that will get executed when we load our plugin. And this runs a jQuery. So what this will do, this will inspect the DOM, the HTML structure of our current page of the IdentityIQ application. And we are going to search for a certain anchor, a link. So let's first decide where we want to insert our link into. Because we're sort of extending the current preferences, I think it's probably a good idea to add that right here. So let's see how we can find that. This is probably extremely small. But I am looking here now at the source code of that particular link. And here we have an anchor with a certain h-reference, and I'm trying to copy-paste that. All right, I'm grabbing that here. So now I can put that in our jQuery. So what this will do, this will identify this particular tag. And I don't know, I don't, all right, okay. This anchor, and what we want to do is identify the tag above the parent and then add another link element, right? So we have this check containing that anchor tag. So we're going to, let's go ahead and I'm quickly going, I'm going to copy-paste this for the sake of time. All right, so we have that particular anchor tag. We take tag, we take the parent, and after that parent, we insert this little snippet of HTML that will create another link element with a link to our own one-page application in the plugin. All right, so that is that. And I am quickly going to add, make sure that we contain the SailPoint bundle JavaScript that will contain some Angular elements that are provided by SailPoint that we can use in our plugin. So I'm just quickly going to copy that from my IdentityIQ installation file. And with that, the basic framework of our plugin is ready to start being worked on. So now let's create the boilerplate of the Angular application so that we can then start working on that and then link those two together. So Angular, if you're not familiar with that, is, uses command line interface to initialize all of the components. So let's, we can, let's go ahead and create our application. I'm using NPX to make sure that we're using Angular 15 because if we would by default use the latest version, that might not be compatible with what is being used inside IdentityIQ. I'm going to just accept all the defaults here. And we are installing all of our packages. And once that is finished, in a second, we can switch our editor to that application. There we go. So if I now open my plugin app, as I have named it, inside Visual Studio Code, and I'm just opening this in a separate window so that the editor is not confused about being in two different kinds of projects at the same time. The first thing I'm going to do is to instruct it that when we want, when we are compiling our Angular application, which is called the build, that we tell it not to hash any of the output JavaScript. So by default, it will add a certain hash to all of the JavaScript files to make sure that the ID there is that it is unique and that the browser would at any time have the correct JavaScript files. But that will only confuse the architecture of our plugin where we need to have a fixed name. So that's why we're doing that here. I'm also quickly going to remove some out-of-the-box HTML because that will interfere. There is a banner toolbar that uses the same bootstrap elements that IdentityIQ does, and that will interfere there. So we're just going to strip that quickly. And now we are ready to add these things into our plugin project. So let's switch back to that window. So we are ready to create our single-page HTML file that will sort of be the base for our application. And I'm going to grab this code as well. And, of course, I need to make sure that I am actually creating it. page.xhtml, here we go. And so this, as far as the plugin is concerned, this is all the HTML that there is. So the thing with Angular, again, if you're not familiar with Angular, basically you create your own HTML tags, you could say, and then the application then will interpret what to do when the browser needs to render that. So in Angular, everything lives under the app root. So we have a tag app root here, and everything that we're going to create in our Angular application will live inside there. And then, all the rest here will point to the JavaScript files that will be compiled And then all the rest here will... during the compile phase by the npm build command. So, this will contain, in fact, the full body of our application. So, in a sense, you could say this is all that you need to know to start to figure out how to get your Angular application into a plugin. But currently, this is not doing anything yet, of course. So, there are two more things we need to do to link the application and our plugin together. We need to first make sure that we tell Maven when we compile the code and build the zip file where to find those compiled JavaScript files, or I should say transpiled, because we're not really compiling anything. So, we'll add a file set here. So, here, this is the folder of our Angular application. The dist folder is where the compiled files will end up. And then, we will copy those in the JS folder together with the other JavaScript files. And then, the last thing is to make sure that we tell Maven to execute that build phase. I'm trying to manage my real estate here. All right. So, we add some configuration for the compile phase. So, Maven will first execute a compile phase where any code that needs to be compiled will be compiled. And after that, we will package everything up in a form that can be used by your application. So, during that compile phase, we're going to say that it should execute. We're using the Maven execute plugin. We will execute the command npm in the folder plugin app, where our Angular app lives, and with the argument run build. So, this will be the equivalent of running npm run build, which is the thing that I adjusted all the way at the beginning here, so to make sure that we don't have any hashing in the file names. And I believe with this, we are good to go. So, let's see what our application actually looks like. So, the boilerplate that we get, that we start with. So, in Angular, in a develop mode, runs as a node application, really. So, you can just run ng serve inside your application. It will now compile just enough so that it can actually serve up what you're developing. And this is what a boilerplate starting point of an Angular app looks like. This is sort of the hello world of Angular, so to speak. So, we should have set up everything properly to build our plugin, so let's go ahead and do that. We would do with the command mail and clean package. And we see here that it's executing ng build output hashing equals none, which is what we configured. And then it created this zip file, which is our plugin, and if we look what's inside that zip file, just double checking, we have our single page HTML and then a bunch of JavaScript files. So, what would that look like if we already installed this plugin now? Let's go ahead to our plugin page. Install. And then we see that we have the link that we inserted right where we want it. If I click that, it should load our single page application. And it looks like I have the wrong name in here. I might have used the wrong plugin name. And it seems to be loading something. So, the first time you load any of these pages, there's a compilation process that goes on in the back. And there we go. So, now here we are inside IdentityIQ in our plugin, and of course, this is not giving us anything useful, but we can already see that we have the same application running in our Angular development environment and inside our plugin. So, now that we know that that is working, we can focus on the functionality that we want our application to execute, and we don't have to go into the cycle of code and then go to plugin, deploy, and test. It's quite cumbersome to each time create a zip file and reinstall it. So, now we can just focus on our development within the application and know that once we are ready, we can just bundle it up in the plugin and then install it with only, you know, minimal amount of types. All right. So, let's go and make this do something relatively useful. So, first off, there's one more thing before we can actually start developing, and that is that we will be using mostly REST calls, so there is no Java context so that we can hook into, which you would have when you're inside a plugin. You have access to the whole, say, point context, so to speak, because we're living in this node application that's obviously not there, but we have enough REST resources to work around that. However, the consequence of this is that if we execute any HTTP calls in our development environment, we're just doing that from wherever we are working, and that's fine. But if we would do the same then within our plugin in the same fashion, then I'm mixing things up. I'm sorry. So, when we're in our plugin, we can perfectly execute our HTTP calls because we're inside the SailPoint environment, but in a browser, the client would become the JavaScript, and then that would add a referrer header that causes a security error. It's a course violation, which is cross-origin resource sharing, basically to prevent cross-tab attack factors, and the browser will refuse to execute that. So to work around that, we can tell Angular to use a proxy configuration, and then the result will be that when you're in development mode, it will be the Angular service software that executes the HTTP request and not the browser. So let's quickly set that up. So just create a proxy configuration file, and we're simply going to tell it anything that starts with slash identity IQ. We want to forward to our identity IQ sandbox host, and so this will be done by our Angular serving component, and then we just tell Angular. I think I'm actually in the wrong window. So let me quickly undo this. All right. And there we go. And then we just tell Angular that that is something that we need to use, which is right here. I'm going to expand this a bit more. So when we are serving our application in a development environment, which is what we're doing right now, this is the command that I executed here, ng serve, we want to pass on this proxy configuration. So from now on, whenever from within our application in development mode, which means on our when we execute an HTTP request, that request will be fetched by our node server and not by the browser. All right. With all these things out of the way, we can actually start developing something. So Bootstrap is a modularly based application. So you build components, and each component has its own rendering, its own styling, and its own code base. So we will start by creating those components. First, we'll be using a lot of Bootstrap elements, just like IdentityIQ is. So we will install some Angular Bootstrap extensions. So the Angular Bootstrap and then also just the Bootstrap CSS libraries, so that those are available for use. And then we'll just tell Angular that we are actually using those, which is in the styles configuration right here. So let me just restart the server so that it would take this all into consideration. And so that I don't have to do this while I am setting up different components, I'm already going to define some modules that we'll be using later on, so that those are available, so that we can use forms later on, we can use tabs, and our HTTP client. Those are sort of like dependencies, you could say. Then we can start generating our components. So first off, we'll generate environments, which is very important, so that you can define different attributes, variables, and configurations based on whether you are running in production or in development. So what this does is it creates two files that will contain the same constant, that is a constant with the same name, but you can give it different values depending on whether you are running in production or in development mode. And the important one is actually for us to know that we're in development mode, so we need to give it some credentials that we'll be using later on, and the fact that we're not in production. So what components do I think we'll be needing? So I'll be using a header component, just for styling, and I can use some shorthands, so instead of, I can say generate component header, I can also use G for short, C for component, I will need a component for forwarding preferences, because that's the thing that we're actually building, and we will have different tabs for different kinds of preferences, for different types of forwarding, let's say. Tab has only one B, and we will need a service that we will use to communicate between our components and the IdentityIQ backend. So let's create S for service, and then each component gets its own folder, but services don't, and I think it's cleaner if they have their own folder, so I'm just going to quickly put them in their own folder, there we go. All right, so now our components are ready and waiting to be used, so we have a header component, each component comes with a style sheet, HTML template. Each component comes with a style sheet, HTML template, and then a TypeScript class that you can use to put in code that will be available to use within the HTML template. So we have our header, we have our forwarding preferences component, forwarding tab, and our service. All right, with that, we can actually start writing stuff. Let me just close all of these for now. And the base of our application is this app component HTML template. So we can start by, let's see if we can get these to fit on the same screen. All right, so we'll empty all of this and we will start by putting up a header. Then underneath, I want to have a container div. I'm going to use very basic bootstrap components that contains a row, and then I want to use the full width of the screen. And in there, under the header, I will have my app forwarding preferences. Okay, so if we look at our app here, we have a basic layout, we have a header, and then whatever comes underneath the header. So let's fill that in. We can already see that the templates, whatever's in the templates is being shown. Let's quickly start by showing something in the header first. So I'm just quickly copy pasting things here. This is just a title, basically. And then now in here, what we want to do, this is basically the same as we have here. So this would be sort of our header. And then here we want to have a series of tabs, and then for each tab, we want to be able to configure the forwarding preferences for whatever that tab is for. So we want a section that contains several tabs. Now I want to create those tabs programmatically. And to do that, I define an array that I will use. So in here, in my forwarding preferences component, so this is the class that represents the component that we're going to render. We define an array of tabs with three JavaScript objects with the name of the kind of forwarding. Actually, I think I'd like to rename this to approvals. So now we can tell the template of the forwarding preferences component that it needs to render those tabs. So let's go into the template. And we'll make this a section. Actually, I'll do it like this. Now in here, I will use the Angular Bootstrap tab set functionality, which is very similar to what we have in IdentityIQ. So this gives us a lot of helper classes and styling to quickly create a good looking set of tabs. So we're creating a tab set of the type tab container. So these are some style classes that come with the bootstrap. And then in here, in the tab set, we will have a list of tabs. However, we don't know how many there are, but there is an array. So ideally, we would use a for loop to go over each element and then create a tab. So in Angular, you can do this within your element by calling ng4, create a for loop, and I would say let tab of tabs. So this tabs here is actually this array right here. So now I have a for loop, which is giving me a list of tabs. And then I can say, so for each tab, every tab has a heading. And the square brackets in Angular mean we are using a double binding, meaning this is a directive on the tab element, but we are also binding the element to the code version of the tab itself. So now in the code, we know that the heading will have whatever name that we give it here. So we have every tab will have a title, every tab is active or not, and we have defined one of those to be active. And also, this comes with a JavaScript event provided by the Angular bootstrap tab set that whenever we click on a tab, when we select it, then we are going to instruct our code that that tab is now active equals true. And with that, we already have three tabs generated for us just on the fly like that. All right, so now let's make this look a little bit better. So this is not a course in style sheets. I am not a web designer. So what I did is I'm just going to quickly show you what I did, and then I'm just going to copy the whole styling. So in Chrome, you can inspect an element, which shows you the element right here in the element browser. And then you can right-click and copy, and this might be very small, but you can select copy styles, and then it will put whatever style sheet is, whatever CSS is styling that particular element on your clipboard. So that would look like something like, if I go to the CSS file, right, so that would look something like this. So beforehand, I did spend a little time of compiling this all together. As I said, I'm not a designer, nor is this a talk on styling, so I'm just going to quickly go ahead and fill these, copy, paste these, and fill these in. Of course, these style sheet files are all available inside your Identity IQ installation, so you could just steal it from there as well, borrow it. It's probably better. All right, and we have this and this. And then we have a general styles file here. And then one last thing is I want to make sure I set the background for that. I actually have to tell the app to do that for me because that's outside of the scope of the template. So inside my app component, I will tell it to once it's done loading, it will set that for me. And I did something wrong here. So that is good. I need to implement AfterviewInit. And then the AfterviewInit will be this. All right. Okay. So it's already starting to look like something. So that's about it for layout and styling. So now we need to put in some code that actually does something. And I might quicken the copy-pasting here instead of typing to make sure I don't run out of time too soon. So I'm quickly going to copy a few files that I want to refer to. Nope. I want to have this and this. All right. Inside. All right. This right here. Okay. So what is it that we want to do really? We want to interface with our IdentityIQ so that we can first of all check what is currently set and then set it or replace it if needed. So luckily we have an existing REST endpoint that is not this. called IdentityPreferencesForwarding. If I'm not mistaken. Oh. Got HTTP localhost. Right. Nope. And I wanted to avoid using Postman because it's just so big and loaded. But I'll just quickly launch that here to steal a particular URL. Huh. Okay. So what we want to be able to do is currently if we look at the preferences we see that Amanda Ross is being set as the forwarder. We have a start date and an end date. And we can fetch that and then we have a JSON result here that gives us an end date, a start date, and then an object that represents a forward user with some identity information. So what we want to be able to do is to replicate this but then for each different type and also to set it if we update that. So that is what we'll be using our service for. So I'll get rid of this for now. So in our service, the forwarding configuration service, we need to first identify that type of information. So I am quickly going to set that up as an interface. Right. So that we have the notion of a forwarding info object containing a start date and end date. And then this other element which is a user containing some identity information. I'll create a helper method that is basically going to be my HTTP GET. If I can import my missing classes. If I can import my missing classes, I need an HTTP client which I will create in my constructor. I need an HTTP client. Once I have this constructor, I actually will use this helper method. I apologize for the quickly copy-pasting. I will go over these things in a second. I want to make sure I can cover these things before I wrap up. I've got to make sure that we have everything imported. Add all missing imports. And then we will need some properties set on the class. When we construct the first instance of this service, Angular provides us with this neat way to ask, are we in dev mode, which we are currently right here in our browser right now. Then we can configure certain things and otherwise we will be in prod mode, meaning that will be executed as part of the plugin once we have installed it. Now when we are in prod mode or in the plugin, we get some helper classes from IdentityIQ, which we don't have right now. But we can already, to help the compiler, we can say that these will exist so we will declare them. We will get this class that will provide us these functions. In dev mode, this will not do anything because it doesn't exist, but we don't need them because they won't be used. But what this allows us to do is to fetch the correct URL that our plugin is actually running as. And we can pass it the correct authentication information. In production, we will use the CSRF token that is provided by the application. But here, for our development setup, we will just be using basic authentication. And that's why we configured the environment file. So that's why we can fetch the username and password just for our development mode. Also, the URL that we will be using is going to be slash IdentityIQ, which is what we set up in the proxy configuration. But of course, in the actual IdentityIQ, in the plugin, it will be provided by IdentityIQ. So this way, we can set up an HTTP client that we can use both in our browser, in our development setup, as well as in the actual IdentityIQ running in production. So with that, we should be able to actually go ahead and fetch information. And... It appears to be that there's still something missing in here. So let's write. And in here... So we created our HTTP client. And then we will fetch the information from that URL that we just tested earlier. And let me verify this very quickly. In our service... Here... Hmm... No, no, no, no, no, no, this... Oh... I'm not returning this. So we do need to return an observable here. But I'm actually... There we go. Else... Hmm... So I think what I'll do here... Is maybe switch to a staging environment that I had set up earlier. Because this is actually a breaking piece that will prevent me from actually creating the plugin. So... Let's see how quickly we can pivot. And... Hmm... So if I run this here... Hmm... That doesn't seem to help. And... I need... This HTTP data as... There's probably someone screaming at the screen right now. It's right there, it's right there. Ah, right, right, right, I think... So in JavaScript, or in Angular, if you make an HTTP request, you don't get an immediate response. It creates what is called an observable, which is an object you can observe or subscribe to. That basically tells you asynchronously to wait for the result. And I think what's happening here is that I'm... Right, okay. I think that was that. So right now... If I look in here... So we have this information. Now we just need to call it from our preferences components. Hmm... Right, so let me quickly copy the code for that. In the forwarding tab component. So for each of these tabs here, I want to do this. I will create a form in the back here, and I will import those interfaces. Whenever this tab initializes, this is going to be executed, which is we're going to reach out to our service. We're going to fetch that. That is okay. Right. And... In the HTML, we need to provide... And here we, I believe, it is because we created a form. And a form has a submit, which means we need to give it some code for that. And that should be the last bit of this component. Hopefully, at least this will compile correctly. Yes. Now... In the console... Right, so the code is not doing what I want, but I do want to finish. I have only one minute left. I do want to finish by showing you that whatever the application is doing right now, we can make it do in the plugin as well. So what it's supposed to do is to get this forwarding info and then displaying it here if it exists. It's probably a very simple fix, but unfortunately, I really don't have the time anymore. So I'm just going to wrap this up into a plugin. So we go back to our plugin project here. I'm going to package using Maven. So this is going to create our plugin zip file. Right. And then if we go back here... We should have the same not working application inside our IdentityIQ. But the point being here was not... I wasn't going to show you how to create a fantastic plugin that is working. The point was to show you how you can... It's doing this again. The point was to show you how to create an application that you can then sort of use as a prototype to then turn into a plugin. And I think it's loading right now. And if we give it five more seconds... Then we do see that we have the same application running here. The only bit that's missing is that somehow it's not fetching this correctly. Then, of course, to update, we can use the same HTTP method to do a put. For the other ones, I was going to invoke a workflow that you can use with a REST interface as well. And the plugin does contain all the rules and the workflows as well. By the moment you install the plugin, those artifacts will be deployed as well. I hope this was useful and you learned something. It was a learning project for me, and I thought maybe someone else could find some use for it as well. Enjoy the rest of your week, and thank you for your attention.