Project

General

Profile

« Previous | Next » 

Revision 60486

latest and gratest from trunk

View differences:

modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/utils/AuthorizationService.java
6 6
public class AuthorizationService {
7 7

  
8 8
    public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
9
    public final String ANONYMOUS_USER = "ROLE_ANONYMOUS";
10
    public final String REGISTERED_USER = "REGISTERED_USER";
9 11

  
10
    private String mapType(String type) {
12
    private String mapType(String type, boolean communityMap) {
11 13
        if(type.equals("organization")) {
12 14
            type = "institution";
13
        }
14
        if(type.equals("ri")) {
15
        } else if(type.equals("ri") && communityMap) {
15 16
            type = "community";
16 17
        }
17 18
        return type;
......
22 23
     *
23 24
     * */
24 25
    public String curator(String type) {
25
        return "CURATOR_" + mapType(type).toUpperCase();
26
        return "CURATOR_" + mapType(type, true).toUpperCase();
26 27
    }
27 28

  
28 29
    /**
......
31 32
     * Id = EE, EGI, etc
32 33
     * */
33 34
    public String manager(String type, String id) {
34
        return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
35
        return mapType(type, true).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
35 36
    }
36 37

  
37 38
    /**
38
     * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
39
     * Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
39 40
     *
40 41
     * Id = EE, EGI, etc
41 42
     * */
42 43
    public String member(String type, String id) {
43
        return mapType(type).toUpperCase() + "_" + id.toUpperCase();
44
        return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
44 45
    }
45 46

  
46 47
    public boolean isCommunity(String type) {
47
        return mapType(type).equals("community");
48
        return mapType(type, false).equals("community");
48 49
    }
49 50
}
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegistryCalls.java
29 29
    public JsonUtils jsonUtils;
30 30

  
31 31

  
32
    private String mapType(String type) {
32
    private String mapType(String type, boolean communityMap) {
33 33
        if(type.equals("organization")) {
34 34
            type = "institution";
35
        }
36
        if(type.equals("ri")) {
35
        } else if(type.equals("ri") && communityMap) {
37 36
            type = "community";
38 37
        }
39 38
        return type;
......
62 61
        params.put("coid", coid);
63 62
        params.put("mail", email);
64 63
        JsonElement response = httpUtils.get("co_people.json", params);
65
        return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
64
        if(response != null) {
65
            JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray();
66
            if(coPeople.size() > 0) {
67
                return coPeople.get(0).getAsJsonObject().get("Id").getAsInt();
68
            }
69
        }
70
        return null;
66 71
    }
67 72

  
68 73
    /**
......
102 107
    }
103 108

  
104 109
    /**
110
     * 4. Get a couId by name
111
     *
112
     * @param name
113
     * @return
114
     */
115
    public Integer getCouId(String name) {
116
        JsonArray cous = getCous();
117
        Integer couId = null;
118
        for (JsonElement cou : cous) {
119
            if (cou.getAsJsonObject().get("Name").getAsString().equals(name)) {
120
                couId = cou.getAsJsonObject().get("Id").getAsInt();
121
            }
122
        }
123
        return couId;
124
    }
125

  
126
    /**
105 127
     * 4. Get a couId by type.id
106 128
     *
107 129
     * @param type
......
109 131
     * @return
110 132
     */
111 133
    public Integer getCouId(String type, String id) {
134
        return getCouId(type, id, true);
135
    }
136

  
137

  
138
    /**
139
     * 4. Get a couId by type.id without mapping type
140
     *
141
     * @param type
142
     * @param id
143
     * @return
144
     */
145
    public Integer getCouId(String type, String id, boolean communityMap) {
112 146
        JsonArray cous = getCous();
113 147
        Integer couId = null;
114 148
        for (JsonElement cou : cous) {
115
            if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type) + "." + id)) {
149
            if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type, communityMap) + "." + id)) {
116 150
                couId = cou.getAsJsonObject().get("Id").getAsInt();
117 151
            }
