Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,26 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (authToken != null) {
authToken = authToken.replaceAll("Bearer ", "");
}

// For Azure AD authentication
String accessToken = request.getHeader("X-MS-TOKEN-AAD-ACCESS-TOKEN");

LOGGER.info("IdToken: " + request.getHeader("X-MS-TOKEN-AAD-ID-TOKEN"));
LOGGER.info("AccessToken: " + request.getHeader("X-MS-TOKEN-AAD-ACCESS-TOKEN"));
LOGGER.info("UserId: " + request.getHeader("X-MS-CLIENT-PRINCIPAL-ID"));
LOGGER.info("UserName: " + request.getHeader("X-MS-CLIENT-PRINCIPAL-NAME"));

//check is ignore
if (!authUtil.isIgnore(requestURI)) {
//invoked by API client
if (!StringUtils.isEmpty(accessToken)) {
if (authTokenService.checkAADToken(accessToken)) {
return true;
} else {
response.sendError(HttpStatus.UNAUTHORIZED.value(), "unauthorized, error authorization code");
}
}

//invoke by client
if (!StringUtils.isEmpty(authToken)) {
if (authTokenService.checkAuthToken(authToken)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.hydralab.center.service;

import com.microsoft.hydralab.center.repository.AuthTokenRepository;
import com.microsoft.hydralab.center.util.AuthUtil;
import com.microsoft.hydralab.common.entity.center.AuthToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -17,6 +18,8 @@
@Service
public class AuthTokenService {

@Resource
AuthUtil authUtil;
@Resource
AuthTokenRepository authTokenRepository;
@Resource
Expand Down Expand Up @@ -64,6 +67,15 @@ public boolean checkAuthToken(String authToken) {
}
}

public boolean checkAADToken(String aadToken) {
Authentication authObj = securityUserService.loadUserAuthentication(authUtil.getLoginUserName(aadToken), aadToken);
if (authObj == null) {
return false;
}
SecurityContextHolder.getContext().setAuthentication(authObj);
return true;
}

public void loadDefaultUser(HttpSession session) {
securityUserService.addDefaultUserSession(session);
}
Expand Down
Loading