KON-14 - Kontakte-Modulzuordnung Suche
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java b/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java index 3dbfb09..65ba925 100644 --- a/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java +++ b/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java
@@ -1,12 +1,32 @@ +/* + ******************************************************************************* + * Copyright (c) 2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************* +*/ package org.eclipse.openk.contactbasedata.api; +import org.eclipse.openk.contactbasedata.viewmodel.UserModule; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; +import java.util.List; + @FeignClient(name = "${services.authNAuth.name}") public interface AuthNAuthApi { @GetMapping(value= "/portal/rest/beservice/checkAuth") feign.Response isTokenValid(@RequestHeader("Authorization") String token ); + + @GetMapping(value= "/portal/rest/beservice/userModulesForUser") + List<UserModule> getUserModulesForUser(@RequestHeader("Authorization") String token ); }
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java b/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java index 766d6d8..23b1a26 100644 --- a/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java +++ b/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java
@@ -76,8 +76,8 @@ token.getRealmAccess().getRoles().stream() .forEach( x -> authorities.add(new SimpleGrantedAuthority("ROLE_"+x.toUpperCase()))); - UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(token.getName(), null, - authorities); + UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(token.getName(), null, authorities); + auth.setDetails(bearerTkn); context.setAuthentication(auth);
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java new file mode 100644 index 0000000..eced874 --- /dev/null +++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java
@@ -0,0 +1,48 @@ +/* + ******************************************************************************* + * Copyright (c) 2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************* + */ +package org.eclipse.openk.contactbasedata.controller; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.extern.log4j.Log4j2; +import org.eclipse.openk.contactbasedata.service.UserModuleService; +import org.eclipse.openk.contactbasedata.viewmodel.UserModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Log4j2 +@RestController +@RequestMapping("/user-modules") +public class UserModuleController { + + @Autowired + private UserModuleService userModuleService; + + @ApiOperation(value = "Ermitteln der UserModules vom Auth'n'Auth-Service") + @ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")}) + @GetMapping + public List<UserModule> getUserModules() { + return userModuleService.getUserModules(); + } + + + + +}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java new file mode 100644 index 0000000..b0c9dc4 --- /dev/null +++ b/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java
@@ -0,0 +1,34 @@ +/* + ******************************************************************************* + * Copyright (c) 2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************* +*/ +package org.eclipse.openk.contactbasedata.service; + +import org.eclipse.openk.contactbasedata.api.AuthNAuthApi; +import org.eclipse.openk.contactbasedata.viewmodel.UserModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class UserModuleService { + @Autowired + private AuthNAuthApi authNAuthApi; + + public List<UserModule> getUserModules() { + String bearerToken = (String)SecurityContextHolder.getContext().getAuthentication().getDetails(); + return authNAuthApi.getUserModulesForUser(bearerToken); + } +}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java new file mode 100644 index 0000000..7f8fd82 --- /dev/null +++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java
@@ -0,0 +1,23 @@ +/* + ******************************************************************************* + * Copyright (c) 2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************* +*/ +package org.eclipse.openk.contactbasedata.viewmodel; + +import lombok.Data; + +@Data +public class UserModule { + private String name; + private String color; +}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a75f8c6..038a215 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml
@@ -73,6 +73,24 @@ jwt: tokenHeader: Authorization + useStaticJwt: false + staticJwt: eyJhbGciOiJSUzI1NiIsIn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ut3s-94ovNYIEn29nzXm2W1ldoXJEq03F880jlysQ5zlRvGF7eXEEpFfI2URyyNQ2UWh0Ssfq-gOAt2pbF1u6prA5RfvUmZ3v1eu21YLGZtgqPqxb1l6odyH3ip15j_HdgnTeo52ymxuRUj65Mskme3V5ev2DitHI9vZgnpV8Idhb4TTWliBeGCOMfDFCg + +server: + port: 9155 + +cors: + allowedOrigins: http://localhost:8080 + corsEnabled: true + + +--- + +spring: + profiles: devserver-unsecure + +jwt: + tokenHeader: Authorization useStaticJwt: true staticJwt: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJIYlI3Z2pobmE2eXJRZnZJTWhUSV9tY2g3ZmtTQWVFX3hLTjBhZVl0bjdjIn0.eyJqdGkiOiI5MGI0NGFkOC1iYjlmLTQ1MzktYTQwYy0yYjQyZTNkNjNiOGEiLCJleHAiOjE1Nzg2NTU3OTUsIm5iZiI6MCwiaWF0IjoxNTc4NjU1NDk1LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvRWxvZ2Jvb2siLCJhdWQiOiJlbG9nYm9vay1iYWNrZW5kIiwic3ViIjoiODYyNjY5NmYtZjFhMi00ZGI1LTkyZWYtZTlhMjQ2Njg1YTU0IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZWxvZ2Jvb2stYmFja2VuZCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjJmMWIzODE5LWZjNjQtNDEzNC1iNWQxLWY3ZWY4NzU5NDBkNCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiKiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsia29uLWFkbWluIiwia29uLXdyaXRlciIsImtvbi1hY2Nlc3MiLCJrb24tcmVhZGVyIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnt9LCJuYW1lIjoiVGVzdGVyRmlyc3RuYW1lX3J3YSBUZXN0ZXJMYXN0b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