Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
24f81ee7
Commit
24f81ee7
authored
Feb 22, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added user key service
Added post key with json
parent
aece94f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
35 deletions
+143
-35
ProvisionController.java
...in/java/nl/uva/sne/drip/api/rest/ProvisionController.java
+33
-5
UserPublicKeysController.java
...va/nl/uva/sne/drip/api/rest/UserPublicKeysController.java
+43
-20
UserKeyService.java
...main/java/nl/uva/sne/drip/api/service/UserKeyService.java
+67
-0
UserScriptService.java
...n/java/nl/uva/sne/drip/api/service/UserScriptService.java
+0
-10
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/rest/ProvisionController.java
View file @
24f81ee7
...
...
@@ -42,15 +42,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.dao.ToscaDao
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.UserKeyService
;
import
nl.uva.sne.drip.api.service.UserScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
import
nl.uva.sne.drip.commons.types.UserScript
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -69,6 +71,12 @@ public class ProvisionController {
@Autowired
private
ToscaService
toscaService
;
@Autowired
private
UserScriptService
userScriptService
;
@Autowired
private
UserKeyService
userKeysService
;
@Autowired
private
CloudCredentialsDao
cloudCredentialsDao
;
...
...
@@ -120,7 +128,7 @@ public class ProvisionController {
parameters
.
addAll
(
userScripts
);
List
<
Parameter
>
userKeys
=
buildKeysParams
(
pReq
.
getUserKeyID
());
parameters
.
addAll
(
user
Script
s
);
parameters
.
addAll
(
user
Key
s
);
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
...
...
@@ -208,11 +216,31 @@ public class ProvisionController {
}
private
List
<
Parameter
>
buildScriptParams
(
String
userScriptID
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
UserScript
script
=
userScriptService
.
getDao
().
findOne
(
userScriptID
);
if
(
script
==
null
)
{
throw
new
BadRequestException
(
"User script: "
+
userScriptID
+
" was not found"
);
}
List
<
Parameter
>
parameters
=
new
ArrayList
();
Parameter
scriptParameter
=
new
Parameter
();
scriptParameter
.
setName
(
"guiscript"
);
scriptParameter
.
setValue
(
script
.
getContents
());
scriptParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
scriptParameter
);
return
parameters
;
}
private
List
<
Parameter
>
buildKeysParams
(
String
userKeyID
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
LoginKey
key
=
userKeysService
.
get
(
userKeyID
,
LoginKey
.
Type
.
PUBLIC
);
if
(
key
==
null
)
{
throw
new
BadRequestException
(
"User key: "
+
userKeyID
+
" was not found"
);
}
List
<
Parameter
>
parameters
=
new
ArrayList
();
Parameter
keyParameter
=
new
Parameter
();
keyParameter
.
setName
(
"sshkey"
);
keyParameter
.
setValue
(
key
.
getKey
());
keyParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
keyParameter
);
return
parameters
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/rest/UserPublicKeysController.java
View file @
24f81ee7
...
...
@@ -22,7 +22,6 @@ import java.util.List;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -32,9 +31,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
nl.uva.sne.drip.api.dao.UserKeyDao
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.service.UserKeyService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
*
...
...
@@ -46,7 +48,7 @@ import org.springframework.web.bind.annotation.PathVariable;
public
class
UserPublicKeysController
{
@Autowired
private
UserKey
Dao
dao
;
private
UserKey
Service
service
;
// curl -v -X POST -F "file=@.ssh/id_dsa.pub" localhost:8080/drip-api/user_key/upload
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
)
...
...
@@ -64,7 +66,8 @@ public class UserPublicKeysController {
upk
.
setKey
(
key
);
upk
.
setName
(
name
);
upk
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
dao
.
save
(
upk
);
service
.
getDao
().
save
(
upk
);
return
upk
.
getId
();
}
catch
(
IOException
|
IllegalStateException
ex
)
{
...
...
@@ -75,24 +78,38 @@ public class UserPublicKeysController {
}
// curl -H "Content-Type: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/user_key/
// @RequestMapping(method = RequestMethod.POST)
// @RolesAllowed({UserService.USER, UserService.ADMIN})
// public @ResponseBody
// String postConf(LoginKey uk) throws JSONException {
// String name = System.currentTimeMillis() + "_" + uk.getName();
// uk.setName(name);
// dao.save(uk);
// return uk.getId();
// }
@RequestMapping
(
method
=
RequestMethod
.
POST
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
postKey
(
@RequestBody
LoginKey
uk
)
{
LoginKey
.
Type
type
=
uk
.
getType
();
if
(
type
!=
null
&&
type
.
equals
(
LoginKey
.
Type
.
PRIVATE
))
{
throw
new
BadRequestException
(
"Key can't be private"
);
}
if
(
uk
.
getKey
()
==
null
)
{
throw
new
BadRequestException
(
"Key can't be empty"
);
}
String
originalName
=
uk
.
getName
();
if
(
originalName
==
null
)
{
originalName
=
"id.pub"
;
}
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalName
;
uk
.
setName
(
name
);
uk
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
service
.
getDao
().
save
(
uk
);
return
uk
.
getId
();
}
//curl localhost:8080/drip-api/user_key/58a20be263d4a5898835676e
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
LoginKey
get
(
@PathVariable
(
"id"
)
String
id
)
{
LoginKey
key
=
dao
.
findOne
(
id
);
if
(
key
==
null
||
!
key
.
getType
().
equals
(
LoginKey
.
Type
.
PUBLIC
))
{
public
@ResponseBody
LoginKey
get
(
@PathVariable
(
"id"
)
String
id
)
{
LoginKey
key
=
service
.
get
(
id
,
LoginKey
.
Type
.
PUBLIC
);
if
(
key
==
null
)
{
throw
new
NotFoundException
();
}
return
key
;
}
...
...
@@ -101,14 +118,20 @@ public class UserPublicKeysController {
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
List
<
String
>
getIds
()
{
List
<
LoginKey
>
all
=
dao
.
findAll
(
);
List
<
LoginKey
>
all
=
service
.
getAll
(
LoginKey
.
Type
.
PUBLIC
);
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
LoginKey
tr
:
all
)
{
if
(
tr
.
getType
().
equals
(
LoginKey
.
Type
.
PUBLIC
))
{
ids
.
add
(
tr
.
getId
());
}
ids
.
add
(
tr
.
getId
());
}
return
ids
;
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
service
.
delete
(
id
,
LoginKey
.
Type
.
PUBLIC
);
return
"Deleteed: "
+
id
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserKeyService.java
0 → 100644
View file @
24f81ee7
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
nl.uva.sne.drip.api.dao.UserKeyDao
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
*
* @author S. Koulouzis
*/
@Service
public
class
UserKeyService
{
@Autowired
UserKeyDao
dao
;
public
UserKeyDao
getDao
()
{
return
dao
;
}
public
List
<
LoginKey
>
getAll
(
LoginKey
.
Type
type
)
{
List
<
LoginKey
>
all
=
getDao
().
findAll
();
if
(
all
!=
null
)
{
List
<
LoginKey
>
allPublic
=
new
ArrayList
<>();
for
(
LoginKey
tr
:
all
)
{
if
(
tr
.
getType
()
!=
null
&&
tr
.
getType
().
equals
(
LoginKey
.
Type
.
PUBLIC
))
{
allPublic
.
add
(
tr
);
}
}
return
allPublic
;
}
return
null
;
}
public
LoginKey
get
(
String
id
,
LoginKey
.
Type
type
)
{
LoginKey
key
=
getDao
().
findOne
(
id
);
if
(
key
.
getType
().
equals
(
type
))
{
return
key
;
}
return
null
;
}
public
void
delete
(
String
id
,
LoginKey
.
Type
type
)
{
LoginKey
k
=
get
(
id
,
type
);
if
(
k
!=
null
)
{
getDao
().
delete
(
k
);
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserScriptService.java
View file @
24f81ee7
...
...
@@ -15,18 +15,8 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.api.dao.UserDao
;
import
nl.uva.sne.drip.api.dao.UserScriptDao
;
import
nl.uva.sne.drip.commons.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Service
;
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment