Skip to content

Authentication

In this scenario, we'll see how to set up a mechanism to admin the user table with Bluage.

In the business layer

Create 2 entities: AppUser and Role and their associated business objects.

In the entity AppUser:

  • Apply the stereotypes "identifier" and "userid" to the attribute login.
  • Apply the stereotype "password" to the attribute password.
  • Apply the tag "generator.class=assigned" to the entity.

In the entity role

  • Apply the stereotype "identifier" to the attribute id.
  • Apply the stereotype "role" to the attribute roleName.

Admin1

Create the view objects:

Admin2

In the service layer

Creates two beans:

Admin3

  • FieldError:
    • Add the stereotype "bean".
    • Add an attribute errors of type List and tag "TemplateObject=String".
    • Add an attribute fieldname of type String.
  • GlobalContext:
    • With the stereotype "bean".
    • With an attribute errors of type List and the tag "TemplateObject=FieldError".

Creates a bean FacadeApiAppUser:

Admin14

  • With the stereotype "bean".
  • An attribute globalContext of type GlobalContext.
  • An attribute appUser of type AppUserVO.

Create two services:

Admin5

ApiAppUser service

  • Apply the stereotypes and "JsonController" to it.
  • Define the methods:
    • createAppUser:

      Admin6

  • Apply the stereotypes "process" and "JsonService".
  • With an object the type FacadeApiAppUser as in parameter.
  • With a boolean as return value.

    This method creates a new user after validates that any other user in the table has the same login.

    If one user exist in the table the methods adds one error to the error list of globalContext.

  • deleteAppUser:

    Admin7

  • Apply the stereotypes "process" and "JsonService".
  • An object of type AppUserVO as parameter.
  • An boolean as return value.

    This method delete a user from the data base.

  • getAppUsers:

    Admin8

  • Apply the stereotypes "process" and "JsonService" to it.
  • A List with the tag "TemplateObject=AppUserVO" as return.

    This methods get from the database the list of existing users.

  • isLoginUsed:

    Admin9

  • Apply the stereotypes "process" and "JsonService" to it.
  • Add an in parameter of String type named login.
  • A boolean as return value.

    The method makes a select to the database to check if there are an existing user with the same login.

  • updateAppUser:

    Admin10

  • Apply the stereotypes "process" and "JsonService" to it.
  • Add an object of type FacadeApiAppUser like in parameter.
  • Add a boolean value as result.

    The method makes the update in the database of the user passed like parameter within of facadeApiAppUser.



ApiRole service

-   Apply the stereotypes and "JsonController" to it.
-   Add the method getRoleList:

Admin11 - Assign the stereotypes "process" and "JsonService". - The return of the method is a List with the tag "TemplateObject=RoleVO". This method load the list of the possible user roles from the database.

Create two services:

Admin12

ServiceAppUser service

-   With a createAppUser operation:
    -   Add the stereotype "create".
    -   Add an in parameter named bo of type AppUserBO.
    -   Add a return parameter named res of type boolean. It will be
        return true if the operation is completed, false if there
        are an error.

This method creates a user in the datatable. - With a createAppUser operation: - Add the stereotype "hql_operation". - Set the tag "hql_request" with the value: "select bo from AppUserBO bo where bo.login = :login" - Add an in parameter named login of type String. - Add a return parameter of type AppUserBO.

This method get the user with the same login passed as parameter. - With a findAllAppUser operation: - Add the stereotype "hql_operation". - Add a return parameter of type List with the tag "TemplateObject=AppUserBO" - Set the tag "hql_request" with: "select bo from AppUserBO bo left join fetch bo.role order by bo.login"

This method returns all the user in the database order by login. - With a updateAppUser operation: - Add the stereotype "update". - An in parameter named bo of type AppUserBO - A return parameter named result of type boolean. This method update the values of the user passer as parameter in the database. It will be return true if the operation is completed, false if there are an error. - With a deleteAppUser operation: - Apply the stereotype "delete" to it. - With an in parameter named bo of type AppUserBO. - With an return parameter of type boolean. This method erase the user passed as parameter from the database. It will be return true if the operation is completed, false if there are an error.

ServiceRole service

-   With a findAllRole operation:
    -   Apply the stereotype "find\_all" to it.
    -   With a return parameter of type List.

This method recover the role list from the database.

In the view layer

In the folder components, add a user case AdminComponents with a Component AppUserForm:

Admin13

The Component have: - A property appUser of type AppUserVO with direction = in. - The properties: - globalContext of type GlobalContext. - pnlUpdateUserForm of type Object. - listRoles of type List with tag TemplateObject = RoleVO. - selectedAppUser of type AppUserVO. Admin14 - A panel pnlUpdateUserForm with tags: - causeValidation = true. - nestedPropertyVisibleProperty = "appUser.login"

