Skip to content
Snippets Groups Projects
Commit 846e85a8 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

use new user-endpoint + fixed indentation + fixed bug 500 on get /user

parent eaf9b009
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ hbp:
# use-current-uri: false # For production server
# pre-established-redirect-uri: https://mip.humanbrainproject.eu/services/login/hbp # For production server
resource:
userInfoUri: https://services.humanbrainproject.eu/oidc/v0/api/user/me
userInfoUri: https://services.humanbrainproject.eu/oidc/userinfo
logging:
level:
......
......@@ -126,16 +126,26 @@ public static void main(String[] args) {
*/
public synchronized User getUser(Principal principal) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User user = (User) session
.createQuery("from User where username= :username")
.setString("username", principal.getName())
.uniqueResult();
if (user == null) {
user = new User(getUserInfos());
session.save(user);
}
session.getTransaction().commit();
User user = null;
try {
session.beginTransaction();
user = (User) session
.createQuery("from User where username= :username")
.setString("username", principal.getName())
.uniqueResult();
if (user == null) {
user = new User(getUserInfos());
session.save(user);
}
session.getTransaction().commit();
} catch (Exception e)
{
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
}
}
return user;
}
......
......@@ -93,7 +93,8 @@ public class ArticlesApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<List<Article>>(HttpStatus.OK).ok(articles);
}
......@@ -129,7 +130,8 @@ public class ArticlesApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Void>(HttpStatus.OK);
}
......@@ -156,7 +158,8 @@ public class ArticlesApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Article>(HttpStatus.OK).ok(article);
}
......@@ -185,7 +188,8 @@ public class ArticlesApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Void>(HttpStatus.OK);
}
......
......@@ -45,7 +45,8 @@ public class DatasetsApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Dataset>(HttpStatus.OK).ok(dataset);
}
......
......@@ -43,7 +43,8 @@ public class GroupsApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Group>(HttpStatus.OK).ok(group);
}
......
......@@ -127,7 +127,8 @@ public class ModelsApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Model>(HttpStatus.OK).ok(model);
}
......@@ -203,7 +204,8 @@ public class ModelsApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
}
return new ResponseEntity<Model>(HttpStatus.OK).ok(model);
......@@ -233,7 +235,8 @@ public class ModelsApi {
if(session.getTransaction() != null)
{
session.getTransaction().rollback();
} }
}
}
return new ResponseEntity<Void>(HttpStatus.OK);
}
......
......@@ -47,34 +47,35 @@ public class User {
}
public User(String userInfo) {
Pattern p;
Matcher m;
p = Pattern.compile("username=([\\w ]+)");
p = Pattern.compile("preferred_username=([\\w ]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.username = m.group(1);
}
p = Pattern.compile("displayName=([\\w ]+)");
p = Pattern.compile("name=([\\w ]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.fullname = m.group(1);
}
p = Pattern.compile("givenName=([\\w ]+)");
p = Pattern.compile("given_name=([\\w ]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.firstname = m.group(1);
}
p = Pattern.compile("familyName=([\\w ]+)");
p = Pattern.compile("family_name=([\\w ]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.lastname = m.group(1);
}
p = Pattern.compile("value=([\\w.]+@[\\w.]+)");
p = Pattern.compile("email=([\\w.]+@[\\w.]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.email = m.group(1);
......@@ -96,10 +97,10 @@ public class User {
this.team = m.group(1);
}
p = Pattern.compile("subprojects=([A-Za-z0-9\\[\\] ]+)");
p = Pattern.compile("picture=([\\w.:/ ]+)");
m = p.matcher(userInfo);
if (m.find()) {
this.team += m.group(1);
this.picture = m.group(1);
}
if (this.picture == null || this.picture.isEmpty()) {
......
......@@ -27,7 +27,7 @@
<property name="tokenServices">
<bean class="org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices">
<constructor-arg name="clientId" value="996f97c5-a3ca-460e-b18b-00df3e2be89a" />
<constructor-arg name="userInfoEndpointUrl" value="https://services.humanbrainproject.eu/oidc/v0/api/user/me" />
<constructor-arg name="userInfoEndpointUrl" value="https://services.humanbrainproject.eu/oidc/userinfo" />
</bean>
</property>
</bean>
......
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