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
b5b2a867
Commit
b5b2a867
authored
Mar 08, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented user register API v0
parent
bcffffd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
UserController0.java
...ain/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
+76
-0
Register.java
.../main/java/nl/uva/sne/drip/commons/v0/types/Register.java
+62
-0
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
0 → 100644
View file @
b5b2a867
/*
* 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
.
v0
.
rest
;
import
nl.uva.sne.drip.api.v1.rest.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.exception.PasswordNullException
;
import
nl.uva.sne.drip.api.exception.UserExistsException
;
import
nl.uva.sne.drip.api.exception.UserNotFoundException
;
import
nl.uva.sne.drip.api.exception.UserNullException
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.PathVariable
;
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.service.UserService
;
import
nl.uva.sne.drip.commons.v0.types.Register
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for handling user accounts
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/manager/v0.0/switch/account/"
)
@Component
public
class
UserController0
{
@Autowired
private
UserService
service
;
@RequestMapping
(
value
=
"/register"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
ADMIN
})
public
@ResponseBody
String
register
(
@RequestBody
Register
register
)
{
if
(
register
.
getUser
()
==
null
)
{
throw
new
UserNullException
();
}
if
(
register
.
getPwd
()
==
null
)
{
throw
new
PasswordNullException
();
}
UserDetails
registeredUser
=
service
.
loadUserByUsername
(
register
.
getUser
());
if
(
registeredUser
!=
null
)
{
throw
new
UserExistsException
(
"Username "
+
register
.
getUser
()
+
" is used"
);
}
User
user
=
new
User
();
user
.
setUsername
(
register
.
getUser
());
user
.
setPassword
(
new
BCryptPasswordEncoder
().
encode
(
register
.
getPwd
()));
service
.
getDao
().
save
(
user
);
return
"Success: "
+
user
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/Register.java
0 → 100644
View file @
b5b2a867
/*
* 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
.
commons
.
v0
.
types
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAttribute
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
*
* @author S. Koulouzis
*/
@XmlRootElement
public
class
Register
{
private
String
user
;
private
String
pwd
;
/**
* @return the user
*/
public
String
getUser
()
{
return
user
;
}
/**
* @param user the user to set
*/
public
void
setUser
(
String
user
)
{
this
.
user
=
user
;
}
/**
* @return the pwd
*/
public
String
getPwd
()
{
return
pwd
;
}
/**
* @param pwd the pwd to set
*/
public
void
setPwd
(
String
pwd
)
{
this
.
pwd
=
pwd
;
}
}
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