progress for registered services page
This commit is contained in:
parent
99b7ee20b2
commit
a6d2bd7bba
|
@ -3,6 +3,8 @@ package eu.dnetlib.openaire.usermanagement;
|
|||
import eu.dnetlib.openaire.usermanagement.utils.RegisteredServicesUtils;
|
||||
import eu.dnetlib.openaire.usermanagement.utils.TokenUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.util.Integers;
|
||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
@ -20,6 +22,7 @@ public class EditRegisteredService extends HttpServlet {
|
|||
|
||||
@Autowired
|
||||
private RegisteredServicesUtils registeredServicesUtils;
|
||||
private static final Logger logger = Logger.getLogger(EditRegisteredService.class);
|
||||
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
|
@ -29,24 +32,34 @@ public class EditRegisteredService extends HttpServlet {
|
|||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
//AuthenticationUtils.checkAuthenticationAndRedirect(authentication, response);
|
||||
String accessToken = authentication.getAccessTokenValue();
|
||||
request.getSession().setAttribute("authenticated",
|
||||
!SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()
|
||||
.equals("anonymousUser"));
|
||||
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.
|
||||
getContext().getAuthentication();
|
||||
|
||||
String accessToken = authentication.getAccessTokenValue();
|
||||
String serviceId = request.getParameter("id");
|
||||
|
||||
try {
|
||||
if (!registeredServicesUtils.isAuthorized(authentication.getSub(), serviceId)) {
|
||||
if (!registeredServicesUtils.isAuthorized(authentication.getSub(), Integer.parseInt(serviceId))) {
|
||||
request.getSession().setAttribute("message", "You have no permission to edit the service.");
|
||||
response.sendRedirect("./registeredService");
|
||||
response.sendRedirect("./registeredServices");
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
} catch (SQLException sqle) {
|
||||
logger.error("Unable to access service with id " + serviceId, sqle);
|
||||
request.getSession().setAttribute("message", "There was an error accessing your service.");
|
||||
response.sendRedirect("./registeredService");
|
||||
response.sendRedirect("./registeredServices");
|
||||
|
||||
} catch (NumberFormatException nfe) {
|
||||
logger.error("Unable to access service with id " + serviceId, nfe);
|
||||
request.getSession().setAttribute("message", "Service with id " + serviceId + " does not exist.");
|
||||
response.sendRedirect("./registeredServices");
|
||||
}
|
||||
|
||||
if (serviceId == null || serviceId.isEmpty()) {
|
||||
request.getSession().setAttribute("message", "No selected service is provided.");
|
||||
request.getSession().setAttribute("message", "Service with id " + serviceId + " does not exist.");
|
||||
}
|
||||
|
||||
ServiceResponse serviceResponse = TokenUtils.getRegisteredService(serviceId, accessToken);
|
||||
|
|
|
@ -55,13 +55,14 @@ public class RegisterServiceServlet extends HttpServlet {
|
|||
if ( name!= null && !name.isEmpty() && userid != null && !userid.isEmpty() &&
|
||||
email != null && !email.isEmpty()) {
|
||||
String serverMessage = TokenUtils.registerService(userid, name, description, email, accessToken);
|
||||
|
||||
System.out.println("Server message" + serverMessage);
|
||||
if (serverMessage == null) {
|
||||
request.getSession().setAttribute("message", "There was an error registering your service. Please try again later.");
|
||||
response.sendRedirect("./registeredServices");
|
||||
}
|
||||
|
||||
serviceResponse = new Gson().fromJson(serverMessage, ServiceResponse.class);
|
||||
System.out.println("SERVICE RESPONSE " + serviceResponse);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ public class RegisteredServicesServlet extends HttpServlet {
|
|||
registeredServices = registeredServicesUtils.
|
||||
getRegisteredServiceDao().fetchAllRegisteredServicesByOwner(userId);
|
||||
|
||||
|
||||
} catch (SQLException sqle) {
|
||||
logger.error("Error fetching registered services for user " + userId , sqle);
|
||||
request.getSession().setAttribute("message", "Error fetching registered services. " +
|
||||
|
@ -65,9 +66,20 @@ public class RegisteredServicesServlet extends HttpServlet {
|
|||
TokenUtils.getRegisteredService(registeredService.getAai_id(),authentication.getAccessTokenValue()));
|
||||
}
|
||||
|
||||
boolean reachedLimit = reachedMaximumNumberOfServices(registeredServices);
|
||||
request.getSession().setAttribute("reachedLimit", reachedLimit);
|
||||
request.getSession().setAttribute("test", "TEST");
|
||||
|
||||
request.getSession().setAttribute("services", serviceResponses);
|
||||
request.getSession().setAttribute("registeredServices", registeredServices);
|
||||
response.setContentType("text/html");
|
||||
request.getRequestDispatcher("./registeredServices.jsp").include(request, response);
|
||||
}
|
||||
|
||||
private boolean reachedMaximumNumberOfServices(List<RegisteredService> registeredServices) {
|
||||
if (registeredServices.size() == 5) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.dnetlib.openaire.usermanagement.utils;
|
|||
import eu.dnetlib.openaire.user.pojos.RegisteredService;
|
||||
import eu.dnetlib.openaire.user.registeredService.RegisteredServiceDao;
|
||||
import eu.dnetlib.openaire.user.registeredService.RegisteredServiceSQL;
|
||||
import org.bouncycastle.util.Integers;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
@ -25,8 +26,10 @@ public class RegisteredServicesUtils {
|
|||
registeredServiceDao.insertRegisteredService(registeredService);
|
||||
}
|
||||
|
||||
public boolean isAuthorized(String userid, String id) throws SQLException {
|
||||
public boolean isAuthorized(String userid, int id) throws SQLException {
|
||||
System.out.println("I AM HERE....");
|
||||
RegisteredService registeredService = registeredServiceDao.fetchRegisteredServiceById(id);
|
||||
System.out.println("....and HERE");
|
||||
System.out.println(registeredService.getAai_id());
|
||||
System.out.println(registeredService.getOwner());
|
||||
if (registeredService.getOwner().equals(userid)) return true;
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
<div class="uk-grid ">
|
||||
<div class="uk-width-1-4@m">
|
||||
<div class="uk-card uk-card-default uk-card-body">
|
||||
<div class="uk-h4">Sidebar title</div>
|
||||
<div class="uk-h4">APIs access</div>
|
||||
<ul class="uk-nav uk-nav-default">
|
||||
<li class=""><a href="./personalToken">Personal token</a></li>
|
||||
<li class=""><a href="./registeredServices">Registered services</a></li>
|
||||
|
@ -92,8 +92,6 @@
|
|||
<input type="hidden" name="serviceId" value="${serviceId}"/>
|
||||
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
|
||||
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
|
||||
<span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
|
||||
<c:remove var="message" scope="session" />
|
||||
<div class="form-group">
|
||||
<span class="msg_first_name_error uk-text-danger uk-text-small uk-float-left" style='${msg_first_name_error_display}'>Please enter a name for your service.</span>
|
||||
<input id="first_name" name="first_name" type="text" placeholder="Name (*)" class="form-control" value=${first_name}></div>
|
||||
|
@ -103,7 +101,7 @@
|
|||
<textarea id="description" name="description" type="textarea" placeholder="Description:" class="form-control uk-textarea" rows="3" value=${description}></textarea>
|
||||
<c:remove var="organization" scope="session" />
|
||||
<div class="uk-width-1-1 uk-grid-margin uk-first-column">
|
||||
<button type="submit" class="uk-button uk-button-default" onclick="">Cancel</button>
|
||||
<button type="submit" class="uk-button uk-button-default" onclick="location.href='../registeredServices'">Cancel</button>
|
||||
<button type="submit" class="uk-button uk-button-primary" onclick="return validate();">Update service</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -54,29 +54,35 @@
|
|||
</div>
|
||||
<!-- user menu -->
|
||||
<div class=uk-navbar-right>
|
||||
<ul class="uk-navbar-nav user_actions">
|
||||
<li><a href="#"> Sign in </a></li>
|
||||
<li>
|
||||
<a class="login uk-icon" aria-expanded="false">
|
||||
<svg height="60" width="60"><circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
||||
<text dy=".4em" font-size="16" text-anchor="middle" x="50%" y="50%"> AK </text></svg>
|
||||
</a>
|
||||
<div class="uk-navbar-dropdown uk-navbar-dropdown-bottom-right" id="userMenu" style="left: 344.433px; top: 100px;">
|
||||
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
||||
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
||||
<ul class="uk-nav uk-navbar-dropdown-nav">
|
||||
<li class=""><a href="./personalToken">Personal token</a></li>
|
||||
<li class=""><a href="./registeredServices">Registered services</a></li>
|
||||
<li class="uk-nav-divider "></li>
|
||||
<li>
|
||||
<a id="logout">Log out</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="uk-navbar-nav user_actions">
|
||||
<c:choose>
|
||||
<c:when test="${not authenticated}">
|
||||
<li><a href="./openid_connect_login"> Sign in </a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li>
|
||||
<a class="login uk-icon" aria-expanded="false">
|
||||
<svg height="60" width="60">
|
||||
<span uk-icon="icon: user; ratio: 2"></span></svg>
|
||||
</a>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<div class="uk-navbar-dropdown uk-navbar-dropdown-bottom-right" id="userMenu" style="left: 344.433px; top: 100px;">
|
||||
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
||||
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
||||
<ul class="uk-nav uk-navbar-dropdown-nav">
|
||||
<li class=""><a href="./personalToken">Personal token</a></li>
|
||||
<li class=""><a href="./registeredServices">Registered services</a></li>
|
||||
<li class="uk-nav-divider "></li>
|
||||
<li>
|
||||
<a href="./openid_logout" id="logout">Log out</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- USER MENU ENDS HERE -->
|
||||
</nav>
|
||||
|
|
|
@ -42,12 +42,18 @@
|
|||
<!-- user menu -->
|
||||
<div class=uk-navbar-right>
|
||||
<ul class="uk-navbar-nav user_actions">
|
||||
<li><a href="#"> Sign in </a></li>
|
||||
<li>
|
||||
<a class="login uk-icon" aria-expanded="false">
|
||||
<svg height="60" width="60"><circle cx="30" cy="30" r="20" stroke-width="2"></circle>
|
||||
<text dy=".4em" font-size="16" text-anchor="middle" x="50%" y="50%"> AK </text></svg>
|
||||
<c:choose>
|
||||
<c:when test="${not authenticated}">
|
||||
<li><a href="./openid_connect_login"> Sign in </a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li>
|
||||
<a class="login uk-icon" aria-expanded="false">
|
||||
<svg height="60" width="60">
|
||||
<span uk-icon="icon: user; ratio: 2"></span></svg>
|
||||
</a>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<div class="uk-navbar-dropdown uk-navbar-dropdown-bottom-right" id="userMenu" style="left: 344.433px; top: 100px;">
|
||||
<div class="uk-navbar-dropdown-grid uk-child-width-1-1 uk-grid uk-grid-stack" uk-grid="">
|
||||
<div class="uk-first-column uk-height-max-medium uk-overflow-auto">
|
||||
|
@ -56,7 +62,7 @@
|
|||
<li class=""><a href="./registeredServices">Registered services</a></li>
|
||||
<li class="uk-nav-divider "></li>
|
||||
<li>
|
||||
<a id="logout">Log out</a>
|
||||
<a href="./openid_logout" id="logout">Log out</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<base href=".">
|
||||
<title>OpenAIRE - Register</title>
|
||||
<title>OpenAIRE - Registered services</title>
|
||||
<script src="./js/jquery.js"></script>
|
||||
<script src="./js/uikit.js"></script>
|
||||
<script src="./js/validation.js"></script>
|
||||
|
@ -88,7 +88,17 @@
|
|||
<!-- CENTER SIDE -->
|
||||
<div class="uk-width-2-3@l uk-width-2-3@m">
|
||||
<h2 class="uk-h2 uk-margin-small-bottom">Registered services</h2>
|
||||
<h5 class="uk-h5">This is the list of all your registered services. You can register up to 5 services.</h5>
|
||||
|
||||
<span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
|
||||
<c:remove var="message" scope="session" />
|
||||
<p><span class="uk-alert-primary uk-text-medium uk-float-left">You can register up to 5 services.</span></p>
|
||||
|
||||
<c:if test="${reachedLimit}">
|
||||
<br>
|
||||
<p><span class="uk-alert-warning uk-text-medium uk-float-left">You have reached the maximum size of allowed registered services.</span></p>
|
||||
<c:remove var="message" scope="session" />
|
||||
<br>
|
||||
</c:if>
|
||||
<div class="middle-box loginscreen animated fadeInDown ">
|
||||
<div class="uk-width-1-1@m uk-width-1-1@s">
|
||||
<div> <span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span> </div>
|
||||
|
@ -168,9 +178,18 @@
|
|||
</ul>
|
||||
</c:if>
|
||||
<div class="uk-text-center">
|
||||
<a class="uk-button uk-button-default uk-button-primary uk-margin-top" href="./registerService">
|
||||
<span class="uk-icon" uk-icon="icon:plus-circle"></span> New service
|
||||
</a>
|
||||
<c:choose>
|
||||
<c:when test="${not reachedLimit}">
|
||||
<a class="uk-button uk-button-default uk-button-primary uk-margin-top" href="./registerService">
|
||||
<span class="uk-icon" uk-icon="icon:plus-circle"></span> New service
|
||||
</a>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="uk-button uk-button-default uk-margin-top" disabled>
|
||||
<span class="uk-icon" uk-icon="icon:plus-circle"> New service</span>
|
||||
</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue