Search in sources :

Example 1 with IOAuthProvider

use of org.eclipse.vorto.repository.oauth.IOAuthProvider in project vorto by eclipse.

the class OAuthProvider method from.

public static OAuthProvider from(IOAuthProvider source) {
    OAuthProvider result = new OAuthProvider();
    result.setId(source.getId());
    result.setLabel(source.getLabel());
    if (source.getWebflowConfiguration().isPresent()) {
        IOAuthFlowConfiguration config = source.getWebflowConfiguration().get();
        result.setLogoHref(config.getLogoHref());
        result.setLoginUrl(config.getFilterProcessingUrl());
    /*
      Assigning the Bosch ID icon to the non-webflow providers, because there will only be the two
      Suite OAuth versions in there for now (actually "merged" into one for presentational
      purposes).
       */
    } else {
        if (source.getLabel().equals(BOSCH_SUITE_OAUTH_LABEL)) {
            result.setLogoHref("webjars/repository-web/dist/images/bosch-social.png");
        }
    }
    return result;
}
Also used : IOAuthFlowConfiguration(org.eclipse.vorto.repository.oauth.IOAuthFlowConfiguration) IOAuthProvider(org.eclipse.vorto.repository.oauth.IOAuthProvider)

Example 2 with IOAuthProvider

use of org.eclipse.vorto.repository.oauth.IOAuthProvider in project vorto by eclipse.

the class HomeController method getUser.

@ApiOperation(value = "Returns the currently logged in User")
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 200, message = "OK") })
@RequestMapping(value = { "/user", "/me" }, method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> getUser(Principal user, final HttpServletRequest request) throws ParseException {
    Map<String, Object> map = new LinkedHashMap<>();
    if (user == null)
        return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED);
    IOAuthProvider provider = registry.getByPrincipal(user);
    OAuthUser oauthUser = provider.createUser((OAuth2Authentication) user);
    User userAccount = accountService.getUser(oauthUser.getUserId());
    Date updateCutoff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(updateDate);
    map.put("name", oauthUser.getUserId());
    if (Objects.nonNull(userAccount)) {
        map.put("subject", userAccount.getSubject());
    }
    map.put("displayName", oauthUser.getDisplayName());
    map.put("isRegistered", Boolean.toString(userAccount != null));
    map.put("roles", oauthUser.getRoles());
    map.put("needUpdate", Boolean.toString(needUpdate(userAccount, updateCutoff)));
    map.put("logOutUrl", provider.getWebflowConfiguration().get().getLogoutUrl(request));
    map.put("provider", new OAuthProvider(provider.getId(), provider.getLabel(), provider.getWebflowConfiguration().get()));
    map.put("sysadmin", userAccount == null ? false : userRepositoryRoleService.isSysadmin(userAccount));
    return new ResponseEntity<>(map, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) OAuthUser(org.eclipse.vorto.repository.oauth.OAuthUser) User(org.eclipse.vorto.repository.domain.User) OAuthUser(org.eclipse.vorto.repository.oauth.OAuthUser) OAuthProvider(org.eclipse.vorto.repository.web.oauth.OAuthProvider) IOAuthProvider(org.eclipse.vorto.repository.oauth.IOAuthProvider) SimpleDateFormat(java.text.SimpleDateFormat) IOAuthProvider(org.eclipse.vorto.repository.oauth.IOAuthProvider) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IOAuthProvider (org.eclipse.vorto.repository.oauth.IOAuthProvider)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 SimpleDateFormat (java.text.SimpleDateFormat)1 User (org.eclipse.vorto.repository.domain.User)1 IOAuthFlowConfiguration (org.eclipse.vorto.repository.oauth.IOAuthFlowConfiguration)1 OAuthUser (org.eclipse.vorto.repository.oauth.OAuthUser)1 OAuthProvider (org.eclipse.vorto.repository.web.oauth.OAuthProvider)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1