Commit ad0a98d1 authored by Matija Obreza's avatar Matija Obreza

Merge branch '497-jsp-admin-oauth-editor' into 'master'

Resolve "JSP Admin OAuth editor"

Closes #497

See merge request genesys-pgr/genesys-server!516
parents 3d6d8196 be263ea5
......@@ -19,6 +19,7 @@ package org.genesys2.server.mvc.admin;
import org.genesys.blocks.oauth.model.OAuthClient;
import org.genesys.blocks.oauth.model.OAuthRole;
import org.genesys.blocks.oauth.service.OAuthClientDetailsService;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.mvc.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
......@@ -65,6 +66,7 @@ public class OAuthManagementController extends BaseController {
model.addAttribute("clientDetails", client);
model.addAttribute("ROLE_CLIENT", OAuthRole.CLIENT);
model.addAttribute("ROLE_TRUSTED_CLIENT", OAuthRole.TRUSTED_CLIENT);
model.addAttribute("ROLE_EVERYONE", OAuthRole.EVERYONE);
return VIEW_PATH + "/edit";
}
......@@ -96,9 +98,12 @@ public class OAuthManagementController extends BaseController {
}
@PreAuthorize("hasAnyRole('VETTEDUSER','ADMINISTRATOR')")
@RequestMapping(value = "/save-client", method = RequestMethod.POST, params = { "id", "action-delete" })
public String deleteClient(Model model, @RequestParam("id") String clientId) {
@RequestMapping(value = "/save-client", method = RequestMethod.POST, params = "action-delete")
public String deleteClient(Model model, @RequestParam("clientId") String clientId) {
OAuthClient clientDetails = clientDetailsService.getClient(clientId);
if (clientDetails == null) {
throw new NotFoundElement("Not found by clientId = " + clientId);
}
LOG.info("Deleting client {}", clientDetails.getClientId());
clientDetailsService.removeClient(clientDetails);
return "redirect:" + CONTROLLER_PATH + "/";
......
......@@ -692,6 +692,7 @@ oauth-client.create=Create OAuth Client
oauth-client.id=Client ID
oauth-client.secret=Client Secret
oauth-client.redirect.uri=Client redirect URI
oauth-client.allowed-cors-origins=Allowed CORS origins
oauth-client.access-token.accessTokenValiditySeconds=Access token validity
oauth-client.access-token.refreshTokenValiditySeconds=Refresh token validity
oauth-client.access-token.defaultDuration=Use default
......
......@@ -58,6 +58,10 @@
<label class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.registeredRedirectUri"/></label>
<div class="col-lg-9 col-md-8"><c:out value="${clientDetails.registeredRedirectUri}" /></div>
</div>
<div class="row">
<label class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.allowed-cors-origins"/></label>
<div class="col-lg-9 col-md-8"><c:out value="${clientDetails.allowedOrigins}" /></div>
</div>
<div class="row">
<label class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.resourceIds"/></label>
<div class="col-lg-9 col-md-8"><c:out value="${clientDetails.resourceIds}" /></div>
......
......@@ -61,7 +61,21 @@
</ul>
</div>
</div>
<div class="form-group">
<label for="redirectUri" class="col-lg-3 col-md-4 control-label">
<spring:message code="oauth-client.allowed-cors-origins"/>
</label>
<div class="col-lg-9 col-md-8">
<textarea style="min-height: 150px" id="corsOrigins" name="origins" class="form-control"><c:forEach items="${clientDetails.allowedOrigins}" var="origin"><c:out value="${origin}" />
</c:forEach></textarea>
<p class="help-block">One per line.</p>
<ul>
<c:forEach items="${clientDetails.allowedOrigins}" var="origin">
<li><c:out value="${origin}"/></li>
</c:forEach>
</ul>
</div>
</div>
<div class="form-group">
<label for="redirectUri" class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.access-token.accessTokenValiditySeconds"/></label>
<div class="col-lg-9 col-md-8">
......@@ -88,6 +102,10 @@
<input type="checkbox" name="roles[]" ${clientDetails.authorities.contains(ROLE_TRUSTED_CLIENT) ? 'checked' : '' } value="TRUSTED_CLIENT"/>
TRUSTED_CLIENT</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="roles[]" ${clientDetails.authorities.contains(ROLE_EVERYONE) ? 'checked' : '' } value="EVERYONE"/>
EVERYONE</label>
</div>
</div>
</div>
<div class="form-group">
......@@ -102,18 +120,26 @@
<label class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.scope"/></label>
<div class="col-lg-9 col-md-8">
<div class="checkbox">
<label><input type="checkbox" name="scopes[]" ${clientDetails.scope.contains('read') ? 'checked' : '' } value="read"/>
<label><input type="checkbox" name="clientScopes[]" ${clientDetails.scope.contains('read') ? 'checked' : '' } value="read"/>
Read</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="scopes[]" ${clientDetails.scope.contains('write') ? 'checked' : '' } value="write"/>
<label><input type="checkbox" name="clientScopes[]" ${clientDetails.scope.contains('write') ? 'checked' : '' } value="write"/>
Write</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="clientScopes[]" ${clientDetails.scope.contains('trust') ? 'checked' : '' } value="trust"/>
Trust</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 col-md-4 control-label"><spring:message code="oauth-client.authorizedGrantTypes"/></label>
<div class="col-lg-9 col-md-8">
<div class="checkbox">
<label><input type="checkbox" name="grantTypes[]" ${clientDetails.authorizedGrantTypes.contains('implicit') ? 'checked' : '' } value="implicit"/>
Implicit</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="grantTypes[]" ${clientDetails.authorizedGrantTypes.contains('authorization_code') ? 'checked' : '' } value="authorization_code"/>
Authorization code</label>
......@@ -156,13 +182,17 @@
<label><input type="checkbox" name="autoApproveScopes[]" ${clientDetails.autoApproveScopes.contains('write') ? 'checked' : '' } value="write"/>
Write</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="autoApproveScopes[]" ${clientDetails.autoApproveScopes.contains('trust') ? 'checked' : '' } value="trust"/>
Trust</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-3 col-lg-9">
<input type="button" onClick="return submitJson(this.form);" value="<spring:message code='save' />" class="btn btn-primary"/>
<input type="button" name="action-delete" value="<spring:message code='delete' />" class="btn btn-default"/>
<input type="submit" name="action-delete" value="<spring:message code='delete' />" class="btn btn-primary"/>
<a class="btn btn-default" href="<c:url value='/admin/oauth-clients/' />" class="btn">
<spring:message code="cancel"/>
</a>
......@@ -179,7 +209,9 @@
var data = $(form).serializeObject();
delete data['_csrf'];
data.redirectUris = data.redirect.split('\n').map(function(x) { return x.trim(); });
data.allowedOrigins = data.origins.split('\n').map(function(x) { return x.trim(); });
delete data.redirect;
delete data.origins;
console.log(data);
$.ajax({
url: form.action + "?action-save=1" + (data.id === undefined ? "" : "&id=" + data.id + "&version=" + data.version),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment