greetgo.mvc.security

MVC Functionality using in greetgo! - security features

License

License

Categories

Categories

Security
GroupId

GroupId

kz.greetgo.mvc
ArtifactId

ArtifactId

greetgo.mvc.security
Last Version

Last Version

3.0.7
Release Date

Release Date

Type

Type

jar
Description

Description

greetgo.mvc.security
MVC Functionality using in greetgo! - security features
Project URL

Project URL

https://github.com/greetgo/greetgo.mvc
Source Code Management

Source Code Management

https://github.com/greetgo/greetgo.mvc.git

Download greetgo.mvc.security

How to add to project

<!-- https://jarcasting.com/artifacts/kz.greetgo.mvc/greetgo.mvc.security/ -->
<dependency>
    <groupId>kz.greetgo.mvc</groupId>
    <artifactId>greetgo.mvc.security</artifactId>
    <version>3.0.7</version>
</dependency>
// https://jarcasting.com/artifacts/kz.greetgo.mvc/greetgo.mvc.security/
implementation 'kz.greetgo.mvc:greetgo.mvc.security:3.0.7'
// https://jarcasting.com/artifacts/kz.greetgo.mvc/greetgo.mvc.security/
implementation ("kz.greetgo.mvc:greetgo.mvc.security:3.0.7")
'kz.greetgo.mvc:greetgo.mvc.security:jar:3.0.7'
<dependency org="kz.greetgo.mvc" name="greetgo.mvc.security" rev="3.0.7">
  <artifact name="greetgo.mvc.security" type="jar" />
</dependency>
@Grapes(
@Grab(group='kz.greetgo.mvc', module='greetgo.mvc.security', version='3.0.7')
)
libraryDependencies += "kz.greetgo.mvc" % "greetgo.mvc.security" % "3.0.7"
[kz.greetgo.mvc/greetgo.mvc.security "3.0.7"]

Dependencies

compile (1)

Group / Artifact Type Version
kz.greetgo.mvc : greetgo.mvc jar 3.0.7

test (3)

Group / Artifact Type Version
org.testng : testng jar 6.14.3
org.assertj : assertj-core jar 3.12.2
kz.greetgo.util : greetgo.util jar 0.1.3

Project Modules

There are no modules declared in this project.

greetgo.mvc

Light implementation of MVC pattern. It is made in the image and likeness of SpringMVC

Capabilities

Organizational capabilities

  • Simple, light and small;
  • Does not contain unnecessary dependencies;
  • Not connected to any Dependency Injection library (so you can use any);

Functionalities

It is made in the image and likeness of SpringMVC (but does not have any drawbacks);

Parameters

Allows to read parameters:

  • for the request: ...?asd=value&...&asd=value2&...
    • using @Par("asd") String asd, get the first value: asd === "value1"
    • using @Par("asd") List<String> asd, get all values: asd === ["value1","value2"]
  • If the parameter contains JSON ...?wow={"asd":"value"}, it can be deserialized using @Par("wow") @Json ClassWithAsd wow;
  • All parameters ...?asd=value&dsa=value can be put directly into the object using @ParamsTo ClassWithAsdAndDsa argument;
  • The parameter can be read from the URL path .../{asd}/... using annotation @ParPath("asd") String asd (it is possible to add @Json);
  • The parameter can be read from the session using @ParSession;
  • The parameter can be read from cookies using @ParCookie (both directly and with the help of cookie-serialization built-in mechanism);
  • The whole request body can be put into the parameter using @RequestInput String requestContentUtf8;
Rendering
  • what the controller method returns can be serialized
    • in JSON using @ToJson from controller method;
    • in XML using @ToXml from controller method;
  • allows you to render in JSP, and transmit parameters there through MvcModel;
  • instead of JSP, you can use any other rendering mechanism (the library does not know anything about JSP);
Redirects
  • Redirects can be done using exceptions: throws Redirect.to("some/uri")
    • and add cookies to them: throws Redirect.to("some/uri").addCookie("KEY", "str value");
      • then they can be read in the parameter of the controller method in this way: @ParCookie(value="KEY", asIs = true) String str
    • or serialized cookies: throws Redirect.to("some/uri").addCookieObject("KEY", object);
      • then they can be read in the parameter of the controller method in this way: @ParCookie(value="KEY", asIs = false) SomeClass object
  • redirects can be returned from the controller method:return Redirect.to("some/uri");
MethodFilter
  • can be filtered by different HTTP methods, using @MethodFilter;

and

  • Request and Response classes are combined into one: RequestTunnel, which simplifies the structure of the library and its use;
  • Cool possibility of organizing erroneous requests:
    • somewhere inside the code throw new RestError(450, "Bad!"); and the request ends with error code 450 and the response body "Bad";
    • or - throw new RestJsonError(450, someObject); and the request ends with error code 450 and and the response body someObject deserialized in JSON;
  • It is possible to implement any complex security;