118 152
        }
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java
120 120
    @Consumes(MediaType.APPLICATION_JSON)
121 121
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
122 122
    public Response createRole(@RequestBody Role role) {
123
        if(calls.getCouId(role.getName()) == null) {
123 124
        calls.createRole(role);
124 125
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
126
        } else {
127
            return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("Role has already existed").toString()).type(MediaType.APPLICATION_JSON).build();
128
        }
125 129
    }
126 130

  
127 131
    /**
......
162 166
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
163 167
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
164 168
    public Response inviteMember(@PathParam("type") String type, @PathParam("id") String id, @RequestBody String body) {
165
        Integer couId = calls.getCouId(type, id);
169
        Integer couId = calls.getCouId(type, id, false);
166 170
        if (couId != null) {
167 171
            JsonObject details = new JsonParser().parse(body).getAsJsonObject();
168 172
            JsonObject email = details.get("email").getAsJsonObject();
......
224 228
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
225 229
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
226 230
    public Response cancelMemberInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
227
        Integer couId = calls.getCouId(type, id);
231
        Integer couId = calls.getCouId(type, id, false);
228 232
        if (couId != null) {
229 233
            verificationUtils.deleteMemberVerifications(email, type, id);
230 234
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Invitations have been deleted").toString()).type(MediaType.APPLICATION_JSON).build();
......
360 364
            if (coPersonId != null) {
361 365
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
362 366
                    if (verification.getVerificationCode().equals(code)) {
363
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
367
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
364 368
                        if (couId != null) {
365 369
                            Integer role = calls.getRoleId(coPersonId, couId);
366 370
                            calls.assignMemberRole(coPersonId, couId, role);
......
429 433
            id, @PathParam("email") String email) {
430 434
        Integer coPersonId = calls.getCoPersonIdByEmail(email);
431 435
        if (coPersonId != null) {
432
            Integer couId = calls.getCouId(type, id);
436
            Integer couId = calls.getCouId(type, id, false);
433 437
            Integer role = null;
434 438
            if(couId != null) {
435 439
                role = calls.getRoleId(coPersonId, couId);
......
461 465
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
462 466
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
463 467
    public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
464
        Integer couId = calls.getCouId(type, id);
468
        Integer couId = calls.getCouId(type, id,false);
465 469
        if(couId != null) {
466 470
            JsonArray members = calls.getUserNamesByCouId(couId, false);
467 471
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
......
479 483
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
480 484
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
481 485
    public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
482
        Integer couId = calls.getCouId(type, id);
486
        Integer couId = calls.getCouId(type, id, false);
483 487
        if(couId != null) {
484 488
            JsonArray members = calls.getUserEmailByCouId(couId, false);
485 489
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
......
495 499
    @GET
496 500
    @Produces(MediaType.APPLICATION_JSON)
497 501
    public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
498
        Integer couId = calls.getCouId(type, id);
502
        Integer couId = calls.getCouId(type, id, false);
499 503
        int count = 0;
500 504
        if(couId != null) {
501 505
            count = calls.getUserNamesByCouId(couId, false).size();
modules/dnet-openaire-users/branches/prod/src/main/webapp/registerService.jsp
88 88
                        </div>
89 89
                        <div class="uk-margin-medium-top">
90 90
                            <label class="uk-form-label uk-text-bold">Security level</label>
91
                            <div class="uk-margin">Security level hint</div>
91
                            <div id="security-hint" class="uk-margin"></div>
92 92
                            <div class="uk-margin-small-top">
93 93
                                <span class="uk-margin-small-right">
94 94
                                    <input id="basic" class="uk-radio uk-margin-small-right" type="radio"
......
220 220
    function checkRadio() {
221 221
        var securityLevel = $('input[type=radio][name=security_level]:checked').val();
222 222
        if(securityLevel === 'basic') {
223
            $("#security-hint").html('Register your service to get a client id and a client secret. Use the client id and secret to make your requests. <a href="https://develop.openaire.eu/basic.html" target="_blank">Read more...</a>');
223 224
            $("#public-key").hide();
224 225
        } else {
226
            $("#security-hint").html('Register your service to get a client id. Declare your public key and instead of using the client secret to make a request, send a client assertion (JWT) signed with your private key. <a href="https://develop.openaire.eu/advanced.html" target="_blank">Read more...</a>');
225 227
            var keyType = $('input[type=radio][name=key_type]:checked').val();
226 228
            $("#public-key").show();
227 229
            if (keyType === 'uri') {
......
309 311
        }
310 312
        return false;
311 313
    }
312
</script>
314
</script>
modules/dnet-openaire-users/branches/prod/src/main/webapp/register.jsp
69 69
                                            <span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
70 70
                                            <c:remove var="message" scope="session" />
71 71
                                            <div class="form-group">
72
                                                <span class="msg_first_name_error uk-text-danger uk-text-small uk-float-left" style='${msg_first_name_error_display}'>Please enter your first name.</span>
72
                                                <span class="msg_first_name_error uk-text-danger uk-text-small uk-float-left" style="display:none;">Please enter your first name.</span>
73 73
                                                <input id="first_name" name="first_name" type="text" placeholder="First name (*)" class="form-control" value=${first_name}></div>
74 74
                                                <c:remove var="msg_first_name_error_display" scope="session" />
75 75
                                                <c:remove var="first_name" scope="session" />
76 76
                                            <div class="form-group">
77
                                                <span class="msg_last_name_error uk-text-danger uk-text-small uk-float-left" style="${msg_last_name_error_display}">Please enter your last name.</span>
77
                                                <span class="msg_last_name_error uk-text-danger uk-text-small uk-float-left" style="display:none;">Please enter your last name.</span>
78 78
                                                <input id="last_name" name="last_name" type="text" placeholder="Last name (*)" class="form-control" value=${last_name}></div>
79 79
                                                <c:remove var="msg_last_name_error_display" scope="session" />
80 80
                                                <c:remove var="last_name" scope="session" />
......
96 96
                                                <input id="username" name="username" type="text" placeholder="Username (*)" class="form-control" value=${username}></div>
97 97
                                                <c:remove var="username" scope="session" />
98 98
                                            <div class="form-group">
99
                                                <span class="msg_email_error uk-text-danger uk-text-small uk-float-left" style="${msg_email_error_display}">Please enter your email.</span>
100
                                                <span class="msg_email_validation_error uk-text-danger uk-text-small uk-float-left" style="${msg_email_validation_error_display}">Please enter a valid email.</span>
101
                                                <span class="msg_email_conf_error uk-text-danger uk-text-small uk-float-left" style="${msg_email_conf_error_display}">These emails don't match.</span>
99
                                                <span class="msg_email_error uk-text-danger uk-text-small uk-float-left" style="display:none;">Please enter your email.</span>
100
                                                <span class="msg_email_validation_error uk-text-danger uk-text-small uk-float-left" style="display:none;">Please enter a valid email.</span>
101
                                                <span class="msg_email_conf_error uk-text-danger uk-text-small uk-float-left" style="display:none;">These emails don't match.</span>
102 102
                                                <span id="email_server_error" class="uk-text-danger uk-text-small uk-float-left">${email_message}</span>
103 103
                                                <c:remove var="msg_email_conf_error_display" scope="session" />
104 104
                                                <c:remove var="msg_email_validation_error_display" scope="session" />
......
110 110
                                                <input id="email_conf" name="email_conf" type="text" placeholder="Confirm email (*)" class="form-control" value=${email_conf}></div>
111 111
                                                <c:remove var="email_conf" scope="session" />
112 112
                                            <div class="form-group">
113
                                                <span class="msg_password_error uk-text-danger uk-text-small uk-float-left" style="${msg_password_error_display}">Please enter your password.</span>
114
                                                <span class="msg_pass_conf_error uk-text-danger uk-text-small uk-float-left" style="${msg_pass_conf_error_display}">These passwords don't match.</span>
113
                                                <span class="msg_password_error uk-text-danger uk-text-small uk-float-left" style="display:none;">Please enter your password.</span>
114
                                                <span class="msg_pass_conf_error uk-text-danger uk-text-small uk-float-left" style="display:none;">These passwords don't match.</span>
115 115
                                                <p>
116 116
                                                <span class="msg_please_add uk-text-danger uk-text-small uk-float-left" style="display:none">Please add: &nbsp</span></p>
117 117
                                                <span class="msg_lowercase_letter uk-text-danger uk-text-small uk-float-left" style="display:none">A lowercase letter. &nbsp</span>
......
119 119
                                                <span class="msg_number uk-text-danger uk-text-small uk-float-left" style="display:none">A number. &nbsp</span>
120 120
                                                <span class="msg_lenght uk-text-danger uk-text-small uk-float-left" style="display:none">Minimum 6 characters. &nbsp</span>
121 121
                                                <p><span class="msg_whitespace uk-text-danger uk-text-small uk-float-left" style="display:none">No white space allowed. &nbsp</span></p>
122
                                                <span class="msg_invalid_password  uk-text-danger uk-text-small uk-float-left" style="${msg_invalid_password_display}">The password must
122
                                                <span class="msg_invalid_password  uk-text-danger uk-text-small uk-float-left" style="display:none;">The password must
123 123
                                                 contain a lowercase letter, a capital (uppercase) letter, a number and must be at least 6 characters long. White space character is not allowed.</span>
124 124
                                                <input id="password" name="password" type="password" placeholder="Password" class="form-control"></div>
125 125
                                                <c:remove var="msg_pass_conf_error_display" scope="session" />
......
129 129
                                                <input id="password_conf" name="password_conf" type="password" placeholder="Confirm password" class="form-control"></div>
130 130
                                            <div class="uk-margin uk-grid-small uk-child-width-auto uk-grid uk-text-left uk-grid-stack" uk-grid="">
131 131
                                                <div class="uk-width-1-1 uk-text-meta uk-text-danger uk-first-column">(*) Required fields</div>
132
                                                <span class="uk-text-danger uk-text-small recaptcha_error" style="${recaptcha_error_display}">You missed the reCAPTCHA validation!</span>
132
                                                <span class="uk-text-danger uk-text-small recaptcha_error" style="display:none;">You missed the reCAPTCHA validation!</span>
133 133
                                                <c:remove var="recaptcha_error_display" scope="session" />
134 134
                                                <div class="g-recaptcha" data-sitekey=${applicationScope.sitekey}></div>
135 135
                                                <div class="uk-width-1-1 uk-grid-margin uk-first-column">
modules/dnet-openaire-users/branches/prod/src/main/webapp/registeredServices.jsp
45 45
                            <div class="uk-text-danger uk-margin-small-bottom">${message}</div>
46 46
                            <c:remove var="message" scope="session"/>
47 47
                        </c:if>
48
                        <div class="uk-alert-primary uk-flex uk-flex-middle">
49
                            <span uk-icon="info"></span>
50
                            <span class="uk-margin-small-left">You can register up to 5 services.</span>
51
                        </div>
52
                        <c:if test="${reachedLimit}">
53
                            <div class="uk-alert-warning uk-flex uk-flex-middle uk-margin-small-top">
54
                                <span uk-icon="warning"></span>
55
                                <span class="uk-margin-small-left">You have reached the maximum size of allowed registered services.</span>
56
                            </div>
57
                        </c:if>
48

  
49

  
58 50
                    </div>
59 51
                    <div class="uk-text-center uk-width-auto@m">
60 52
                        <c:choose>
......
74 66
                        <c:remove var="reachedLimit" scope="session"/>
75 67
                    </div>
76 68
                </div>
77
                <div class="uk-margin-medium-top">
69
                <div class="uk-margin-top">
70
                    <div class="uk-alert-primary uk-alert uk-margin-top-remove uk-flex uk-flex-middle">
71
                        <span uk-icon="info"></span>
72
                        <span class="uk-margin-small-left">You can register up to 5 services.
73
                        For more information please read the <a href="https://develop.openaire.eu/authentication.html" target="_blank">OpenAIRE API Authentication documentation</a>.</span>
74
                    </div>
75
                    <c:if test="${reachedLimit}">
76
                        <div class="uk-alert-warning uk-flex uk-flex-middle uk-margin-small-top">
77
                            <span uk-icon="warning"></span>
78
                            <span class="uk-margin-small-left">You have reached the maximum size of allowed registered services.</span>
79
                        </div>
80
                    </c:if>
78 81
                    <c:if test="${empty registeredServices && showEmptyList}">
79 82
                        <div class="uk-text-center">You have not registered any service yet!</div>
80 83
                    </c:if>
......
83 86
                            <li>
84 87
                                <div class="uk-grid uk-child-width-1-4 uk-text-muted" uk-grid>
85 88
                                    <div>Name</div>
86
                                    <div>Service Id</div>
89
                                    <div>Client Id</div>
87 90
                                    <div>Creation Date</div>
88 91
                                    <div>Actions</div>
89 92
                                </div>
......
140 143
                                <li id="details${registeredService.id}" hidden="hidden">
141 144
                                    <div class="uk-alert">
142 145
                                        <p><span class="uk-text-primary">Name:</span> ${services[key].clientName}</p>
143
                                        <p><span class="uk-text-primary">Service Id:</span> ${services[key].clientId}</p>
146
                                        <p><span class="uk-text-primary">Client Id:</span> ${services[key].clientId}</p>
144 147
                                        <p><span class="uk-text-primary">Scope:</span> openid</p>
145 148
                                        <p><span class="uk-text-primary">Grant type:</span> client credentials</p>
146 149
                                        <c:choose>
modules/dnet-openaire-users/branches/prod/src/main/webapp/overview.jsp
44 44
            <div class="uk-margin-top">
45 45
                The OpenAIRE APIs can be accessed over HTTPS both by authenticated and unauthenticated requests.
46 46
                To achieve <b>better rate limits</b> you need to make <b>authenticated requests</b>.
47
                <p><span uk-icon="icon:info"></span> For more information please read the <a href="https://develop.openaire.eu/authentication.html" target="_blank">documentation</a>.</p>
47
            </div>
48 48

  
49
            <div class="uk-container uk-container-small uk-margin-top">
50

  
51
                <div class="uk-alert-primary uk-alert uk-margin-top-remove">
52
                    <span uk-icon="info"></span>
53
                    <span class="uk-margin-small-left">For more information please read the <a href="https://develop.openaire.eu/authentication.html" target="_blank">OpenAIRE API Authentication documentation</a>.</span>
49 54
            </div>
50
            <div class="uk-container uk-container-small uk-margin-top">
55

  
51 56
                <div class="uk-grid uk-child-width-1-2@m uk-child-width-1-1" uk-grid>
52 57
                    <div>
53 58
                        <div class="uk-card uk-card-default uk-card-body">
......
62 67
                        </div>
63 68
                    </div>
64 69
                </div>
70

  
65 71
            </div>
66 72
            <!-- END OF CENTER SIDE -->
67 73
        </div>
modules/dnet-openaire-users/branches/prod/src/main/webapp/personal.jsp
30 30
                console.error('unable to copy text');
31 31
            }
32 32
        }
33
        $(document).ready(function () {
34
            document.addEventListener('copy', (event) => {
35
                const selection = document.getSelection();
36
                event.clipboardData.setData('text/plain', selection.toString().trim());
37
                event.preventDefault();
38
            });
39
        });
33 40
    </script>
34 41
    <link rel="stylesheet" style="text/css" href="./css/theme.css">
35 42
    <link rel="stylesheet" style="text/css" href="./css/custom.css">

Also available in: Unified diff