MIFOSX-395: provide optional staffId and staffDisplayName to auth response.

This commit is contained in:
Keith Woodlock
2013-05-30 12:50:38 +01:00
parent 7f062a394b
commit c08d163562
5 changed files with 90 additions and 22 deletions
+52 -17
View File
@@ -90,7 +90,7 @@
<body>
<div id="page-wrapper">
<div id="flybar">
<div id="nav-logo">1.2.0.RELEASE API</div>
<div id="nav-logo">1.3.0.RELEASE API</div>
<div class="flybar-nav">
<h2 class="flybar-button">Overview</h2>
<div class="flybar-menu-overview">
@@ -12720,8 +12720,7 @@ GET https://DomainName/api/v1/runreports/{reportName}
</div>
</div>
<a id="authenticate_request" name="authenticate_request"
class="old-syle-anchor">&nbsp;</a>
<a id="authenticate_request" name="authenticate_request" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Verify authentication</h4>
@@ -12736,24 +12735,60 @@ POST authentication?username=mifos&password=password
Content-Type: application/json
No Request Body
</code>
<p>Example response of autentication for user that is not linked with any staff.</p>
<code class="method-response">
{
"username": "mifos",
"userId": 1,
"base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
"authenticated": true,
"roles": [
{
"id": 1,
"name": "Super user",
"description": "This role provides all application permissions."
}
],
"permissions": [
"ALL_FUNCTIONS"
]
"username": "mifos",
"userId": 1,
"base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
"authenticated": true,
"officeId": 1,
"officeName": "Head Office",
"roles": [
{
"id": 1,
"name": "Super user",
"description": "This role provides all application permissions."
}
],
"permissions": [
"ALL_FUNCTIONS"
]
}
</code>
<p>Example response of autentication for user that is linked with a staff member and role.</p>
<code class="method-response">
{
"username": "mifos",
"userId": 1,
"base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
"authenticated": true,
"officeId": 1,
"officeName": "Head Office",
"staffId": 1,
"staffDisplayName": "Director, Program",
"organisationalRole": {
"id": 100,
"code": "staffOrganisationalRoleType.programDirector",
"value": "Program Director"
},
"roles": [
{
"id": 1,
"name": "Super user",
"description": "This role provides all application permissions."
}
],
"permissions": [
"ALL_FUNCTIONS"
]
}
</code>
<code class="method-request">
POST authentication?username=mifos&password=fail
Content-Type: application/json
@@ -76,9 +76,14 @@ public class AuthenticationApiResource {
final Long officeId = principal.getOffice().getId();
final String officeName = principal.getOffice().getName();
final Long staffId = principal.getStaffId();
final String staffDisplayName = principal.getStaffDisplayName();
final EnumOptionData organisationalRole = principal.organisationalRoleData();
authenticatedUserData = new AuthenticatedUserData(username, officeId, officeName, organisationalRole, roles, permissions,
authenticatedUserData = new AuthenticatedUserData(username, officeId, officeName, staffId, staffDisplayName,
organisationalRole, roles, permissions,
principal.getId(), new String(base64EncodedAuthenticationKey));
}
@@ -28,6 +28,10 @@ public class AuthenticatedUserData {
@SuppressWarnings("unused")
private final String officeName;
@SuppressWarnings("unused")
private final Long staffId;
@SuppressWarnings("unused")
private final String staffDisplayName;
@SuppressWarnings("unused")
private final EnumOptionData organisationalRole;
@SuppressWarnings("unused")
private final Collection<RoleData> roles;
@@ -41,17 +45,21 @@ public class AuthenticatedUserData {
this.authenticated = false;
this.officeId = null;
this.officeName = null;
this.staffId = null;
this.staffDisplayName = null;
this.organisationalRole = null;
this.roles = null;
this.permissions = permissions;
}
public AuthenticatedUserData(final String username, final Long officeId, final String officeName,
final EnumOptionData organisationalRole, final Collection<RoleData> roles, final Collection<String> permissions,
final Long userId, final String base64EncodedAuthenticationKey) {
public AuthenticatedUserData(final String username, final Long officeId, final String officeName, final Long staffId,
final String staffDisplayName, final EnumOptionData organisationalRole, final Collection<RoleData> roles,
final Collection<String> permissions, final Long userId, final String base64EncodedAuthenticationKey) {
this.username = username;
this.officeId = officeId;
this.officeName = officeName;
this.staffId = staffId;
this.staffDisplayName = staffDisplayName;
this.organisationalRole = organisationalRole;
this.userId = userId;
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
@@ -31,7 +31,6 @@ public class Staff extends AbstractPersistable<Long> {
@Column(name = "lastname", length = 50)
private String lastname;
@SuppressWarnings("unused")
@Column(name = "display_name", length = 100)
private String displayName;
@@ -47,6 +46,7 @@ public class Staff extends AbstractPersistable<Long> {
@Column(name = "organisational_role_enum", nullable = true)
private Integer organisationalRoleType;
@SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "organisational_role_parent_staff_id", nullable = true)
private Staff organisationalRoleParentStaff;
@@ -158,4 +158,8 @@ public class Staff extends AbstractPersistable<Long> {
public Long officeId() {
return this.office.getId();
}
public String displayName() {
return this.displayName;
}
}
@@ -465,4 +465,20 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
if (hasNotPermissionForDatatable(datatable, "READ")) { throw new NoAuthorizationException("Not authorised to read datatable: "
+ datatable); }
}
public Long getStaffId() {
Long staffId = null;
if (this.staff != null) {
staffId = this.staff.getId();
}
return staffId;
}
public String getStaffDisplayName() {
String staffDisplayName = null;
if (this.staff != null) {
staffDisplayName = this.staff.displayName();
}
return staffDisplayName;
}
}