Disadvantages

  • Previously, it is needed to implement two classes (but there is an example of implementation and you can just copy/paste!);

Typical Rest-controller

@Bean
@ControllerPrefix("/orgUnit")
public class OrgUnitController implements Controller {

  public BeanGetter<OrgUnitRegister> orgUnitRegister;

  @ToJson
  @OnGet("/rootList")
  public OrgUnitRootListResult rootList() {
    return orgUnitRegister.get().rootList();
  }

  @ToJson
  @OnGet("/children/{parentId}")
  public List<OrgUnitNode> children(@ParPath("parentId") String parentId) {
    return orgUnitRegister.get().children(parentId);
  }


  @ToJson
  @OnGet("/findRootAndSaveCurrentOrgUnitId")
  public void findRootAndSaveCurrentOrgUnitId(@Par("type") String type, @Par("id") String id) {
    orgUnitRegister.get().findRootAndSaveCurrentOrgUnitId(type, id);
  }

  @ToJson
  @OnGet("/details/{orgUnitId}")
  public OrgUnitDetails details(@ParPath("orgUnitId") String orgUnitId) {
    return orgUnitRegister.get().details(orgUnitId);
  }

  @ToJson
  @OnDelete("/delete/{orgUnitId}")
  public void delete(@ParPath("orgUnitId") String orgUnitId) {
    orgUnitRegister.get().delete(orgUnitId);
  }

  @ToJson
  @OnPost("/save")
  public OrgUnitNode save(@Par("parentId") String parentId,
                          @Par("id") String id,
                          @Par("guid") String guid,
                          @Par("name") String name
  ) {
    return orgUnitRegister.get().save(parentId, id, guid, name);
  }

  @ToJson
  @OnGet("/pathToPerson/{rootOrgUnitId}/{personId}")
  public List<String> pathToPerson(@ParPath("rootOrgUnitId") String rootOrgUnitId,
                                   @ParPath("personId") String personId,
                                   MvcModel model
  ) {
    List<String> ret = orgUnitRegister.get().pathToPerson(rootOrgUnitId, personId);
    model.setStatus(ret != null ? 200 : 202);
    return ret;
  }

  @ToJson
  @OnGet("/pathToOrgUnit/{orgUnitId}")
  public List<String> pathToOrgUnit(@ParPath("orgUnitId") String orgUnitId, MvcModel model) {
    List<String> ret = orgUnitRegister.get().pathToOrgUnit(orgUnitId);
    model.setStatus(ret != null ? 200 : 202);
    return ret;
  }

  @ToJson
  @OnGet("/search")
  public List<OrgUnitSearchRecord> search(@ParamsTo OrgUnitSearch a, MvcModel model) {
    orgUnitRegister.get().search(a);
    model.setStatus(a.hasMoreElements ? 200 : 201);
    return a.result;
  }

  @ToJson
  @OnPost("/switchingRoleContent")
  public List<SwitchingRole> switchingRoleContent() {
    return orgUnitRegister.get().switchingRoleContent();
  }

  @ToJson
  @OnPost("/assignedRoles/{orgUnitId}")
  public List<AssignedRoleId> assignedRoles(@ParPath("orgUnitId") String urgUnitId) {
    return orgUnitRegister.get().assignedRoles(urgUnitId);
  }

  @ToJson
  @OnPost("/addRoles")
  public Map<String, AssignTypeModification> addRoles(
    @Par("id") String personId, @Par("roleIds") @Json List<String> roleIds,
    @ParSession("personId") String modifierId
  ) {
    return orgUnitRegister.get().addRoles(personId, roleIds, modifierId);
  }

  @ToJson
  @OnPost("/removeRoles")
  public Map<String, AssignTypeModification> removeRoles(
    @Par("id") String personId, @Par("roleIds") @Json List<String> roleIds,
    @ParSession("personId") String modifierId
  ) {
    return orgUnitRegister.get().removeRoles(personId, roleIds, modifierId);
  }


  @ToJson
  @OnGet("/allPersonsUnder")
  public List<PersonRecord> allPersonsUnder(@ParamsTo InOutAllPersonsUnder inOut, MvcModel model) {
    orgUnitRegister.get().allPersonsUnder(inOut);
    model.setStatus(inOut.hasMore ? 201 : 200);
    return inOut.list;
  }
}

Versions

Version
3.0.7
3.0.6
3.0.5
3.0.4
3.0.2
3.0.1
3.0.0
2.1.2
2.1.1
2.1.0
2.0.10
2.0.9
2.0.8
2.0.7