All the fields in the screen must be within this panel. - A Label lblLogin with text = "Login". - A TextBox txtLogin with tags: - colProperty = login. - instance = appUser. - readOnly = true. - A Label lblPassword with text "Password". - A TextBox txtPassword with tags: - colProperty = password. - instance = appUser. - type = password. - valMessage = "Password is required". - valRequired = true. - A Message msgTxtPassword with tag "forId = txtPassword". - A Label lblConfirmPassword with text "Confirm password". - A TextBox txtConfirmPassword with stereotype "ValidatorEquals" with tags: - colProperty = confirmPassword. - equals = txtPassword. - instance = appUser. - type = password. - valMessage = "Confirm password is required". - valRequired = true. - A Message msgTxtConfirmPassword with tag "forId = txtConfirmPassword". - A Label lblTxtConfirmPasswordNotEqual with tags: - nestedPropertyVisibleProperty = "txtConfirmPassword.dirty && txtConfirmPassword.errors?.validateEqual" - text = "Password aren't equals". - A Label lblRole with text "Role". - A DropDown ddRole with tags: - instance = appUser. - key = roleName. - listInstance = listRoles. - nestedProperty = "role.id". - valMessage = "Role is required". - valRequired = true. - value = id. - A Message msgDdRole with "forId = ddRole". - A Button btnUpdate with text = "Update user". - A event btnUpdateEventClick associated with the button btnUpdate:

Admin15

If the form is not valid the method mark the fields in error for show the error messages. If the form is valid, the method update the appUser passed as parameter to the component. After, the execution navigate to the main screen.

Creates an admin folder with a diagram user case named admin. Inside the diagram add the screens:

Admin16

  • AdminHome:

    Admin17

    Add the stereotype "START_VIEW" to it.

    The screen have:

  • The properties:
    • globalContext of type GlobalContext.
    • listOfAppUsers of type List with the tag "TemplateObject=AppUserVO".
    • selectedAppUser of type AppUserVO.

      Admin18

  • A principal panel named subContent.
  • Add "Component" AppUserForm with selectedAppUser as parameter.
  • A panel of type simple named pnlGrid.
  • A DataGrid dgUserList inside, with the tag "listInstance=listOfAppUsers".
  • A Label named dgcolLogin associate to the datagrid with tags:
    • colProperty = login.
    • headerText = "Login".
  • A Label dgcolRole associates to the datagrid with tags:
    • headerText = "Role".
    • nestedProperty = "role.roleName".
  • A Button dgcolBtnSelect associate to the datagrid with tag text = "Select".
    • A Button dgcolBtnDelete associate to the datagrid with tag text = "Delete".
  • The event btnLoginEventClick associate to dgcolBtnSelect:

    Admin19

    The method has as parameters an EventClick object and an AppUserVO object named item. It assign item to the selectedAppUser variable. Angular refresh the component AppUserFom.

  • An event btnDeleteEventClick associate to the control dgcolBtnDelete: Admin20

The method has as parameters the EventClick and an object of type AppUserVO named item. It calls ApiAppUser.deleteAppUser to delete the item AppUserVO. After it calls getAppUsers for refresh the data in the screen. - AdminMain: Admin21

The screen have:

Admin22 - A principal panel named content. - A panel named subContent. - A panel submenu with the buttons btnCreateUser and btnAdminHome. - The event btnCreateUserEventClick associate to control btnCreateUser: Admin23

This method navigate to the CreateUser screen. - An event btnAdminHomeEventClick associate to the control btnAdminHome: Admin24 This method navigate to the screen AdminHome. - CreateUser: Admin25

The screen have: - The properties: - globalContext of type GlobalContext. - pnlCreateUserForm of type Object. - resultMessage of type String. - listRoles of List with tag "TemplateObject=RoleVO". - appUser of type AppUserVO. Admin26 - A principal panel named subContent. - A Label lblTitle with tag text="Create new user". - A panel pnlCreateUserForm of type form which contains all the others controls in the screen. - A Label lblLogin with text "Login". - A TextBox txtLogin with tags: - colProperty = login. - instance = appUser - valMessage = "Login is required". - valRequired = true. - A Message msgTxtLogin with tags "forId = txtLogin". - A Label lblTxtLoginUsed with tags: - nestedPropertyVisibleProperty = "txtLogin.dirty && txtLogin.errors?.used". - text = "Login is used". - A Label lblPassword with text "Password". - A TextBox txtPassword with tags: - colProperty = password. - instance = appUser. - type = password. - valMessage = "Password is required". - valRequired = true. - A Message msgTxtPassword with tag "forId = txtPassword". - A Label lblConfirmPassword with text "Confirm password". - A TextBox txtConfirmPassword with stereotype "ValidatorEquals" and tags: - colProperty = confirmPassword. - equals = txtPassword. - instance = appUser. - type = password. - valMessage = "Confirm password is required". - valRequired = true. - A Message msgTxtConfirmPassword with tags "forId = txtConfirmPassword". - A Label lblTxtConfirmPasswordNotEqual with tags: - nestedPropertyVisibleProperty = "txtConfirmPassword.dirty && txtConfirmPassword.errors?.validateEqual" - text = "Password aren't equals". - A Label lblRole with text "Role". - A DropDown with tags: - colProperty = role. - instance = appUser. - key = roleName. - listInstance = listRoles. - valMessage = "Role is required". - valRequired = true. - A Message msgDdRole with tag "forId = ddRole". - A Button btnCreate with text "Create user". - A Label with tag "colProperty = resultMessage". - The event btnCreateEventClick associate to btnCreate control with a EventClick parameter: Admin27

The method verify if the pnlCreateUserForm is valid. If the form not is valid, le messages du form are marked as dirty for show the error message. If the form is valid, the method calls createAppUser for create a user. If the creations fails, an error message is show. If the creation is success the message "User created" is show.