Adding method to check if user exists

application-manager-new
Ace 9 years ago
parent ae08246052
commit 8f8209db08

@ -274,9 +274,11 @@ public class DoorManagerManagerService {
String accessToken = userStoreManager.getUserClaimValue(userInfo.userName, "http://wso2.org/claims/lock/accesstoken", null);
String cardNumber = userStoreManager.getUserClaimValue(userInfo.userName, "http://wso2.org/claims/lock/cardnumber", null);
if(cardNumber.equals(userInfo.cardNumber)){
if(accessToken != null){
if(accessToken != null && doorManagerDAO.getAutomaticDoorLockerDeviceDAO().
checkCardDoorAssociation(cardNumber, userInfo.deviceId)){
JSONObject credentials = new JSONObject();
credentials.put(DoorManagerConstants.DEVICE_PLUGIN_PROPERTY_ACCESS_TOKEN, accessToken);
credentials.put(DoorManagerConstants.DEVICE_PLUGIN_PROPERTY_ACCESS_TOKEN, accessToken);
return Response.ok(credentials, MediaType.APPLICATION_JSON_TYPE).build();
}
}

@ -261,6 +261,34 @@ public class DoorManagerDAOImpl {
return status;
}
public boolean checkCardDoorAssociation(String cardNum, String deviceID) throws DoorManagerDeviceMgtPluginException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = DoorManagerDAO.getConnection();
String createDBQuery = "SELECT * FROM SHARED_DOORLOCK_SAFE WHERE" +
" DOORMANAGER_DEVICE_ID = ? AND SERIAL_NUMBER = ?";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, cardNum);
stmt.setString(2, deviceID);
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("Lock : "+ deviceID + " is associated with card no : "+cardNum);
}
}
} catch (SQLException e) {
String msg = "No associations were found between lock : "+ deviceID +" and card : "+ cardNum;
log.error(msg, e);
throw new DoorManagerDeviceMgtPluginException(msg, e);
} finally {
DoorManagerUtils.cleanupResources(stmt, null);
}
return status;
}
public List<String> getUserCredentials(String deviceId, String UIDofUser) throws DoorManagerDeviceMgtPluginException {
Connection conn = null;

Loading…
Cancel
Save